列出拉取请求的提交
List commits on a pull request
我看到对于拉取请求的提交,根据文档,最大限制为 250:List commits on a Pull Request and if the pull request exceeds 250 commits then another end-point is suggested which is: List Commits
Lists a maximum of 250 commits for a pull request. To receive a complete commit list for pull
requests with more than 250 commits, use the List commits endpoint.
GET /repos/:owner/:repo/pulls/:pull_number/commits
但是,我不知道如何使用 List Commits 端点来确定它是否与拉取请求相关联。
编辑:想知道我是否应该在这里依赖 git 命令。即克隆 repo,运行 git 日志以获取所有提交的列表。有更好的方法吗?
问题:并非所有提交都会被推送到拉取请求?
此外,我正在寻找一种方法来查看自首次提出拉取请求以来是否有任何新提交以增量方式添加到拉取请求中。
对于处理评论并将其添加到现有拉取请求的情况,在这种情况下,我希望只验证增量更改。
关于如何实现这一点的任何指示或文档?
您可以使用 GET /repos/:owner/:repo/commits/:commit_sha/pulls
列出与提交关联的拉取请求,这将显示与给定提交关联的拉取请求。这确实意味着您需要检查每个提交以查看它是否与 PR 相关联。这将产生 大量 的额外网络流量,因此除非绝对必要,否则我不会建议使用此端点查找与 PR 相关的提交。
我能看到的为 PR 寻找新提交的最佳解决方案是在创建拉取请求后获取分支的所有提交。您需要 GET
PR,拉出 created_at
字段,并使用提交端点从分支检索提交,并使用 PR 的 created_at
字段作为since
提交请求正文中的字段并指定目标分支。
github documentation 表示如何在本地检查拉取请求:
在远程仓库上,拉取请求的当前“活动提交”存储在 refs/pull/<id>/head
下;当合并请求被合并时,另一个 ref 出现在 refs/pul/<id>/merge
.
引用文档:您可以在本地副本上获取单个合并请求:
Fetch the reference to the pull request based on its ID number, creating a new branch in the process.
$ git fetch origin pull/ID/head:BRANCHNAME
您现在可以比较 BRANCHNAME
和 master
(*) 以查看合并请求的提交列表:
git log master..BRANCHNAME
git rev-list master..BRANCHNAME
请注意,您可以选择将 pull/ID/head
提取到分支以外的某个引用中:
git fetch origin pull/ID/head:refs/remotes/origin/pr/ID
# now the pr appears as 'origin/pr/ID'
(*) 如果目标分支不是 master
,则您需要获取此信息,例如从 api。
您还可以将 refspec 设置为自动获取所有合并请求;参见例如 this gist :
Locate the section for your github remote in the .git/config file. It looks like this:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:joyent/node.git
Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:joyent/node.git
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
下一个 git fetch
将下载所有拉取请求(关闭、合并和一起打开)的所有引用。
我没有看到 refspec 中表示的拉取请求的 历史记录 :
- 您可以使用上述 refspec 设置存储库的克隆,
- 和 github 上的一个挂钩,它会在每次对拉取请求进行推送时通知此克隆,
- 以便克隆在收到通知时 运行
git fetch origin
这样:拉取请求的历史记录将出现在其引用日志中:
git reflog origin/pr/<id>
更直接的方法:使用挂钩,您可以访问正在推送的提交和正在更新的拉取请求,因此您可以设置一些东西来存储该拉取请求的历史记录。
我看到对于拉取请求的提交,根据文档,最大限制为 250:List commits on a Pull Request and if the pull request exceeds 250 commits then another end-point is suggested which is: List Commits
Lists a maximum of 250 commits for a pull request. To receive a complete commit list for pull requests with more than 250 commits, use the List commits endpoint.
GET /repos/:owner/:repo/pulls/:pull_number/commits
但是,我不知道如何使用 List Commits 端点来确定它是否与拉取请求相关联。
编辑:想知道我是否应该在这里依赖 git 命令。即克隆 repo,运行 git 日志以获取所有提交的列表。有更好的方法吗? 问题:并非所有提交都会被推送到拉取请求?
此外,我正在寻找一种方法来查看自首次提出拉取请求以来是否有任何新提交以增量方式添加到拉取请求中。 对于处理评论并将其添加到现有拉取请求的情况,在这种情况下,我希望只验证增量更改。 关于如何实现这一点的任何指示或文档?
您可以使用 GET /repos/:owner/:repo/commits/:commit_sha/pulls
列出与提交关联的拉取请求,这将显示与给定提交关联的拉取请求。这确实意味着您需要检查每个提交以查看它是否与 PR 相关联。这将产生 大量 的额外网络流量,因此除非绝对必要,否则我不会建议使用此端点查找与 PR 相关的提交。
我能看到的为 PR 寻找新提交的最佳解决方案是在创建拉取请求后获取分支的所有提交。您需要 GET
PR,拉出 created_at
字段,并使用提交端点从分支检索提交,并使用 PR 的 created_at
字段作为since
提交请求正文中的字段并指定目标分支。
github documentation 表示如何在本地检查拉取请求:
在远程仓库上,拉取请求的当前“活动提交”存储在 refs/pull/<id>/head
下;当合并请求被合并时,另一个 ref 出现在 refs/pul/<id>/merge
.
引用文档:您可以在本地副本上获取单个合并请求:
Fetch the reference to the pull request based on its ID number, creating a new branch in the process.
$ git fetch origin pull/ID/head:BRANCHNAME
您现在可以比较 BRANCHNAME
和 master
(*) 以查看合并请求的提交列表:
git log master..BRANCHNAME
git rev-list master..BRANCHNAME
请注意,您可以选择将 pull/ID/head
提取到分支以外的某个引用中:
git fetch origin pull/ID/head:refs/remotes/origin/pr/ID
# now the pr appears as 'origin/pr/ID'
(*) 如果目标分支不是 master
,则您需要获取此信息,例如从 api。
您还可以将 refspec 设置为自动获取所有合并请求;参见例如 this gist :
Locate the section for your github remote in the .git/config file. It looks like this:
[remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = git@github.com:joyent/node.git
Now add the line
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:[remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = git@github.com:joyent/node.git fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
下一个 git fetch
将下载所有拉取请求(关闭、合并和一起打开)的所有引用。
我没有看到 refspec 中表示的拉取请求的 历史记录 :
- 您可以使用上述 refspec 设置存储库的克隆,
- 和 github 上的一个挂钩,它会在每次对拉取请求进行推送时通知此克隆,
- 以便克隆在收到通知时 运行
git fetch origin
这样:拉取请求的历史记录将出现在其引用日志中:
git reflog origin/pr/<id>
更直接的方法:使用挂钩,您可以访问正在推送的提交和正在更新的拉取请求,因此您可以设置一些东西来存储该拉取请求的历史记录。