fix(cmd,github): address review feedback on PR #106
PR Ready Gate / clear-labels (pull_request) Successful in 2s
CI / test (pull_request) Successful in 19s
CI / review (anthropic--claude-4.6-sonnet, sonnet, SONNET_REVIEW_TOKEN) (pull_request) Successful in 47s
CI / review (gpt-5, security, ., rodin/security-patterns, SECURITY_REVIEW.md, SECURITY_REVIEW_TOKEN) (pull_request) Successful in 1m38s
CI / review (gpt-5, gpt, GPT_REVIEW_TOKEN) (pull_request) Successful in 1m49s
PR Ready Gate / clear-labels (pull_request) Successful in 2s
CI / test (pull_request) Successful in 19s
CI / review (anthropic--claude-4.6-sonnet, sonnet, SONNET_REVIEW_TOKEN) (pull_request) Successful in 47s
CI / review (gpt-5, security, ., rodin/security-patterns, SECURITY_REVIEW.md, SECURITY_REVIEW_TOKEN) (pull_request) Successful in 1m38s
CI / review (gpt-5, gpt, GPT_REVIEW_TOKEN) (pull_request) Successful in 1m49s
- Replace panic() with fmt.Fprintf+os.Exit(1) in provider switch default (repo convention: never panic) - Remove spurious 'event' field from DismissReview payload (GitHub dismiss endpoint only documents 'message') - Change translateReviewEvent default to return 'COMMENT' as canonical fallback instead of passing unknown events through to GitHub API - Refactor supersedeOldReviews to use explicit switch/case with default error for exhaustiveness
This commit is contained in:
@@ -170,7 +170,8 @@ func main() {
|
||||
}
|
||||
client = github.NewClient(*reviewerToken, ghBaseURL)
|
||||
default:
|
||||
panic("unreachable: unhandled provider " + *provider)
|
||||
fmt.Fprintf(os.Stderr, "Error: unhandled provider %q\n", *provider)
|
||||
os.Exit(1)
|
||||
}
|
||||
slog.Info("VCS client initialized", "provider", *provider)
|
||||
|
||||
@@ -523,7 +524,8 @@ func verdictToEvent(verdict string) vcs.ReviewEvent {
|
||||
// For GitHub: dismisses old reviews.
|
||||
// For Gitea: edits the review body and resolves inline comments.
|
||||
func supersedeOldReviews(ctx context.Context, client vcs.Client, provider, vcsURL, owner, repoName string, prNumber int, oldReviews []vcs.Review, newReviewID int64, sentinel string) error {
|
||||
if provider == "github" {
|
||||
switch provider {
|
||||
case "github":
|
||||
for _, old := range oldReviews {
|
||||
if err := client.DismissReview(ctx, owner, repoName, prNumber, old.ID, "Superseded by new review"); err != nil {
|
||||
slog.Warn("failed to dismiss review", "id", old.ID, "error", err)
|
||||
@@ -532,9 +534,12 @@ func supersedeOldReviews(ctx context.Context, client vcs.Client, provider, vcsUR
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "gitea":
|
||||
// Gitea: EditComment + ResolveComment flow
|
||||
default:
|
||||
return fmt.Errorf("supersedeOldReviews: unsupported provider %q", provider)
|
||||
}
|
||||
|
||||
// Gitea: existing EditComment + ResolveComment flow
|
||||
giteaAdapter, ok := client.(*gitea.Adapter)
|
||||
if !ok {
|
||||
return fmt.Errorf("expected gitea.Adapter for gitea provider, got %T", client)
|
||||
|
||||
+1
-3
@@ -42,7 +42,6 @@ type reviewCommentCreate struct {
|
||||
// dismissReviewRequest is the GitHub API request body for dismissing a review.
|
||||
type dismissReviewRequest struct {
|
||||
Message string `json:"message"`
|
||||
Event string `json:"event"`
|
||||
}
|
||||
|
||||
// userResponse is the GitHub API response for the authenticated user.
|
||||
@@ -60,7 +59,7 @@ func translateReviewEvent(event vcs.ReviewEvent) string {
|
||||
case vcs.ReviewEventComment:
|
||||
return "COMMENT"
|
||||
default:
|
||||
return string(event)
|
||||
return "COMMENT"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +160,6 @@ func (c *Client) DismissReview(ctx context.Context, owner, repo string, number i
|
||||
|
||||
payload := dismissReviewRequest{
|
||||
Message: message,
|
||||
Event: "DISMISS",
|
||||
}
|
||||
|
||||
_, err := c.doJSONRequest(ctx, http.MethodPut, reqURL, payload)
|
||||
|
||||
Reference in New Issue
Block a user