From 74837be7384f5d95fe00a4fd832d0f035697357a Mon Sep 17 00:00:00 2001 From: Oleg Vaskevich Date: Wed, 1 May 2024 17:15:57 -0700 Subject: [PATCH 1/2] Update av stack submit to only open last PR in browser --- cmd/av/stack_submit.go | 13 +++++++++++-- internal/actions/pr.go | 24 +++++++++++++++--------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/cmd/av/stack_submit.go b/cmd/av/stack_submit.go index 5fa47614..63096653 100644 --- a/cmd/av/stack_submit.go +++ b/cmd/av/stack_submit.go @@ -69,6 +69,7 @@ If the --current flag is given, this command will create pull requests up to the } // ensure pull requests for each branch in the stack + var lastCreatedPullRequest *meta.PullRequest ctx := context.Background() client, err := getGitHubClient() if err != nil { @@ -80,13 +81,17 @@ If the --current flag is given, this command will create pull requests up to the result, err := actions.CreatePullRequest( ctx, repo, client, tx, actions.CreatePullRequestOpts{ - BranchName: branchName, - Draft: config.Av.PullRequest.Draft, + BranchName: branchName, + Draft: config.Av.PullRequest.Draft, + NoOpenBrowser: true, }, ) if err != nil { return err } + if result.Created { + lastCreatedPullRequest = result.Branch.PullRequest + } // make sure the base branch of the PR is up to date if it already exists if !result.Created && result.Pull.BaseRefName != result.Branch.Parent.Name { if _, err := client.UpdatePullRequest( @@ -111,6 +116,10 @@ If the --current flag is given, this command will create pull requests up to the } } + if lastCreatedPullRequest != nil && config.Av.PullRequest.OpenBrowser { + actions.OpenPullRequestInBrowser(lastCreatedPullRequest.Permalink) + } + return nil }, } diff --git a/internal/actions/pr.go b/internal/actions/pr.go index 1b97f02d..18925e9c 100644 --- a/internal/actions/pr.go +++ b/internal/actions/pr.go @@ -46,6 +46,8 @@ type CreatePullRequestOpts struct { Force bool // If true, open an editor for editing the title and body Edit bool + // If true, do not open the browser after creating the PR + NoOpenBrowser bool } type CreatePullRequestResult struct { @@ -407,21 +409,25 @@ func CreatePullRequest( colors.UserInput(pull.Permalink), "\n", ) - if didCreatePR && config.Av.PullRequest.OpenBrowser { - if err := browser.Open(pull.Permalink); err != nil { - _, _ = fmt.Fprint(os.Stderr, - " - couldn't open browser ", - colors.UserInput(err), - " for pull request link ", - colors.UserInput(pull.Permalink), - ) - } + if didCreatePR && !opts.NoOpenBrowser && config.Av.PullRequest.OpenBrowser { + OpenPullRequestInBrowser(pull.Permalink) } tx.SetBranch(branchMeta) return &CreatePullRequestResult{didCreatePR, branchMeta, pull}, nil } +func OpenPullRequestInBrowser(pullRequestLink string) { + if err := browser.Open(pullRequestLink); err != nil { + _, _ = fmt.Fprint(os.Stderr, + " - couldn't open browser ", + colors.UserInput(err), + " for pull request link ", + colors.UserInput(pullRequestLink), + ) + } +} + func savePRDescriptionToTemporaryFile(saveFile string, contents string) { if err := os.WriteFile(saveFile, []byte(contents), 0644); err != nil { logrus.WithError(err). From d2d9637f9b05f584a6b86c0baeef3bcaa6e0c6b5 Mon Sep 17 00:00:00 2001 From: Oleg Vaskevich Date: Mon, 6 May 2024 16:14:06 -0700 Subject: [PATCH 2/2] Bulk open instead --- cmd/av/stack_submit.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/av/stack_submit.go b/cmd/av/stack_submit.go index 63096653..5ae67448 100644 --- a/cmd/av/stack_submit.go +++ b/cmd/av/stack_submit.go @@ -69,7 +69,7 @@ If the --current flag is given, this command will create pull requests up to the } // ensure pull requests for each branch in the stack - var lastCreatedPullRequest *meta.PullRequest + createdPullRequestPermalinks := []string{} ctx := context.Background() client, err := getGitHubClient() if err != nil { @@ -90,7 +90,7 @@ If the --current flag is given, this command will create pull requests up to the return err } if result.Created { - lastCreatedPullRequest = result.Branch.PullRequest + createdPullRequestPermalinks = append(createdPullRequestPermalinks, result.Branch.PullRequest.Permalink) } // make sure the base branch of the PR is up to date if it already exists if !result.Created && result.Pull.BaseRefName != result.Branch.Parent.Name { @@ -116,8 +116,10 @@ If the --current flag is given, this command will create pull requests up to the } } - if lastCreatedPullRequest != nil && config.Av.PullRequest.OpenBrowser { - actions.OpenPullRequestInBrowser(lastCreatedPullRequest.Permalink) + if config.Av.PullRequest.OpenBrowser { + for _, createdPullRequestPermalink := range createdPullRequestPermalinks { + actions.OpenPullRequestInBrowser(createdPullRequestPermalink) + } } return nil