简体   繁体   English

Github Rest api:Head 字段的正确值是多少?

[英]Github Rest api : what is the right value of Head field?

I am trying to create a Pull Request, using curl .我正在尝试使用 curl 创建一个拉取请求。 y The pull request source and target branch are in the same repo. y 拉取请求源和目标分支在同一个仓库中。 (Not cros repository). (不是跨存储库)。 The source branch name is cd/apim-1.25.27 , and the target branch name is master .源分支名称为cd/apim-1.25.27 ,目标分支名称为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…我一直有以下错误,并尝试了head字段格式(PR 源分支名称)的所有可能性,但仍然无法创建 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我从 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.我只使用 curl 遇到了这个问题。

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');
      }
   });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GitHub 应用程序和 GitHub 的 REST API 之间有什么区别? - What is the difference between a GitHub App and the REST API for GitHub? 授权此REST API请求的“正确方法”是什么? - What is 'The right way' to authorize this REST API request? REST API 响应的正确方法是什么? - What is a right way for REST API response? Magento2 REST API - POST 可配置产品选项:value_index 字段是什么? - Magento2 REST API - POST configurable product options : What is the value_index field? 在C#中,将附件发布到Confluence REST API的正确方法是什么? - In C#, what is the right way to post attachments to Confluence REST API? 什么是其余 API 方法 - COPY、HEAD、OPTIONS、LINK、UNLINK、PURGE、LOCK、UNLO​​CK、PROPFIND、VIEW - What is rest API methods - COPY, HEAD, OPTIONS, LINK, UNLINK, PURGE, LOCK, UNLOCK, PROPFIND, VIEW 通过GitHub REST API在github上创建Fork仓库 - Fork repository on github through GitHub REST API Github REST API 完整示例 - Github REST API full example Github REST API git克隆 - Github REST API git clone REST API管理字段的最大字符数的最佳实践是什么? - What is the best practice for a REST api to manage maximum characters for a field?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM