feat(forge): pull request review read surface (ListReviews/ListReviewComments/ReplyToReview)
Add a forge-neutral PullRequestReviewReader (type-asserted, like the noop forge gap) so archie can react to review activity on a PR it opened. GitHub and Gitea implementations normalise review state to approved/requested_changes/commented/ dismissed and apply a sinceID dedup cursor. First slice of archie-core-8li9 (PR review comment remediation).
This commit is contained in:
1 parent
da28ddb5e6
commit
80d2bbf899
4 files changed
+399
No files matched your search
@@ -7,6 +7,8 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// New creates a Forge implementation for the given type.
|
||||
@@ -113,3 +115,67 @@ type RepoForge interface {
|
||||
// development link in the issue sidebar.
|
||||
LinkBranch(ctx context.Context, owner, repo string, issueNumber int, branch string) error
|
||||
}
|
||||
|
||||
// ReviewState values for Review.State, normalised across forges.
|
||||
const (
|
||||
ReviewStateApproved = "approved"
|
||||
ReviewStateRequestedChanges = "requested_changes"
|
||||
ReviewStateCommented = "commented"
|
||||
ReviewStateDismissed = "dismissed"
|
||||
)
|
||||
|
||||
// Review is a forge-neutral review of an existing PR: an approval, a
|
||||
// request-changes, a plain comment, or a dismissal.
|
||||
type Review struct {
|
||||
ID int64
|
||||
Author string
|
||||
State string // one of the ReviewState* constants
|
||||
SubmittedAt time.Time
|
||||
}
|
||||
|
||||
// ReviewComment is a forge-neutral review comment on an existing PR.
|
||||
// Line is a location hint, not authoritative: the remediation agent reads
|
||||
// the whole file. InReplyTo is the parent comment ID on GitHub; Gitea's
|
||||
// inline comments are flat under a review, so it is 0 there.
|
||||
type ReviewComment struct {
|
||||
ID int64
|
||||
Author string
|
||||
Body string
|
||||
Path string
|
||||
Line int
|
||||
InReplyTo int64
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// PullRequestReviewReader reads review activity on an existing PR. Forge
|
||||
// implementations that cannot read reviews (the noop forge) do not implement
|
||||
// it; callers type-assert and refuse when the capability is absent.
|
||||
//
|
||||
// sinceID is the dedup cursor: only entries with ID > sinceID are returned,
|
||||
// so a poller and a webhook delivery of the same comment collapse on the same
|
||||
// ID (the TaskEnvelope.IdempotencyKey pattern applied to reviews).
|
||||
type PullRequestReviewReader interface {
|
||||
ListReviews(ctx context.Context, owner, repo string, number int, sinceID int64) ([]Review, error)
|
||||
ListReviewComments(ctx context.Context, owner, repo string, number int, sinceID int64) ([]ReviewComment, error)
|
||||
// ReplyToReview posts a reply to an existing review comment (commentID).
|
||||
// A summary for a whole review (e.g. "requested changes" addressed) is a
|
||||
// plain PR comment via Forge.Comment, not this method.
|
||||
ReplyToReview(ctx context.Context, owner, repo string, number int, commentID int64, body string) error
|
||||
}
|
||||
|
||||
// normalizeReviewState maps a GitHub review state string onto the neutral
|
||||
// ReviewState* constants. Unknown states pass through lowercased.
|
||||
func normalizeReviewState(s string) string {
|
||||
switch s {
|
||||
case "APPROVED":
|
||||
return ReviewStateApproved
|
||||
case "CHANGES_REQUESTED":
|
||||
return ReviewStateRequestedChanges
|
||||
case "COMMENTED":
|
||||
return ReviewStateCommented
|
||||
case "DISMISSED":
|
||||
return ReviewStateDismissed
|
||||
default:
|
||||
return strings.ToLower(s)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user