Skip to content

Commit

Permalink
Add merge --upto to only merge part of the stack
Browse files Browse the repository at this point in the history
Fixes #158

commit-id:1d003c89
  • Loading branch information
ejoffe authored and Eitan Joffe committed Jan 23, 2022
1 parent 3325223 commit bedc23c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .spr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ githubRepoOwner: ejoffe
githubRepoName: spr
githubHost: github.com
requireChecks: true
requireApproval: false
requireApproval: true
githubRemote: origin
githubBranch: master
12 changes: 11 additions & 1 deletion cmd/spr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,22 @@ VERSION: {{.Version}}
Name: "merge",
Usage: "Merge all mergeable pull requests",
Action: func(c *cli.Context) error {
stackedpr.MergePullRequests(ctx)

if c.IsSet("upto") {
upto := c.Int("upto")
stackedpr.MergePullRequests(ctx, &upto)
} else {
stackedpr.MergePullRequests(ctx, nil)
}
stackedpr.UpdatePullRequests(ctx)
return nil
},
Flags: []cli.Flag{
detailFlag,
&cli.IntFlag{
Name: "upto",
Usage: "Only merge prs upto and including the provided pr number",
},
},
},
{
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,21 @@ MERGED #59 Feature 2
[·✗✔✗] 60: Feature 3
```

To merge only part of the stack use the **--upto** flag with the top pull request number in the stack that you would like to merge.

```shell
> git spr merge --upto 58
MERGED #58 Feature 1
[·✗✔✗] 60: Feature 3
[✔✔✔✔] 59: Feature 2
```

Show Current Pull Requests
--------------------------
```shell
> git spr status
[·✗✔✗] 60: Feature 3
[✔✔✔✔] 59: Feature 2
```

Configuration
Expand Down
10 changes: 8 additions & 2 deletions spr/spr.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (sd *stackediff) UpdatePullRequests(ctx context.Context) {
// pull request. This one merge in effect merges all the commits in the stack.
// We than close all the pull requests which are below the merged request, as
// their commits have already been merged.
func (sd *stackediff) MergePullRequests(ctx context.Context) {
func (sd *stackediff) MergePullRequests(ctx context.Context, upto *int) {
sd.profiletimer.Step("MergePullRequests::Start")
githubInfo := sd.github.GetInfo(ctx, sd.gitcmd)
sd.profiletimer.Step("MergePullRequests::getGitHubInfo")
Expand All @@ -197,10 +197,16 @@ func (sd *stackediff) MergePullRequests(ctx context.Context) {
for prIndex = 0; prIndex < len(githubInfo.PullRequests); prIndex++ {
pr := githubInfo.PullRequests[prIndex]
if !pr.Mergeable(sd.config) {
prIndex--
break
}
if upto != nil && pr.Number == *upto {
break
}
}
if prIndex == len(githubInfo.PullRequests) {
prIndex--
}
prIndex--
if prIndex == -1 {
return
}
Expand Down
4 changes: 2 additions & 2 deletions spr/spr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestSPRBasicFlowFourCommits(t *testing.T) {
githubmock.ExpectClosePullRequest(c2)
githubmock.ExpectCommentPullRequest(c3)
githubmock.ExpectClosePullRequest(c3)
s.MergePullRequests(ctx)
s.MergePullRequests(ctx, nil)
lines = strings.Split(output.String(), "\n")
assert.Equal("MERGED 1 : test commit 1", lines[0])
assert.Equal("MERGED 1 : test commit 2", lines[1])
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestSPRAmendCommit(t *testing.T) {
githubmock.ExpectClosePullRequest(c1)
githubmock.ExpectCommentPullRequest(c2)
githubmock.ExpectClosePullRequest(c2)
s.MergePullRequests(ctx)
s.MergePullRequests(ctx, nil)
lines = strings.Split(output.String(), "\n")
assert.Equal("MERGED 1 : test commit 1", lines[0])
assert.Equal("MERGED 1 : test commit 2", lines[1])
Expand Down

0 comments on commit bedc23c

Please sign in to comment.