Skip to content

Commit aaf4593

Browse files
committed
review and refactor handler
1 parent 269e8a5 commit aaf4593

4 files changed

Lines changed: 12 additions & 13 deletions

File tree

pkg/event/event.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ type CommentEvent struct {
2121
CommentBody string
2222
// CommentAuthor is the login of the comment author.
2323
CommentAuthor string
24-
2524
// IsReviewComment indicates this came from a pull_request_review_comment event.
2625
IsReviewComment bool
26+
// IsReviewComment indicates this came from a pull_request_review_comment event.
27+
IsIssueComment bool
2728
// DiffHunk is the diff hunk associated with a review comment (empty for issue comments).
2829
DiffHunk string
2930
// FilePath is the file path associated with a review comment (empty for issue comments).

pkg/event/issue_comment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ func parseIssueComment(eventPath string) (*CommentEvent, error) {
5858
IsReviewComment: false,
5959
KeywordDetected: detected,
6060
SkillOverride: skillOverride,
61+
IsIssueComment: true,
6162
}, nil
6263
}

pkg/event/review_comment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ func parseReviewComment(eventPath string) (*CommentEvent, error) {
5757
Line: payload.Comment.Line,
5858
KeywordDetected: detected,
5959
SkillOverride: skillOverride,
60+
IsIssueComment: false,
6061
}, nil
6162
}

pkg/handler/handler.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func New(token, claudeKey, claudeModel string, dryRun bool, skillsDir string) *H
3636
}
3737
}
3838

39-
// ClassifyResult holds the classification outputs for use by callers.
4039
type ClassifyResult struct {
4140
Detected bool
4241
SkillName string
@@ -70,7 +69,7 @@ func (h *Handler) HandleGithubEvent(githubEventName, githubEventPath string) (*C
7069

7170
reactor := ghcontext.NewReactor(h.token)
7271
if err := reactor.AddReaction(ctx, event.RepoOwner, event.RepoName, event.CommentID, event.IsReviewComment, "eyes"); err != nil {
73-
log.Printf("Warning: failed to add eyes reaction: %v", err)
72+
log.Printf("failed to add eyes reaction: %s", err)
7473
}
7574

7675
var promptParams classifier.PromptParams
@@ -85,12 +84,13 @@ func (h *Handler) HandleGithubEvent(githubEventName, githubEventPath string) (*C
8584
gh := ghcontext.New(h.token)
8685
prCtx, err := gh.FetchPRContext(ctx, event.RepoOwner, event.RepoName, event.PRNumber)
8786
if err != nil {
88-
log.Printf("Warning: failed to gather PR context: %v", err)
87+
log.Printf("failed to gather pr context: %v", err)
8988
promptParams.PRTitle = "(unknown)"
9089
} else {
9190
promptParams.PRTitle = prCtx.PRTitle
9291
}
93-
} else {
92+
}
93+
if event.IsIssueComment {
9494
gh := ghcontext.New(h.token)
9595
prCtx, err := gh.FetchPRContext(ctx, event.RepoOwner, event.RepoName, event.PRNumber)
9696
if err != nil {
@@ -101,17 +101,17 @@ func (h *Handler) HandleGithubEvent(githubEventName, githubEventPath string) (*C
101101
promptParams.ChangedFiles = ghcontext.FormatChangedFiles(prCtx.ChangedFiles)
102102
}
103103

104-
cls := classifier.New(h.claudeKey, h.claudeModel)
105-
result, err := cls.Classify(ctx, promptParams)
104+
claudeClassifier := classifier.New(h.claudeKey, h.claudeModel)
105+
result, err := claudeClassifier.Classify(ctx, promptParams)
106106
if err != nil {
107107
if reactErr := reactor.AddReaction(ctx, event.RepoOwner, event.RepoName, event.CommentID, event.IsReviewComment, "confused"); reactErr != nil {
108-
log.Printf("Warning: failed to add confused reaction: %v", reactErr)
108+
log.Printf("failed to add confused reaction: %v", reactErr)
109109
}
110110
return nil, fmt.Errorf("classifying comment: %w", err)
111111
}
112112

113113
if result.IsEmpty() {
114-
log.Println("Comment not a substantive learning, skipping")
114+
log.Println("comment not a substantive learning, skipping")
115115
if err := setOutput("detected", "false"); err != nil {
116116
return nil, err
117117
}
@@ -174,8 +174,6 @@ func (h *Handler) HandleGithubEvent(githubEventName, githubEventPath string) (*C
174174
}, nil
175175
}
176176

177-
// listExistingSkills scans dir for subdirectories containing a SKILL.md file
178-
// and returns their directory names.
179177
func listExistingSkills(dir string) []string {
180178
if dir == "" {
181179
return nil
@@ -194,7 +192,6 @@ func listExistingSkills(dir string) []string {
194192
if relErr != nil {
195193
return nil
196194
}
197-
// Only include top-level skill directories (not nested paths).
198195
if !strings.Contains(rel, string(os.PathSeparator)) {
199196
skills = append(skills, rel)
200197
}
@@ -204,7 +201,6 @@ func listExistingSkills(dir string) []string {
204201
return skills
205202
}
206203

207-
// setOutput writes a key=value pair to the GITHUB_OUTPUT file.
208204
func setOutput(key, value string) error {
209205
outputFile := os.Getenv("GITHUB_OUTPUT")
210206
if outputFile == "" {

0 commit comments

Comments
 (0)