问题描述
我们可以用 Github GraphQL 比较两个分支吗?
Can we compare two branches with the Github GraphQL?
从他们的 v3 rest API,您可以:
From their v3 rest API, you can do:
/repos/:owner/:repo/compare/:base...:head
(文档:https://developer.github/v3/repos/commits/#compare-two-commits)
这适用于 SHA、分支、标签等.
and this works with SHA's, branches, tags, etc.
但是,我无法在文档中找到等效的 GraphQL 查询.
However, I'm unable to find it's equivalent GraphQL query in the docs.
这是我迄今为止的尝试:
This is my attempt so far :
我可以单独获取每个分支的提交列表,但是,整个历史记录都已加载,我只想要 canary 分支和 nightly 分支之间的区别.
I'm able to get the list of commits for each branch seperately, however, the entire history is loaded and I would only like the difference between canary branch and nightly branch.
query{
repository(owner:"samridh",name:"release-generator"){
name
branch0: ref(qualifiedName: "canary"){
target{
... on Commit {
history(first:100){
...CommitFragment
}
}
}
}
branch1: ref(qualifiedName: "nightly"){
target{
... on Commit {
history(first:100){
...CommitFragment
}
}
}
}
}
}
fragment CommitFragment on CommitHistoryConnection {
totalCount
nodes {
oid
message
committedDate
author {
name
email
}
}
pageInfo {
hasNextPage
endCursor
}
}
这本来可以这样做:
/repos/samridh/release-generator/compare/nightly...canary
在 v3 REST API 中
in the v3 REST API
推荐答案
不幸的是,在浏览了 github 社区页面的几个小时后,似乎截至目前,该 API 并未在 v4 上迁移,并且必须通过 v3 本身完成.
Unfortunately, after scrolling through hours and hours of the github community page, it seems that as of this date, the API is not migrated on the v4, and must be done via v3 itself.
但是,v3 API 仅支持 250 次提交,超出此范围的任何提交都将被忽略且不会显示.不过,这可以通过使用 graphQL 来解决.
However, the v3 API only supports 250 commits, any commits beyond that will be ignored and not shown. This can be worked around using graphQL though.
触发此查询以获取起点和终点:
Fire this query to get the starting and ending points:
query getStartAndEndPoints {
repository(owner: "samridh", name: "release-generator") {
endPoint: ref(qualifiedName: "canary") {
...internalBranchContent
}
startPoint: ref(qualifiedName: "nightly") {
...internalBranchContent
}
}
}
fragment internalBranchContent on Ref {
target {
... on Commit {
history(first: 1) {
edges {
node {
committedDate
}
}
}
}
}
}
这将为您提供查询的开始和结束日期.
This will give you the start and end date of the query.
将这些值插入到:
query findDifference{
repository(owner:"samridh",name:"release-generator"){
ref(qualifiedName: "canary"){
target{
... on Commit {
history(
first : 100,
after: $(value of previous end cursor) #keep it empty first time
until : $(endDate),
since: $(startDate),
){
...CommitFragment
}
}
}
}
}
}
fragment CommitFragment on CommitHistoryConnection {
totalCount
nodes {
oid
}
pageInfo {
startCursor
hasNextPage
endCursor
}
}
并提取所有的oid,一次100个(Github GraphQL一次只支持100个)
and extract all the oid, 100 at a time ( Github GraphQL only supports 100 at a time )
最后,您可以调用 v3 API,同样:
Finally, you can call the v3 API, likewise :
/repos/samridh/release-generator/compare/<commit1>...<commit100>
/repos/samridh/release-generator/compare/<commit101>...<commit200>
/repos/samridh/release-generator/compare/<commit201>...<commit300>
这篇关于如何用GraphQL比较github中的两个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论