Using curl to create a pull request to GitHub repository

44 Views Asked by At

I can create (push) a new file on the GitHub repository with Curl via GitHub REST API and convert my file to Base64 format. Here is my working curl for push:

curl -X PUT -H "Authorization: token xxx" https://api.github.com/repos/{owner}/{repo}/contents/{path}/{fileName} -d "{\"message\":\"your commit message\",\"content\":\"file in BASE64\"}"

Now I want to create a pull request via curl to the GitHub repository. I read GitHub Docs, but I can't find any working sample for this topic. Can anyone provide a sample?

1

There are 1 best solutions below

0
Shachar297 On

POST /repos/:owner/:repo/pulls

# Request Payload
PR_PAYLOAD='{
  "title": "'"${PR_TITLE}"'",
  "body": "'"${PR_BODY}"'",
  "head": "'"${USERNAME}:${HEAD_BRANCH}"'",
  "base": "'"${BASE_BRANCH}"'"
}'

# The actual request
curl -X POST \
  -H "Authorization: token ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d "${PR_PAYLOAD}" \
  "https://api.github.com/repos/${USERNAME}/${REPO}/pulls"

Full example from documentation:

curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/OWNER/REPO/pulls \
  -d '{"title":"Amazing new feature","body":"Please pull these awesome changes in!","head":"octocat:new-feature","base":"master"}'