From 5dbec25f449be011ecf8ec8e9bd7830143aac429 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Thu, 7 May 2020 14:27:33 -0500 Subject: [PATCH] handle pr for branch case --- command/pr_review.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/command/pr_review.go b/command/pr_review.go index e445acfc8..9754c178b 100644 --- a/command/pr_review.go +++ b/command/pr_review.go @@ -89,9 +89,10 @@ func prReview(cmd *cobra.Command, args []string) error { } var prNum int + branchWithOwner := "" if len(args) == 0 { - prNum, _, err = prSelectorForCurrentBranch(ctx, baseRepo) + prNum, branchWithOwner, err = prSelectorForCurrentBranch(ctx, baseRepo) if err != nil { return fmt.Errorf("could not query for pull request for current branch: %w", err) } @@ -114,9 +115,17 @@ func prReview(cmd *cobra.Command, args []string) error { return fmt.Errorf("did not understand desired review action: %w", err) } - pr, err := api.PullRequestByNumber(apiClient, baseRepo, prNum) - if err != nil { - return fmt.Errorf("could not find pull request: %w", err) + var pr *api.PullRequest + if prNum > 0 { + pr, err = api.PullRequestByNumber(apiClient, baseRepo, prNum) + if err != nil { + return fmt.Errorf("could not find pull request: %w", err) + } + } else { + pr, err = api.PullRequestForBranch(apiClient, baseRepo, "", branchWithOwner) + if err != nil { + return fmt.Errorf("could not find pull request: %w", err) + } } err = api.AddReview(apiClient, pr, input)