| 253 | } |
| 254 | |
| 255 | func 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 |