Skip to content

Commit

Permalink
handle pr for branch case
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed May 7, 2020
1 parent d81e622 commit 5dbec25
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions command/pr_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down

0 comments on commit 5dbec25

Please sign in to comment.