github - Git 命令从问题编号获取拉取请求主题主体
问题描述
我想通过 git 命令尤其是 gitPython 库从问题编号中获取拉取请求正文、主题和 URL。我该怎么做?
解决方案
GitPython用于git
相关对象,而Pull Request与GitHub相关,因此不能用于获取 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"
}
}
}
}
注意:您需要生成令牌才能访问 GraphQL API,您可以按照此处给出的步骤生成令牌
或者,您甚至可以使用下面的 GitHub 的 v3 API来获取拉取请求详细信息,其中包含body、title和url字段作为响应的一部分
GET https://api.github.com/repos/{owner}/{repoName}/pulls/{pullRequestNumber}
GET https://api.github.com/repos/gitpython-developers/GitPython/pulls/974
推荐阅读
- fortran - 用 gfortran 忽略固有的 gamma 函数
- google-cloud-platform - How attach a GCP IAM policy to a resource with gcloud command tool?
- ruby-on-rails - Rails full error message without attribute
- reactjs - How do you add an keyup event listener to window in a React functional component that only gets added when the app originally loads?
- django - django.db.utils.IntegrityError while writing APITestCase for my views?
- c# - 通过 NamedPipeWrapper 使用 Named Pipes 在 Winforms 和 Windows 服务应用程序之间进行通信
- python - 在 python bot 中找不到错误
- python - python中的并行数据(熵)收集
- file - copy and rename by specific condition - batch
- unity3d - 有没有办法解决在unity2d中构建后似乎损坏的png文件?