我想通过git命令,特别是gitPython库,从问题编号中获取pull请求正文、主题和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 bodyn titlen urln }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的v3neneneba API来获取拉取请求的详细信息,该请求的主体、标题和url字段将作为响应的一部分
GET https://api.github.com/repos/{owner}/{repoName}/pulls/{pullRequestNumber}
GET https://api.github.com/repos/gitpython-developers/GitPython/pulls/974