gogs icon indicating copy to clipboard operation
gogs copied to clipboard

APIs for pull requests

Open yurivict opened this issue 9 years ago β€’ 23 comments

Particularly these commands are desired:

  • /api/v1/{user}/{repo}/pulls?status={open/closed}&id={id} - retrieves the list of pull requests (or one pull request)
  • /api/v1/{user}/{repo}/pull/{num}/files - retrieves the list of affected files for the pull request
  • /api/v1/{user}/{repo}/pull/{num}/diff - retrieves the diff file for the pull request
  • /api/v1/{user}/{repo}/pull/{num}/comments - retrieves the list of comments
  • /api/v1/{user}/{repo}/pull/{num}/comment-submit - PUT submits a new comment

yurivict avatar Dec 20 '15 09:12 yurivict

Besides enumerated commands, we use the following PR API in GitLab:

  1. Accept pull request via API
  2. Reassign pull request
  3. Create comment in pull request

We'd like to migrate to Gogs from Gitlab, but these api commands are required in our infrastructure (PR are accepted via an external utility).

romanresh avatar Apr 27 '16 10:04 romanresh

I just wanted to mention that I have written a Gogs Plugin for Jenkins to support Pipeline Multibranch and Org Scanning (auto creates project folders for repos and Pipeline projects for branches that have a Jenkinsfile in them). Initial release is available here: https://github.com/kmadel/gogs-branch-source-plugin/releases/tag/v0.1-alpha

The biggest missing features is support for Pull Requests. Even without a webhook or a Rest API to interact with them - is there anyway to interact with PRs via plain vanialla Git?

Thanks for the awesome work!

kmadel avatar Aug 04 '16 13:08 kmadel

By the way, I would like to mention that I believe Pull Requests should be able to be retrieved the same way that repo branches are (and the way GitHub does it):

GET /repos/:owner/:repo/pulls

And with at least the 'state' parameter to filter: state string Either open, closed, or all to filter by state. Default: open

kmadel avatar Aug 15 '16 16:08 kmadel

@Unknown are you already working on this in conjunction with #2246? If not, I would like to help out.

lstahlman avatar Aug 15 '16 21:08 lstahlman

@lstahlman OK, go ahead.

unknwon avatar Aug 15 '16 21:08 unknwon

Thanks!

lstahlman avatar Aug 15 '16 21:08 lstahlman

One implementing the API should probably orientate himself at this github api?

hhenkel avatar Aug 15 '16 22:08 hhenkel

That makes sense. I think most of the features requested here fit with that api, though some are dependent on related features that are still in progress (e.g., comments API).

lstahlman avatar Aug 15 '16 23:08 lstahlman

I also wanted to mention (and please correct me if I am wrong), but I don't believe it is even currently possible to get a list of Pull Request issues.

GET /repos/:owner/:repo/issues does not allow passing in the Issue option to include pull requests per https://github.com/gogits/gogs/blob/master/routers/api/v1/repo/issue.go#L19

kmadel avatar Sep 02 '16 15:09 kmadel

I am including the ability to pass options through /repos/:owner/:repo/pulls and I think there should be the same sort of support for issues. I was actually considering submitting a PR for that once I'm done with the initial work for the PR API.

lstahlman avatar Sep 02 '16 15:09 lstahlman

@lstahlman How far along are you on the PR API - and did you see this PR: #3547

Not quite as robust as what GitHub includes for PRs, but a simple start - I suppose you may already have something better.

kmadel avatar Sep 02 '16 15:09 kmadel

Yeah I saw that and am somewhat dependent on that PR getting accepted. I had my own version in dev, but it very closely matches what you submitted.

I'm pretty far along on the basics (list, get, create, update). I was starting to add support for PR commit/file details, but I think I will split that into a separate contribution.

lstahlman avatar Sep 02 '16 16:09 lstahlman

@lstahlman Are you still working on this one? if so can you send a PR for what you have? :smiley:

bkcsoft avatar Oct 10 '16 13:10 bkcsoft

I paused while waiting for #3547 & gogits/go-gogs-client#47 to be accepted, but I'll go ahead and post a WIP PR shortly so the code is out there.

lstahlman avatar Oct 10 '16 19:10 lstahlman

The WIP PRs I just posted implement the basic list, get, create, edit & merge features. I'm open to feedback and can add in extra bits where needed. I still need to finish the documentation markdown but should be able to post that in the next day or so.

@kmadel this is going to conflict with your PR #3547 as I changed the API format of the PR struct to more closely match the Github API (there seems to be a bit of a push for this).

lstahlman avatar Oct 12 '16 06:10 lstahlman

FYI I updated the PR to include the documentation. It's lengthy so I won't cross-post it here.

lstahlman avatar Oct 12 '16 20:10 lstahlman

Along with the support of pull requests β€” if it's not already implemented β€” please, really please make it possible to git fetch the pull-requests as git refs.

git fetch github pull/42/head # how it's implemented on github

Both github and gitlab support this and it's one of the great features they share, and bitbucket lack of it is the most frustrating side of the tool. Don't be like bitbucket, be like the others!

guyzmo avatar Dec 25 '16 17:12 guyzmo

@guyzmo what you're requesting is already there? #1655

hhenkel avatar Jan 02 '17 08:01 hhenkel

@hhenkel Brilliant!

Just need the PR listing/creation/close/comment API and it's going to be πŸ‘Œ

guyzmo avatar Jan 02 '17 13:01 guyzmo

BTW, if I may comment on the API structure, it's better to use a more RESTful structure:

  • /api/v1/{user}/{repo}/pullrequest
  • GET: (with ?status={open/closed}&id={id} params) retrieves (and filters) the list of pull requests
  • POST: creates a new PR
  • /api/v1/{user}/{repo}/pullrequest/{num}
  • GET: retrieves all details about a given PR
  • UPDATE: modifies mutable values of the PR
  • DELETE: ΓΈ (to close a PR update its status value)
  • /api/v1/{user}/{repo}/pullrequest/{num}/comment
    • GET: retrieves the list of comments
    • POST: creates a new comment
    • UPDATE/PUT: updates an existing comment
    • DELETE: deletes a comment

  • /api/v1/{user}/{repo}/pull/{num}/diff
    • would that one be really necessary? I mean, a simple property with link of the existing diff web page and patch raw file should be enough.
  • Though if that info cannot be reached using API's auth on the web content pages, then the API endpoint needs to be there
  • /api/v1/{user}/{repo}/pullrequest/{num}/files - retrieves the list of affected files for the pull request
  • idem: would it be necessary? The list of affected files can be easily extracted from a patch file.

my €0.02

guyzmo avatar Jan 02 '17 13:01 guyzmo

@guyzmo Gogs is following the GitHub API as close as possible, so deviating from it by choice (for little reason) would not be merged.

bkcsoft avatar Jan 02 '17 17:01 bkcsoft

This is a good idea, as from my experience implementing git services APIs, I have to admit github API is a very good one (whether you name it pull, pulls or pullrequest is just a minor technical detail). And what I suggested is following that API, cf Github documentation. I'm just suggesting to take baby steps in implementing it πŸ˜‰

the really necessary

the nice to have

you can also get commit list (which is not really useful if you implement the commit list endpoint):

guyzmo avatar Jan 02 '17 19:01 guyzmo

Any news?

ricardobranco777 avatar Oct 13 '23 19:10 ricardobranco777