簡體   English   中英

通過 go-github 使用搜索 API 進行合並請求

[英]Use Search API for Pull Requests with go-github

場景:我從 GitHub 收到狀態 webhook 事件。我想找到與提交相關的任何拉取請求。

StatusEvent包含提交.SHA.Repo (Respository) object。這似乎足以找到適用的 PR。

問題:如果觸發status事件以響應在與提交分開的存儲庫中對 PR 執行的檢查,則會出現問題......

嘗試 1 :go-github package 包含一個帶有.ListPullRequestsWithCommit方法的PullRequestsService調用此 GitHub API 方法 不幸的是,這似乎只返回包含提交的 repo 中的 PR。 意思是,它似乎忽略了使用分叉回購的提交創建的 PR。

嘗試 2 :go-github 有一個接受query參數的SearchService.Issues方法。 使用參數type:pr SHA:<sha> ,您會遇到“支持”PR 的問題(不確定正確的術語)——無論原始回購如何。

然后,使用PullRequestsService.Get方法,您可以獲得實際的PullRequest數據。

原型代碼(使用風險自負):

commitSha := event.GetCommit().GetSHA()
ownerLogin := repo.GetOwner().GetLogin()

issues, _, err := client.Search.Issues(ctx, fmt.Sprintf("type:pr SHA:%s", commitSha), &github.SearchOptions{})
// if err != nil { ??? }
// if len(issues.Issues) == 0 { ??? }
issue := issue.Issue[0]
pr, _, err := client.PullRequests.Get(ctx, ownerLogin, issue.GetNumber())
// if err != nil { ??? }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM