feat: inline review comments on specific lines #26

Merged
rodin merged 6 commits from feat/inline-review-comments into main 2026-05-02 06:13:02 +00:00
2 changed files with 31 additions and 6 deletions
Showing only changes of commit ec19622133 - Show all commits
+27 -5
View File
1
@@ -316,11 +316,35 @@ func main() {
// POST new review (first run, or state transition fallthrough)
log.Printf("Posting review (event=%s)...", event)
_, err = giteaClient.PostReview(ctx, owner, repoName, prNumber, event, reviewBody, inlineComments)
posted, err := giteaClient.PostReview(ctx, owner, repoName, prNumber, event, reviewBody, inlineComments)
if err != nil {
log.Fatalf("Failed to post review: %v", err)
}
log.Printf("Review posted successfully")
log.Printf("Review posted (id=%d, user=%s)", posted.ID, posted.User.Login)
// Post-posting escalation: if we just posted APPROVED but a sibling
// from the same user has REQUEST_CHANGES, mark ours as superseded and
// re-post as REQUEST_CHANGES. This handles the first-run case where
// we don't know our login until after posting.
if event == "APPROVED" && *updateExisting && *reviewerName != "" {
reviews, err := giteaClient.ListReviews(ctx, owner, repoName, prNumber)
if err == nil && shouldEscalate(reviews, posted.ID, posted.User.Login, sentinel) {
log.Printf("Post-posting escalation: sibling has REQUEST_CHANGES")
// Mark our just-posted review as superseded
commentID, err := giteaClient.GetTimelineReviewCommentID(ctx, owner, repoName, prNumber, sentinel)
if err == nil {
supersededBody := fmt.Sprintf("~~*This review has been superseded by a newer review below.*~~\n\n%s", sentinel)
giteaClient.EditComment(ctx, owner, repoName, commentID, supersededBody)
}
// Re-post as REQUEST_CHANGES
_, err = giteaClient.PostReview(ctx, owner, repoName, prNumber, "REQUEST_CHANGES", reviewBody, inlineComments)
if err != nil {
log.Printf("Warning: could not re-post as REQUEST_CHANGES: %v", err)
} else {
log.Printf("Review escalated to REQUEST_CHANGES")
}
}
}
}
// fetchFileContext fetches the full content of modified files from the PR branch.
3
@@ -508,9 +532,7 @@ func reviewUnchanged(reviews []gitea.Review, newBody, newEvent, sentinel string)
if !strings.Contains(r.Body, sentinel) {
continue
}
// Compare state (map APPROVED back from Gitea's representation)
existingEvent := r.State
if existingEvent == r.State && existingEvent == newEvent && r.Body == newBody {
if r.State == newEvent && r.Body == newBody {
return true
}
}
+4 -1
View File
2
@@ -407,7 +407,10 @@ func (c *Client) EditComment(ctx context.Context, owner, repo string, commentID
payload := struct {
Body string `json:"body"`
}{Body: newBody}
data, _ := json.Marshal(payload)
data, err := json.Marshal(payload)
if err != nil {
return fmt.Errorf("marshal edit payload: %w", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, reqURL, bytes.NewReader(data))
if err != nil {