Skip to content

Commit

Permalink
Refactor UpdatePullRequest to accept PR stack instead of GitHubInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSims authored and ejoffe committed Apr 24, 2023
1 parent 95547e5 commit 1046af0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions github/githubclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,7 @@ func addManualMergeNotice(body string) string {
"Do not merge manually using the UI - doing so may have unexpected results.*"
}

func (c *client) UpdatePullRequest(ctx context.Context, gitcmd git.GitInterface,
info *github.GitHubInfo, pr *github.PullRequest, commit git.Commit, prevCommit *git.Commit) {
func (c *client) UpdatePullRequest(ctx context.Context, gitcmd git.GitInterface, pullRequests []*github.PullRequest, pr *github.PullRequest, commit git.Commit, prevCommit *git.Commit) {

if c.config.User.LogGitHubCalls {
fmt.Printf("> github update %d : %s\n", pr.Number, pr.Title)
Expand All @@ -508,7 +507,7 @@ func (c *client) UpdatePullRequest(ctx context.Context, gitcmd git.GitInterface,
Str("FromBranch", pr.FromBranch).Str("ToBranch", baseRefName).
Interface("PR", pr).Msg("UpdatePullRequest")

body := formatBody(commit, info.PullRequests)
body := formatBody(commit, pullRequests)
if c.config.Repo.PRTemplatePath != "" {
pullRequestTemplate, err := readPRTemplate(gitcmd, c.config.Repo.PRTemplatePath)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion github/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type GitHubInterface interface {
CreatePullRequest(ctx context.Context, gitcmd git.GitInterface, info *GitHubInfo, commit git.Commit, prevCommit *git.Commit) *PullRequest

// UpdatePullRequest updates a pull request with current commit
UpdatePullRequest(ctx context.Context, gitcmd git.GitInterface, info *GitHubInfo, pr *PullRequest, commit git.Commit, prevCommit *git.Commit)
UpdatePullRequest(ctx context.Context, gitcmd git.GitInterface, pullRequests []*PullRequest, pr *PullRequest, commit git.Commit, prevCommit *git.Commit)

// AddReviewers adds a reviewer to the given pull request
AddReviewers(ctx context.Context, pr *PullRequest, userIDs []string)
Expand Down
3 changes: 1 addition & 2 deletions github/mockclient/mockclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ func (c *MockClient) CreatePullRequest(ctx context.Context, gitcmd git.GitInterf
}
}

func (c *MockClient) UpdatePullRequest(ctx context.Context, gitcmd git.GitInterface, info *github.GitHubInfo,
pr *github.PullRequest, commit git.Commit, prevCommit *git.Commit) {
func (c *MockClient) UpdatePullRequest(ctx context.Context, gitcmd git.GitInterface, pullRequests []*github.PullRequest, pr *github.PullRequest, commit git.Commit, prevCommit *git.Commit) {
fmt.Printf("HUB: UpdatePullRequest\n")
c.verifyExpectation(expectation{
op: updatePullRequestOP,
Expand Down
6 changes: 3 additions & 3 deletions spr/spr.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (sd *stackediff) UpdatePullRequests(ctx context.Context, reviewers []string
for i := range githubInfo.PullRequests {
go func(i int) {
pr := githubInfo.PullRequests[i]
sd.github.UpdatePullRequest(ctx, sd.gitcmd, githubInfo, pr, pr.Commit, nil)
sd.github.UpdatePullRequest(ctx, sd.gitcmd, githubInfo.PullRequests, pr, pr.Commit, nil)
wg.Done()
}(i)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ func (sd *stackediff) UpdatePullRequests(ctx context.Context, reviewers []string
for i := range updateQueue {
go func(i int) {
pr := updateQueue[i]
sd.github.UpdatePullRequest(ctx, sd.gitcmd, githubInfo, pr.pr, pr.commit, pr.prevCommit)
sd.github.UpdatePullRequest(ctx, sd.gitcmd, githubInfo.PullRequests, pr.pr, pr.commit, pr.prevCommit)
wg.Done()
}(i)
}
Expand Down Expand Up @@ -295,7 +295,7 @@ func (sd *stackediff) MergePullRequests(ctx context.Context, count *uint) {
prToMerge := githubInfo.PullRequests[prIndex]

// Update the base of the merging pr to target branch
sd.github.UpdatePullRequest(ctx, sd.gitcmd, githubInfo, prToMerge, prToMerge.Commit, nil)
sd.github.UpdatePullRequest(ctx, sd.gitcmd, githubInfo.PullRequests, prToMerge, prToMerge.Commit, nil)
sd.profiletimer.Step("MergePullRequests::update pr base")

// Merge pull request
Expand Down

0 comments on commit 1046af0

Please sign in to comment.