evalAddComment checks whether a comment received replies, reactions, or was deleted/hidden.
(item CreatedItemReport, repoOverride string)
| 12 | |
| 13 | // evalAddComment checks whether a comment received replies, reactions, or was deleted/hidden. |
| 14 | func evalAddComment(item CreatedItemReport, repoOverride string) OutcomeReport { |
| 15 | repo := resolveItemRepo(item, repoOverride) |
| 16 | outcomeEvalCommentLog.Printf("Evaluating add_comment: repo=%s, url=%s", repo, item.URL) |
| 17 | report := OutcomeReport{ |
| 18 | Type: item.Type, |
| 19 | ObjectURL: item.URL, |
| 20 | Repo: repo, |
| 21 | } |
| 22 | |
| 23 | // Extract comment ID from URL: .../issues/123#issuecomment-456789 or .../comments/456789 |
| 24 | commentID := extractCommentID(item.URL) |
| 25 | if commentID == "" { |
| 26 | outcomeEvalCommentLog.Printf("Unable to extract comment ID from URL: %s", item.URL) |
| 27 | report.Result = OutcomeError |
| 28 | report.EvalError = "cannot extract comment ID from URL" |
| 29 | return report |
| 30 | } |
| 31 | |
| 32 | data, err := ghAPIGet("issues/comments/"+commentID, repo) |
| 33 | if err != nil { |
| 34 | // 404 means deleted |
| 35 | if errorutil.IsNotFoundError(err) { |
| 36 | outcomeEvalCommentLog.Printf("Comment %s deleted (404)", commentID) |
| 37 | report.Result = OutcomeRejected |
| 38 | report.Detail = "deleted" |
| 39 | return report |
| 40 | } |
| 41 | report.Result = OutcomeError |
| 42 | report.EvalError = err.Error() |
| 43 | return report |
| 44 | } |
| 45 | |
| 46 | // Check reactions |
| 47 | reactions, _ := data["reactions"].(map[string]any) |
| 48 | totalReactions := 0 |
| 49 | if reactions != nil { |
| 50 | if tc, ok := reactions["total_count"].(float64); ok { |
| 51 | totalReactions = int(tc) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // Check if the comment is minimized (hidden) |
| 56 | // The REST API field is "performed_via_github_app" but minimized state |
| 57 | // is not directly in REST. We approximate: if the comment body is empty |
| 58 | // or the node_id can be checked via GraphQL. For now, use reactions+replies. |
| 59 | |
| 60 | // To check replies, we need the issue number and look for comments posted after this one |
| 61 | issueNumber := parseNumberFromURL(item.URL) |
| 62 | replyCount := 0 |
| 63 | if issueNumber > 0 { |
| 64 | commentList, cerr := ghAPIGetArray(fmt.Sprintf("issues/%d/comments", issueNumber), repo) |
| 65 | if cerr == nil { |
| 66 | createdAt, _ := data["created_at"].(string) |
| 67 | for _, c := range commentList { |
| 68 | cCreatedAt, _ := c["created_at"].(string) |
| 69 | if cCreatedAt > createdAt { |
| 70 | user, _ := c["user"].(map[string]any) |
| 71 | login, _ := user["login"].(string) |
nothing calls this directly
no test coverage detected