From 1046af0ce7c29036ae88f888504619b64f5a7428 Mon Sep 17 00:00:00 2001 From: Michael Sims Date: Sun, 23 Apr 2023 23:13:08 -0500 Subject: [PATCH] Refactor UpdatePullRequest to accept PR stack instead of GitHubInfo --- github/githubclient/client.go | 5 ++--- github/interface.go | 2 +- github/mockclient/mockclient.go | 3 +-- spr/spr.go | 6 +++--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/github/githubclient/client.go b/github/githubclient/client.go index cd7f4e4..0f6fbb5 100644 --- a/github/githubclient/client.go +++ b/github/githubclient/client.go @@ -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) @@ -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 { diff --git a/github/interface.go b/github/interface.go index 0824c88..5e708fd 100644 --- a/github/interface.go +++ b/github/interface.go @@ -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) diff --git a/github/mockclient/mockclient.go b/github/mockclient/mockclient.go index b96fc95..97d3690 100644 --- a/github/mockclient/mockclient.go +++ b/github/mockclient/mockclient.go @@ -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, diff --git a/spr/spr.go b/spr/spr.go index 4003a5e..fadb971 100644 --- a/spr/spr.go +++ b/spr/spr.go @@ -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) } @@ -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) } @@ -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