[jsweep] Clean add_workflow_run_comment.cjs#26161
Conversation
- Extract buildCommentBody() helper to separate body assembly from API call logic - Extract postDiscussionComment() helper to unify discussion/discussion_comment GraphQL calls - Merge duplicate issues/issue_comment and pull_request/pull_request_review_comment switch cases - Remove redundant core.error in catch block (keep only core.warning for non-critical errors) - Add 11 new tests: buildCommentBody(), postDiscussionComment(), missing PR number for pull_request_review_comment Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Refactors add_workflow_run_comment.cjs to reduce duplication and improve readability while expanding test coverage for the new helpers and an additional error path.
Changes:
- Extracted
buildCommentBody()to centralize comment-body construction (sanitization + markers + optional lock notice). - Extracted
postDiscussionComment()to unify GraphQL discussion comment posting (top-level vs reply). - Added targeted tests for the new helpers and for missing PR number in
pull_request_review_commentevents; updated API-error behavior expectation to warning-only.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/add_workflow_run_comment.cjs | Refactors comment construction + discussion posting into helpers; merges duplicated switch cases; removes non-critical core.error. |
| actions/setup/js/add_workflow_run_comment.test.cjs | Adds coverage for new helper functions and validates behavior changes (warning-only on API error, missing PR number case). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
🧪 Test Quality Sentinel ReportTest Quality Score: 83/100✅ Excellent test quality
Test Classification Details📋 All 12 tests (click to expand)
Flagged Tests — Requires ReviewNo tests require mandatory review. Minor observation below for optional improvement. 💡
|
|
@copilot review all comments |
Reviewed all comments:
No issues to address. |
|
Hey The PR looks well-structured with thorough test coverage (11 new tests covering the extracted helpers) and a detailed description. This looks ready for maintainer review! ✅
|
Summary
Cleaned
add_workflow_run_comment.cjs— a github-script context file that creates activation comments with workflow run links on issues, PRs, and discussions.Changes
add_workflow_run_comment.cjsExtracted
buildCommentBody()helperExtracted
postDiscussionComment()helperreplyToNodeIdparameterMerged duplicate switch cases
issuesandissue_commentcases share identical logic → merged with fall-throughpull_requestandpull_request_review_commentcases share identical logic → merged with fall-throughRemoved redundant
core.errorin catch blockcore.errorfollowed immediately bycore.warningfor the same errorcore.error(which creates a red error annotation) and kept onlycore.warningadd_workflow_run_comment.test.cjsAdded 11 new test cases (21 → 32 tests):
buildCommentBody()— 7 tests covering run URL inclusion, reaction marker, workflow-id marker, tracker-id marker, lock notice (issues vs pull_request), unknown event typespostDiscussionComment()— 3 tests covering top-level comment, threaded reply withreplyToId, and output settingpull_request_review_comment— 1 test (gap in original coverage)Context
github,core,context)actions/setup/js/add_workflow_run_comment.cjsValidation ✅
npm run format:cjs✓npm run lint:cjs✓npm run typecheck✓npm run test:js— 32 passed ✓ (all 21 original tests + 11 new tests)Warning
The following domain was blocked by the firewall during workflow execution:
invalid.example.invalidTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.