Pull Request via Github API

From the example in https://docs.github.com/en/rest/reference/pulls#create-a-pull-request, it seems quite easy:

1curl \
2  -X POST \
3  -H "Accept: application/vnd.github.v3+json" \
4  https://api.github.com/repos/octocat/hello-world/pulls \
5  -d '{"title":"title","head":"head","base":"base"}'

The above means, create a pull request with title "title" with code in branch "head" against the branch in "base" for the repo https://github.com/octocat/hello-world.git

In case you need to authenticate, add

1-u <user>:<GITHUB_TOKEN>

before the -H

1curl \
2  -X POST \
3  -u your_user:DEFINED_GITHUB_TOKEN_HERE
4  -H "Accept: application/vnd.github.v3+json" \
5  https://api.github.com/repos/octocat/hello-world/pulls \
6  -d '{"title":"title","head":"head","base":"base"}'

You can also use a payload json file for this value:

1-d '{"title":"title","head":"head","base":"base"}'

and write it as:

1-d @payload.json

See https://stackoverflow.com/questions/18611903/how-to-pass-payload-via-json-file-for-curl

Posts in this Series