Clarification: simple Merge Request with the API? #8590

Closed
opened 2025-11-02 08:11:51 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @ekianjo on GitHub (Feb 21, 2022).

Hi, I am finding the API very useful to execute a bunch of actions, however I can't figure out how to use the pull request/merge part of the API - the Swagger documentation for that one is far from being very explicit.
Could you provide an example?

Originally created by @ekianjo on GitHub (Feb 21, 2022). Hi, I am finding the API very useful to execute a bunch of actions, however I can't figure out how to use the pull request/merge part of the API - the Swagger documentation for that one is far from being very explicit. Could you provide an example?
GiteaMirror added the type/question label 2025-11-02 08:11:51 -06:00
Author
Owner

@eladyn commented on GitHub (Feb 28, 2022):

The following works for me:

curl -X 'POST' \
  'https://try.gitea.io/api/v1/repos/org/repo/pulls?token=myaccesstoken' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "base": "main",
  "body": "This is a PR",
  "head": "username:feature-branch",
  "title": "PR title"
}'

As for the JSON:

  • base is the base branch in the target repository (e.g. in the above example, you would create a PR to the org/repo repository with target branch main)
  • head is the username and the branch from which you want to create a pull request, separated by :. If the username is omitted, it is assumed that the PR is from a branch in the base repository. (So in the example, we create a PR from the branch feature-branch in the username/repo repository)

The rest should be quite easy to figure out. Alternatively, you can have a look at the source code, especially this function. Hope this helps!

@eladyn commented on GitHub (Feb 28, 2022): The following works for me: ``` curl -X 'POST' \ 'https://try.gitea.io/api/v1/repos/org/repo/pulls?token=myaccesstoken' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "base": "main", "body": "This is a PR", "head": "username:feature-branch", "title": "PR title" }' ``` As for the JSON: - `base` is the base branch in the target repository (e.g. in the above example, you would create a PR to the `org/repo` repository with target branch `main`) - `head` is the username and the branch from which you want to create a pull request, separated by `:`. If the username is omitted, it is assumed that the PR is from a branch in the base repository. (So in the example, we create a PR from the branch `feature-branch` in the `username/repo` repository) The rest should be quite easy to figure out. Alternatively, you can have a look at the source code, especially [this function](https://github.com/go-gitea/gitea/blob/4697735c8da31fb0c48686e0b02634df86de1319/routers/api/v1/repo/pull.go#L919-L1044). Hope this helps!
Author
Owner

@ekianjo commented on GitHub (Mar 19, 2022):

Thanks let me check this out! @eladyn

@ekianjo commented on GitHub (Mar 19, 2022): Thanks let me check this out! @eladyn
Author
Owner

@ekianjo commented on GitHub (Mar 20, 2022):

Hi @eladyn I tried your suggestion but I seem to be getting a 422 error with the following message:

$message
[1] "[Head]: Required"

Even though I entered the branch name in the head variable as "head":"username:branch_name" - any idea why I might be getting this error?

@ekianjo commented on GitHub (Mar 20, 2022): Hi @eladyn I tried your suggestion but I seem to be getting a 422 error with the following message: $message [1] "[Head]: Required" Even though I entered the branch name in the head variable as "head":"username:branch_name" - any idea why I might be getting this error?
Author
Owner

@eladyn commented on GitHub (Mar 20, 2022):

@ekianjo Could you post the full request / payload, you tried this with (ofc with private information stripped, if any)? It seems there is something it doesn't like about your JSON.

Edit: For reference, here is a real example that should work once, if you want to try it:

curl -X 'POST' \
  'https://try.gitea.io/api/v1/repos/pr_api_test/pr_test/pulls?token=c738eeb298980e863778821da509eb8877fb1380' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "base": "main",
  "head": "content",
  "title": "first pr",
  "body": "This is a PR!"
}'
@eladyn commented on GitHub (Mar 20, 2022): @ekianjo Could you post the full request / payload, you tried this with (ofc with private information stripped, if any)? It seems there is something it doesn't like about your JSON. Edit: For reference, here is a real example that should work once, if you want to try it: ```console curl -X 'POST' \ 'https://try.gitea.io/api/v1/repos/pr_api_test/pr_test/pulls?token=c738eeb298980e863778821da509eb8877fb1380' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "base": "main", "head": "content", "title": "first pr", "body": "This is a PR!" }' ```
Author
Owner

@6543 commented on GitHub (May 10, 2022):

just play around with https://try.gitea.io/api/swagger#/repository/repoMergePullRequest ... on https://try.gitea.io/

@6543 commented on GitHub (May 10, 2022): just play around with https://try.gitea.io/api/swagger#/repository/repoMergePullRequest ... on https://try.gitea.io/
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#8590