fix(workflow): repost a review without inline comments when the forge refuses their placement
This commit is contained in:
1 file changed
+22
-4
@@ -688,7 +688,7 @@ func postApprovedReview(ctx context.Context, tc *TaskContext, gate task.ReviewGa
|
||||
if len(posted) == 0 {
|
||||
return "operator approved no findings; nothing posted", nil
|
||||
}
|
||||
if err := tc.Forge.CreateReviewComments(ctx, gate.Owner, gate.Repo, gate.PRNumber, gate.HeadSHA, forgeReview(posted, tc.prReview.files)); err != nil {
|
||||
if err := postReview(ctx, tc, gate.Owner, gate.Repo, gate.PRNumber, gate.HeadSHA, posted); err != nil {
|
||||
return "", fmt.Errorf("post approved review: %w", err)
|
||||
}
|
||||
return fmt.Sprintf("posted %d finding(s) approved by the operator as %s", len(posted), prreview.ReviewEventFor(posted)), nil
|
||||
@@ -723,9 +723,27 @@ func postPRReview(ctx context.Context, tc *TaskContext) error {
|
||||
if len(tc.prReview.scored) == 0 {
|
||||
return nil
|
||||
}
|
||||
return tc.Forge.CreateReviewComments(
|
||||
ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.PRNumber, tc.prReview.headSHA, forgeReview(tc.prReview.scored, tc.prReview.files),
|
||||
)
|
||||
return postReview(ctx, tc, tc.Task.Owner, tc.Task.Repo, tc.Task.PRNumber, tc.prReview.headSHA, tc.prReview.scored)
|
||||
}
|
||||
|
||||
// postReview posts findings as one review. A forge that refuses an inline
|
||||
// placement rejects the whole review, so on failure the findings are posted
|
||||
// again with none inline.
|
||||
func postReview(ctx context.Context, tc *TaskContext, owner, repo string, number int, headSHA string, findings []prreview.ScoredFinding) error {
|
||||
review := forgeReview(findings, tc.prReview.files)
|
||||
err := tc.Forge.CreateReviewComments(ctx, owner, repo, number, headSHA, review)
|
||||
if err == nil || len(review.Comments) == 0 {
|
||||
return err
|
||||
}
|
||||
places := make([]string, 0, len(review.Comments))
|
||||
for _, c := range review.Comments {
|
||||
places = append(places, fmt.Sprintf("%s:%d", c.Path, c.Line))
|
||||
}
|
||||
tc.Log.Warn("forge refused inline review comments; posting them in the body", "err", err, "inline", places)
|
||||
if retry := tc.Forge.CreateReviewComments(ctx, owner, repo, number, headSHA, forgeReview(findings, nil)); retry != nil {
|
||||
return fmt.Errorf("%w (inline at %s); without inline comments: %w", err, strings.Join(places, ", "), retry)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// runPRReviewAgent runs one read-only agent call in workspace and returns an
|
||||
|
||||
Reference in new issue
Block a user