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

Update av stack submit to open PRs in browser after entire stack is submitted #268

Merged
merged 2 commits into from
May 7, 2024
Merged
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
15 changes: 13 additions & 2 deletions cmd/av/stack_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
createdPullRequestPermalinks := []string{}
ctx := context.Background()
client, err := getGitHubClient()
if err != nil {
Expand All @@ -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 {
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 {
if _, err := client.UpdatePullRequest(
Expand All @@ -111,6 +116,12 @@ If the --current flag is given, this command will create pull requests up to the
}
}

if config.Av.PullRequest.OpenBrowser {
for _, createdPullRequestPermalink := range createdPullRequestPermalinks {
actions.OpenPullRequestInBrowser(createdPullRequestPermalink)
}
}

return nil
},
}
Expand Down
24 changes: 15 additions & 9 deletions internal/actions/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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).
Expand Down