我想通过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"
}
}
}
}
Note:您需要生成一个token来访问GraphQL API,可以通过执行给定的here
步骤来生成它或者,您甚至可以如下使用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