Git 从问题编号中获取拉取请求主题正文的命令

Git command to get pull request subject body from issue number

我想通过 git 命令,尤其是 gitPython 库,从问题编号中获取拉取请求正文、主题和 URL。我该怎么做?

GitPython 用于 git 相关对象,而 Pull RequestGitHub 相关,因此不能用于获取 GitHub 数据。

您可以使用 GitHub 的 v4 GraphQL API 通过以下查询获取拉取请求详细信息

query {
  repository(name: "gitPython",owner:"gitpython-developers"){
    pullRequest(number:974){
      body
      title
      url
    }
  }
}

上述查询的curl请求:

curl -L -X POST 'https://api.github.com/graphql' \
-H 'Authorization: bearer <token>' \
-H 'Content-Type: text/plain' \
--data-raw '{"query":"{\n repository(name: \"gitPython\",owner:\"gitpython-developers\"){\n pullRequest(number:974){\n body\n title\n url\n }\n }\n }"'

上述请求的响应:

{
  "data": {
    "repository": {
      "pullRequest": {
        "body": "Removed A from Dockerfile that I added accidentally. THIS WILL BREAK THE BUILD",
        "title": "Remove A from Dockerfile",
        "url": "https://github.com/gitpython-developers/GitPython/pull/974"
      }
    }
  }
}

注意:您需要生成一个token来访问GraphQL API,您可以按照以下步骤生成给出的步骤 here

或者,您甚至可以使用 GitHub 的 v3 API 来获取拉取请求的详细信息,其中包含 bodytitleurl 字段作为响应的一部分

GET https://api.github.com/repos/{owner}/{repoName}/pulls/{pullRequestNumber}

GET https://api.github.com/repos/gitpython-developers/GitPython/pulls/974