是否有一种方法来验证如果一个git sha属于一个git分支与go-github客户端?



希望使用go GitHub客户端来获得结果git branch -r origin/<branch> --contains <sha>

是否有一种方法来验证git sha是否属于go-github客户端的git分支?

我似乎无法找到一个API端点,可以具体回答SHA是否属于分支,所以你必须在分支内迭代提交。比如:

func main() {
ctx := context.Background()
sts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: "<token>"},
)
tc := oauth2.NewClient(ctx, sts)
client := github.NewClient(tc)
repoOwner := "<owner>"
repoName := "<repo>"
branchToSearch := "<branch>"
shaToFind := "<sha>"
resultsPerPage := 25
listOptions := github.ListOptions{PerPage: resultsPerPage}
for {
rc, resp, err := client.Repositories.ListCommits(ctx,
repoOwner,
repoName,
&github.CommitsListOptions{
SHA:         branchToSearch,
ListOptions: listOptions,
},
)
if err != nil {
log.Panic(err)
}
for _, c := range rc {
if *c.SHA == shaToFind {
log.Printf("FOUND commit "%s" in the branch "%s"n", shaToFind, branchToSearch)
return
}
}
if resp.NextPage == 0 {
break
}
listOptions.Page = resp.NextPage
}
log.Printf("NOT FOUND commit "%s" in the branch "%s"n", shaToFind, branchToSearch)
}

相关内容

  • 没有找到相关文章

最新更新