MCPcopy Create free account
hub / github.com/ejoffe/spr / matchPullRequestStack

Function matchPullRequestStack

github/githubclient/client.go:255–373  ·  view source on GitHub ↗
(
	repoConfig *config.RepoConfig,
	branchPrefix string,
	targetBranch string,
	localCommitStack []git.Commit,
	allPullRequests fezzik_types.PullRequestConnection)

Source from the content-addressed store, hash-verified

253}
254
255func matchPullRequestStack(
256 repoConfig *config.RepoConfig,
257 branchPrefix string,
258 targetBranch string,
259 localCommitStack []git.Commit,
260 allPullRequests fezzik_types.PullRequestConnection) []*github.PullRequest {
261
262 if len(localCommitStack) == 0 || allPullRequests.Nodes == nil {
263 return []*github.PullRequest{}
264 }
265
266 // pullRequestMap is a map from commit-id to pull request
267 pullRequestMap := make(map[string]*github.PullRequest)
268 for _, node := range *allPullRequests.Nodes {
269 var commits []git.Commit
270 for _, v := range *node.Commits.Nodes {
271 for _, line := range strings.Split(v.Commit.MessageBody, "\n") {
272 if strings.HasPrefix(line, "commit-id:") {
273 commits = append(commits, git.Commit{
274 CommitID: strings.Split(line, ":")[1],
275 CommitHash: v.Commit.Oid,
276 Subject: v.Commit.MessageHeadline,
277 Body: v.Commit.MessageBody,
278 })
279 }
280 }
281 }
282
283 pullRequest := &github.PullRequest{
284 ID: node.Id,
285 Number: node.Number,
286 Title: node.Title,
287 Body: node.Body,
288 FromBranch: node.HeadRefName,
289 ToBranch: node.BaseRefName,
290 Commits: commits,
291 InQueue: node.MergeQueueEntry != nil,
292 }
293
294 matches := git.BranchNameRegex(branchPrefix).FindStringSubmatch(node.HeadRefName)
295 if matches != nil {
296 commit := (*node.Commits.Nodes)[len(*node.Commits.Nodes)-1].Commit
297 pullRequest.Commit = git.Commit{
298 CommitID: matches[2],
299 CommitHash: commit.Oid,
300 Subject: commit.MessageHeadline,
301 Body: commit.MessageBody,
302 }
303
304 checkStatus := github.CheckStatusPass
305 if commit.StatusCheckRollup != nil {
306 switch commit.StatusCheckRollup.State {
307 case "SUCCESS":
308 checkStatus = github.CheckStatusPass
309 case "PENDING":
310 checkStatus = github.CheckStatusPending
311 default:
312 checkStatus = github.CheckStatusFail

Callers 2

GetInfoMethod · 0.85

Calls 1

BranchNameRegexFunction · 0.92

Tested by 1