Add a `tod project create` command #3189
Robert Navarro opened 1 week ago

I use tod (4.3.4) from coding agents against my OneDev 16.9.1 server. An agent needed to create a project for a new repository and found no command for it: tod project has list, current, get and get-query-description. It fell back to curl against POST /~api/projects, with a full request body copied from GET /~api/projects/<id> of an existing project, since it could not find which fields the endpoint requires. That worked and returned the new id.

From reading the code, the required fields are name, gitPackConfig and codeIndexingSetting (the e2e helper in e2e-test/tests/api.js sends {} for the last two), but nothing in tod points an agent there.

I would like to add tod project create <path> with --key, --description and the feature toggles (code, issue, pack, wiki, time tracking), printing the same JSON as tod project get. I see two ways to do it and would like to know which you prefer:

  • A. Add /~api/tod/create-project to TodResource. It takes a path like parent/child, goes through ProjectService.setup() the way NewProjectPage does, and returns ProjectHelper.getDetail(). This is two PRs (server and tod), and the command only works on a server release that has the endpoint.
  • B. Have tod call POST /~api/projects directly. This is one tod PR and works on current servers, but tod has to look up the parent id from its path, send the two empty settings objects, and make a second call to print the project detail. tod already calls DELETE /~api/job-runs/{id} when cancelling a build, so it would not be the only call outside /~api/tod.

I lean towards A, since it creates projects the same way the web UI does (path based, missing parents created), but B works for me too. I am willing to put up the PR(s) for whichever you pick.

Before filing I searched OD and TOD issues and PRs for project creation from tod or the REST API and found no duplicate. The closest is OD-2831, which asked for endpoints and tod commands for branch association.

  • Robin Shen commented 1 week ago

    Tod is primary used to work with existing projects in a AI agent environment. It is assumed to be a tool covering every aspects of API, especially for less used features. For project creation, I'd suggest to use API directly.

  • Robin Shen commented 1 week ago

    It is assumed to be a tool covering every aspects of API,

    It is NOT assumed to be a tool covering every aspects of API...

  • Robert Navarro commented 1 week ago

    So tod isn't meant to be an equivalent of GitHub's gh CLI? That diminishes its value a lot for my local agents. They work best when one CLI covers the whole forge, and "use the API directly" means leaving tod to find the server URL and token and call curl.

    Would you take a tod api <method> <path> passthrough, similar to gh api? It would reuse tod's configured server and token, so the less used parts of the API stay reachable without a dedicated command for each. I can put up the PR.

  • Robin Shen commented 1 week ago

    Yes, it is not a equivalent of gh. For AI agents, it is quite convenient to use API directly, with the json api help specifically created for AI agents:

    https://code.onedev.io/~api/help

  • Robert Navarro commented 1 week ago

    Thanks, I didn't know about /~api/help. I had tried /~help/api, which is the web page, so my agent ended up copying a request body from an existing project instead. I've pointed my agents at the JSON help for anything tod doesn't cover, so I'll close this.

  • Robert Navarro changed state to 'Closed' 1 week ago
    Previous Value Current Value
    Open
    Closed
1/1
Type
Enhancement
Priority
Normal
Assignee
Labels
No labels
Issue Votes (0)
Watchers (2)
Reference
OD-3189
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover