Refactor: Extract duplicate comment helpers into separate modules#3565
Refactor: Extract duplicate comment helpers into separate modules#3565
Conversation
- Create new comment_helpers.cjs with generateFooter() and getRepositoryUrl() - Add comprehensive tests for the new module (17 test cases) - Refactor create_issue.cjs to use shared helpers - Refactor add_comment.cjs to use shared helpers - Refactor create_pr_review_comment.cjs to use shared helpers - Add comment_helpers.cjs to Go embedded sources - All tests pass (780 JavaScript tests + Go unit tests) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
| * This helper handles trial mode where target repository URLs are different from execution context | ||
| * @returns {string} Repository URL | ||
| */ | ||
| function getRepositoryUrl() { |
There was a problem hiding this comment.
Split into separate files following the repository pattern:
generate_footer.cjs- Footer generation helperget_repository_url.cjs- Repository URL helper
Each with their own test files. All 780 JavaScript tests + Go unit tests pass.
Commit: da12d73
- Split comment_helpers.cjs into generate_footer.cjs and get_repository_url.cjs - Create separate test files for each helper - Update all consumers to import from separate modules - Update Go embedded sources to register both new modules - All tests pass (780 JavaScript tests + Go unit tests) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
| return `${githubServer}/${context.repo.owner}/${context.repo.repo}`; | ||
| } | ||
| } | ||
| generateFooter, |
There was a problem hiding this comment.
@copilot looks like invalid generated JavaScript , check bundler code
There was a problem hiding this comment.
Fixed. Changed module.exports to single-line format to match the repository pattern (like sanitize_content.cjs). The bundler now correctly removes the entire export statement instead of leaving dangling fragments.
Before (multi-line):
module.exports = {
generateFooter,
};After (single-line):
module.exports = { generateFooter };All 780 JavaScript tests + Go tests pass. Lock files now contain valid JavaScript.
Commit: 9eae7b7
- Change module.exports from multi-line to single-line format - Fixes invalid JavaScript generation in bundled lock files - Follows repository pattern used by other helper modules - All 780 JavaScript tests + Go unit tests pass Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot revert previous commit, merge main |
This reverts commit 9eae7b7. The bundler fix is already included in main branch. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ent-output-helpers
- Regenerate all 26 lock files with bundled helper functions - generateFooter and getRepositoryUrl properly inlined - All 780 JavaScript tests pass Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR successfully refactors duplicate comment helper code by extracting shared footer generation and repository URL logic into separate, reusable modules. The refactoring eliminates ~154 lines of duplicate code across three safe-output scripts while maintaining full test coverage and following the repository's established patterns.
Key Changes:
- Creates two focused helper modules (
generate_footer.cjsandget_repository_url.cjs) with comprehensive test suites - Updates three consumer scripts to use the new shared helpers via
require() - Properly registers both modules in Go's embedded JavaScript sources
- Successfully recompiles all 26 workflow lock files with correctly bundled helper functions
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/js/generate_footer.cjs |
New helper module for AI attribution footer generation with workflow context |
pkg/workflow/js/generate_footer.test.cjs |
Comprehensive test suite with 11 test cases covering all footer variations |
pkg/workflow/js/get_repository_url.cjs |
New helper module handling repository URL resolution in trial and normal modes |
pkg/workflow/js/get_repository_url.test.cjs |
Test suite with 6 test cases covering all URL resolution scenarios |
pkg/workflow/js/create_issue.cjs |
Refactored to import and use generateFooter helper |
pkg/workflow/js/add_comment.cjs |
Refactored to import both generateFooter and getRepositoryUrl helpers |
pkg/workflow/js/create_pr_review_comment.cjs |
Refactored to import both helpers for PR review comment creation |
pkg/workflow/js.go |
Added embed directives and registration for both new helper modules |
.github/workflows/*.lock.yml (26 files) |
Recompiled workflows with correctly inlined helper functions via bundler |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Refactor: Extract Duplicate Comment Output Helpers
This PR addresses duplicate code in comment-related safe-output scripts by extracting shared footer generation and repository URL helper logic into separate modules following the repository's pattern.
Plan
comment_helpers.cjswith:generateFooter()functiongetRepositoryUrl()functioncreate_issue.cjsto use shared helpersadd_comment.cjsto use shared helperscreate_pr_review_comment.cjsto use shared helpersChanges Made
Split into separate modules following repository pattern:
pkg/workflow/js/generate_footer.cjs- Footer generation helper (44 lines)pkg/workflow/js/generate_footer.test.cjs- Test suite (11 test cases)pkg/workflow/js/get_repository_url.cjs- Repository URL helper (27 lines)pkg/workflow/js/get_repository_url.test.cjs- Test suite (6 test cases)Modified Files:
pkg/workflow/js/create_issue.cjs- Updated importpkg/workflow/js/add_comment.cjs- Updated importspkg/workflow/js/create_pr_review_comment.cjs- Updated importspkg/workflow/js.go- Added both modules to embedded sources.lock.ymlfiles - Recompiled with bundled helpersTotal Impact:
Benefits
✅ Single point of truth for footer generation and repository URL logic
✅ Consistent messaging across all comment types (issues, PRs, discussions)
✅ Easier maintenance and future updates
✅ Follows repository pattern (one function per file)
✅ Comprehensive test coverage (17 total test cases split across 2 files)
✅ Valid bundled JavaScript (bundler fix from main handles multi-line exports)
✅ All workflows recompiled with updated helpers
✅ No functionality broken - all tests pass
Test Results
Merged from main
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.