Skip to content

Commit

Permalink
merge queue support
Browse files Browse the repository at this point in the history
  • Loading branch information
soluchok authored and ejoffe committed Jul 28, 2023
1 parent d8f0ee2 commit 5f9733c
Show file tree
Hide file tree
Showing 10 changed files with 440 additions and 47 deletions.
13 changes: 11 additions & 2 deletions cmd/reword/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"os"
"strings"

"github.com/ejoffe/spr/config"
"github.com/ejoffe/spr/git/realgit"
"github.com/google/uuid"
)

func main() {
filename := os.Args[1]

gitcmd := realgit.NewGitCmd(config.DefaultConfig())
if !strings.HasSuffix(filename, "COMMIT_EDITMSG") {
readfile, err := os.Open(filename)
check(err)
Expand All @@ -29,7 +31,14 @@ func main() {
check(err)

for _, line := range lines {
line := strings.Replace(line, "pick ", "reword ", 1)
if strings.HasPrefix(line, "pick") {
res := strings.Split(line, " ")
var out string
gitcmd.Git("log --format=%B -n 1 "+res[1], &out)
if !strings.Contains(out, "commit-id") {
line = strings.Replace(line, "pick ", "reword ", 1)
}
}
writefile.WriteString(line + "\n")
}
writefile.Close()
Expand Down
23 changes: 21 additions & 2 deletions github/githubclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,34 @@ func matchPullRequestStack(
// pullRequestMap is a map from commit-id to pull request
pullRequestMap := make(map[string]*github.PullRequest)
for _, node := range *allPullRequests.Nodes {
var commits []git.Commit
for _, v := range *node.Commits.Nodes {
for _, line := range strings.Split(v.Commit.MessageBody, "\n") {
if strings.HasPrefix(line, "commit-id:") {
commits = append(commits, git.Commit{
CommitID: strings.Split(line, ":")[1],
CommitHash: v.Commit.Oid,
Subject: v.Commit.MessageHeadline,
Body: v.Commit.MessageBody,
})
}
}
}

pullRequest := &github.PullRequest{
ID: node.Id,
Number: node.Number,
Title: node.Title,
Body: node.Body,
FromBranch: node.HeadRefName,
ToBranch: node.BaseRefName,
Commits: commits,
InQueue: node.MergeQueueEntry != nil,
}

matches := git.BranchNameRegex.FindStringSubmatch(node.HeadRefName)
if matches != nil {
commit := (*node.Commits.Nodes)[0].Commit
commit := (*node.Commits.Nodes)[len(*node.Commits.Nodes)-1].Commit
pullRequest.Commit = git.Commit{
CommitID: matches[2],
CommitHash: commit.Oid,
Expand Down Expand Up @@ -520,11 +536,14 @@ func (c *client) UpdatePullRequest(ctx context.Context, gitcmd git.GitInterface,

input := genclient.UpdatePullRequestInput{
PullRequestId: pr.ID,
BaseRefName: &baseRefName,
Title: title,
Body: &body,
}

if !pr.InQueue {
input.BaseRefName = &baseRefName
}

if c.config.User.PreserveTitleAndBody {
input.Title = nil
input.Body = nil
Expand Down
125 changes: 125 additions & 0 deletions github/githubclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,131 @@ func TestMatchPullRequestStack(t *testing.T) {
prs genclient.PullRequestsViewerPullRequests
expect []*github.PullRequest
}{
{
name: "ThirdCommitQueue",
commits: []git.Commit{
{CommitID: "00000001"},
{CommitID: "00000002"},
{CommitID: "00000003"},
},
prs: genclient.PullRequestsViewerPullRequests{
Nodes: &genclient.PullRequestsViewerPullRequestsNodes{
{
Id: "2",
HeadRefName: "spr/master/00000002",
BaseRefName: "master",
MergeQueueEntry: &genclient.PullRequestsViewerPullRequestsNodesMergeQueueEntry{Id: "020"},
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1", MessageBody: "commit-id:1"},
},
{
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2", MessageBody: "commit-id:2"},
},
},
},
},
},
},
expect: []*github.PullRequest{
{
ID: "2",
FromBranch: "spr/master/00000002",
ToBranch: "master",
Commit: git.Commit{
CommitID: "00000002",
CommitHash: "2",
Body: "commit-id:2",
},
InQueue: true,
Commits: []git.Commit{
{CommitID: "1", CommitHash: "1", Body: "commit-id:1"},
{CommitID: "2", CommitHash: "2", Body: "commit-id:2"},
},
MergeStatus: github.PullRequestMergeStatus{
ChecksPass: github.CheckStatusFail,
},
},
},
},
{
name: "FourthCommitQueue",
commits: []git.Commit{
{CommitID: "00000001"},
{CommitID: "00000002"},
{CommitID: "00000003"},
{CommitID: "00000004"},
},
prs: genclient.PullRequestsViewerPullRequests{
Nodes: &genclient.PullRequestsViewerPullRequestsNodes{
{
Id: "2",
HeadRefName: "spr/master/00000002",
BaseRefName: "master",
MergeQueueEntry: &genclient.PullRequestsViewerPullRequestsNodesMergeQueueEntry{Id: "020"},
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1", MessageBody: "commit-id:1"},
},
{
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2", MessageBody: "commit-id:2"},
},
},
},
},
{
Id: "3",
HeadRefName: "spr/master/00000003",
BaseRefName: "spr/master/00000002",
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "3", MessageBody: "commit-id:3"},
},
},
},
},
},
},
expect: []*github.PullRequest{
{
ID: "2",
FromBranch: "spr/master/00000002",
ToBranch: "master",
Commit: git.Commit{
CommitID: "00000002",
CommitHash: "2",
Body: "commit-id:2",
},
InQueue: true,
Commits: []git.Commit{
{CommitID: "1", CommitHash: "1", Body: "commit-id:1"},
{CommitID: "2", CommitHash: "2", Body: "commit-id:2"},
},
MergeStatus: github.PullRequestMergeStatus{
ChecksPass: github.CheckStatusFail,
},
},
{
ID: "3",
FromBranch: "spr/master/00000003",
ToBranch: "spr/master/00000002",
Commit: git.Commit{
CommitID: "00000003",
CommitHash: "3",
Body: "commit-id:3",
},
Commits: []git.Commit{
{CommitID: "3", CommitHash: "3", Body: "commit-id:3"},
},
MergeStatus: github.PullRequestMergeStatus{
ChecksPass: github.CheckStatusFail,
},
},
},
},
{
name: "Empty",
commits: []git.Commit{},
Expand Down
22 changes: 11 additions & 11 deletions github/githubclient/gen/genclient/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5f9733c

Please sign in to comment.