Skip to content

Commit

Permalink
fix(reviewers): add requested reviewers when updating PR (#349)
Browse files Browse the repository at this point in the history
* fix(reviewers): add requested reviewers on PR update too

* refactor(pr): move the addition of contextual data to a PR into a reusable function
  • Loading branch information
Maximilien-R authored Aug 21, 2024
1 parent d128811 commit eca0eb4
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions repository/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,9 @@ func (r Repository) createPullRequest(ctx context.Context, options GitHubOptions
"pull-request": pr.GetHTMLURL(),
}).Info("New Pull Request created")

err = r.ensurePullRequestLabels(ctx, options, pr)
if err != nil {
return nil, fmt.Errorf("failed to ensure that Pull Request %s has the right labels: %w", pr.GetHTMLURL(), err)
}

err = r.addPullRequestComments(ctx, options, pr)
err = r.enrichPullRequestWithContextualData(ctx, options, pr)
if err != nil {
return nil, fmt.Errorf("failed to add comments to Pull Request %s: %w", pr.GetHTMLURL(), err)
}

err = r.addPullRequestAssignees(ctx, options, pr)
if err != nil {
return nil, fmt.Errorf("failed to add assignees to Pull Request %s: %w", pr.GetHTMLURL(), err)
}

err = r.addPullRequestReviewers(ctx, options, pr)
if err != nil {
return nil, fmt.Errorf("failed to add reviewers for Pull Request %s: %w", pr.GetHTMLURL(), err)
return nil, fmt.Errorf("failed to enrich the Pull Request %s: %w", pr.GetHTMLURL(), err)
}

return pr, nil
Expand Down Expand Up @@ -169,19 +154,9 @@ func (r Repository) updatePullRequest(ctx context.Context, options GitHubOptions
}).Debug("No need to update the Pull Request")
}

err = r.ensurePullRequestLabels(ctx, options, pr)
if err != nil {
return nil, fmt.Errorf("failed to ensure that Pull Request %s has the right labels: %w", pr.GetHTMLURL(), err)
}

err = r.addPullRequestComments(ctx, options, pr)
if err != nil {
return nil, fmt.Errorf("failed to add comments to Pull Request %s: %w", pr.GetHTMLURL(), err)
}

err = r.addPullRequestAssignees(ctx, options, pr)
err = r.enrichPullRequestWithContextualData(ctx, options, pr)
if err != nil {
return nil, fmt.Errorf("failed to add assignees to Pull Request %s: %w", pr.GetHTMLURL(), err)
return nil, fmt.Errorf("failed to enrich the Pull Request %s: %w", pr.GetHTMLURL(), err)
}

return pr, nil
Expand Down Expand Up @@ -338,6 +313,32 @@ func (r Repository) addPullRequestReviewers(ctx context.Context, options GitHubO
return nil
}

func (r Repository) enrichPullRequestWithContextualData(ctx context.Context, options GitHubOptions, pr *github.PullRequest) error {
var err error

err = r.ensurePullRequestLabels(ctx, options, pr)
if err != nil {
return fmt.Errorf("failed to ensure that Pull Request %s has the right labels: %w", pr.GetHTMLURL(), err)
}

err = r.addPullRequestComments(ctx, options, pr)
if err != nil {
return fmt.Errorf("failed to add comments to Pull Request %s: %w", pr.GetHTMLURL(), err)
}

err = r.addPullRequestAssignees(ctx, options, pr)
if err != nil {
return fmt.Errorf("failed to add assignees to Pull Request %s: %w", pr.GetHTMLURL(), err)
}

err = r.addPullRequestReviewers(ctx, options, pr)
if err != nil {
return fmt.Errorf("failed to add reviewers for Pull Request %s: %w", pr.GetHTMLURL(), err)
}

return nil
}

func (r Repository) mergePullRequest(ctx context.Context, options GitHubOptions, pr *github.PullRequest) error {
if options.PullRequest.Merge.Auto {
return r.mergePullRequestUsingAutoMerge(ctx, options, pr)
Expand Down

0 comments on commit eca0eb4

Please sign in to comment.