Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete remote branch after closing pull request. #383

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions git/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func GetLocalTopCommit(cfg *config.Config, gitcmd GitInterface) *Commit {
return &commits[len(commits)-1]
}

func DeleteRemoteBranch(cfg *config.Config, gitcmd GitInterface, branchName string) {
command := fmt.Sprintf("push origin --delete %s", branchName)
err := gitcmd.Git(command, nil)
check(err)
}

// GetLocalCommitStack returns a list of unmerged commits
//
// the list is ordered with the bottom commit in the stack first
Expand Down
4 changes: 4 additions & 0 deletions git/mockgit/mockgit.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func (m *Mock) ExpectFetch() {
m.expect("git rebase origin/master --autostash")
}

func (m *Mock) ExpectDeleteBranch(branchName string) {
m.expect(fmt.Sprintf("git push origin --delete %s", branchName))
}

func (m *Mock) ExpectLogAndRespond(commits []*git.Commit) {
m.expect("git log --format=medium --no-color origin/master..HEAD").commitRespond(commits)
}
Expand Down
1 change: 1 addition & 0 deletions spr/spr.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ func (sd *stackediff) MergePullRequests(ctx context.Context, count *uint) {
prToMerge.Number, sd.config.Repo.GitHubHost, sd.config.Repo.GitHubRepoOwner, sd.config.Repo.GitHubRepoName, prToMerge.Number)
sd.github.CommentPullRequest(ctx, pr, comment)
sd.github.ClosePullRequest(ctx, pr)
git.DeleteRemoteBranch(sd.config, sd.gitcmd, pr.FromBranch)
}
sd.profiletimer.Step("MergePullRequests::close prs")

Expand Down
3 changes: 3 additions & 0 deletions spr/spr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,13 @@ func TestSPRBasicFlowFourCommits(t *testing.T) {
githubmock.ExpectMergePullRequest(c4, genclient.PullRequestMergeMethod_REBASE)
githubmock.ExpectCommentPullRequest(c1)
githubmock.ExpectClosePullRequest(c1)
gitmock.ExpectDeleteBranch('???') // Not sure where to find the branch name?
githubmock.ExpectCommentPullRequest(c2)
githubmock.ExpectClosePullRequest(c2)
gitmock.ExpectDeleteBranch('???')
githubmock.ExpectCommentPullRequest(c3)
githubmock.ExpectClosePullRequest(c3)
gitmock.ExpectDeleteBranch('???')
s.MergePullRequests(ctx, nil)
lines = strings.Split(output.String(), "\n")
assert.Equal("MERGED 1 : test commit 1", lines[0])
Expand Down