Skip to content

Commit 766e495

Browse files
committed
Be transparent about which part of pr create flow failed
When applying metadata to the new PR such as assignees or reviewers, if the operation fails, an error message would get printed: failed to create pull request: <API error text> This was misleading, because the PR did get created; it's just that updating it failed. The new error message is: https://github.com/OWNER/REPO/pull/123 pull request update failed: <API error text> The PR URL is printed on stdout and the error message is printed on stderr. In case of any errors, the exit code is still non-zero.
1 parent 987e95f commit 766e495

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

api/queries_pr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ func CreatePullRequest(client *Client, repo *Repository, params map[string]inter
683683
}
684684
err := client.GraphQL(repo.RepoHost(), updateQuery, variables, &result)
685685
if err != nil {
686-
return nil, err
686+
return pr, err
687687
}
688688
}
689689

@@ -708,7 +708,7 @@ func CreatePullRequest(client *Client, repo *Repository, params map[string]inter
708708
}
709709
err := client.GraphQL(repo.RepoHost(), reviewQuery, variables, &result)
710710
if err != nil {
711-
return nil, err
711+
return pr, err
712712
}
713713
}
714714

pkg/cmd/pr/create/create.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,15 @@ func createRun(opts *CreateOptions) error {
366366
}
367367

368368
pr, err := api.CreatePullRequest(client, baseRepo, params)
369+
if pr != nil {
370+
fmt.Fprintln(opts.IO.Out, pr.URL)
371+
}
369372
if err != nil {
370-
return fmt.Errorf("failed to create pull request: %w", err)
373+
if pr != nil {
374+
return fmt.Errorf("pull request update failed: %w", err)
375+
}
376+
return fmt.Errorf("pull request create failed: %w", err)
371377
}
372-
373-
fmt.Fprintln(opts.IO.Out, pr.URL)
374378
} else if action == shared.PreviewAction {
375379
openURL, err := generateCompareURL(baseRepo, baseBranch, headBranchLabel, title, body, tb.Assignees, tb.Labels, tb.Projects, tb.Milestones)
376380
if err != nil {

0 commit comments

Comments
 (0)