Skip to content

[jsweep] Clean add_workflow_run_comment.cjs#26161

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
jsweep/clean-add-workflow-run-comment-0d1886a87675ee5b
Draft

[jsweep] Clean add_workflow_run_comment.cjs#26161
github-actions[bot] wants to merge 1 commit intomainfrom
jsweep/clean-add-workflow-run-comment-0d1886a87675ee5b

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

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.cjs

Extracted buildCommentBody() helper

  • Moved all comment body assembly (sanitization, lock notice, workflow-id marker, tracker-id marker, reaction type marker) into a dedicated function
  • Separates body construction from API dispatch logic, making each function single-purpose

Extracted postDiscussionComment() helper

  • Unified the two near-identical GraphQL mutation blocks (discussion vs discussion_comment) into one function with an optional replyToNodeId parameter
  • Eliminates ~30 lines of duplicated mutation code

Merged duplicate switch cases

  • issues and issue_comment cases share identical logic → merged with fall-through
  • pull_request and pull_request_review_comment cases share identical logic → merged with fall-through
  • Removes ~15 lines of duplicated code while preserving all behavior

Removed redundant core.error in catch block

  • The catch block was calling core.error followed immediately by core.warning for the same error
  • The comment explicitly says "Don't fail the job - just warn since this is not critical"
  • Removed core.error (which creates a red error annotation) and kept only core.warning

add_workflow_run_comment.test.cjs

Added 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 types
  • postDiscussionComment() — 3 tests covering top-level comment, threaded reply with replyToId, and output setting
  • Missing PR number for pull_request_review_comment — 1 test (gap in original coverage)

Context

  • Execution context: github-script (globals: github, core, context)
  • File: actions/setup/js/add_workflow_run_comment.cjs

Validation ✅

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: npm run test:js — 32 passed ✓ (all 21 original tests + 11 new tests)

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • invalid.example.invalid

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "invalid.example.invalid"

See Network Configuration for more information.

Generated by jsweep - JavaScript Unbloater · ● 2.6M ·

  • expires on Apr 16, 2026, 4:47 AM UTC

- 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>
@github-actions
Copy link
Copy Markdown
Contributor Author

Great work from the jsweep automation! 🎉 This refactor of add_workflow_run_comment.cjs is clean, well-scoped, and comes with thorough test coverage. The extracted buildCommentBody() and postDiscussionComment() helpers make the code considerably easier to reason about, and the merged switch fall-throughs neatly eliminate duplicated branches.

The PR looks well-aligned with the project's agentic development workflow and is ready for maintainer review.

Generated by Contribution Check · ● 2.7M ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants