I am trying to create a Pull Request, using curl . y The pull request source and target branch are in the same repo. (Not cros repository). The source branch name is cd/apim-1.25.27
, and the target branch name is master
.
I keep having the following error, and tried every possibility for the head
field format (the PR source branch name), but still can't get to create a the PR…
My curl :
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ******" \
https://api.github.com/repos/MY_ORGANIZATION/My_REPOSITORY/pulls \
-d '{"title":"Amazing new feature","body":"Please pull these awesome changes in!","head":"cd/apim-1.25.27","base":"master"}'
I got this message from github api
{
"message": "Validation Failed",
"errors": [
{
"resource": "PullRequest",
"field": "head",
"code": "invalid"
}
],
"documentation_url": "https://docs.github.com/rest/reference/pulls#create-a-pull-request"
I got the issue only using curl.
Creating the pull request with postman works well.
Finally I end up using octokit library, github official development kit ( https://octokit.github.io/rest.js/v18#pulls-create ).
Below the code I used:
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({auth: '${GITHUB_PAT_PR}' });
octokit.rest.pulls.create(
{
owner: 'OWNER',
repo: '${REPOSITORY_NAME}',
title: 'Creating new pull request',
body: 'Pull request detailled description',
head: 'source_branche',
base: 'destination_branch'
}).then(data => console.log("The pullrequest was successfuly created!"))
.catch(err => {
let reponseGithub = err.response.data.errors[0];
if(reponseGithub && reponseGithub.message && reponseGithub.message.includes("A pull request already exists for")) {
console.log("A pull request already exists for this repository");
}
else
{
console.log("An unexpected error occurred while creating the pull request on Github");
console.log("check octokit documentation ==> https://octokit.github.io/rest.js/v18#pulls-create ");
console.log("Github API Documentation ==> https://docs.github.com/rest/reference/pulls#create-a-pull-request ");
console.log(err.response.data.errors);
throw new Error('an error message');
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.