🔍 Duplicate Code Detected: Comment Output Helpers
Analysis of commit 7292890
Assignee: @copilot
Summary
Multiple comment-related safe-output scripts reimplement the same footer generation and repository URL helper logic. Keeping three divergent copies makes it easy to miss fixes (for example when updating footer text or URL logic) and inflates maintenance cost.
Duplication Details
Pattern: Repeated footer/repository helper functions across comment scripts
- Severity: Medium
- Occurrences: 5 helper copies across 3 files
- Locations:
pkg/workflow/js/create_issue.cjs:19
pkg/workflow/js/add_comment.cjs:17
pkg/workflow/js/create_pr_review_comment.cjs:18
pkg/workflow/js/create_pr_review_comment.cjs:51
pkg/workflow/js/add_comment.cjs:142
- Code Sample:
function generateFooter(
workflowName,
runUrl,
workflowSource,
workflowSourceURL,
triggeringIssueNumber,
triggeringPRNumber,
triggeringDiscussionNumber
) {
let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`;
if (triggeringIssueNumber) {
footer += ` for #${triggeringIssueNumber}`;
} else if (triggeringPRNumber) {
footer += ` for #${triggeringPRNumber}`;
} else if (triggeringDiscussionNumber) {
footer += ` for discussion #${triggeringDiscussionNumber}`;
}
if (workflowSource && workflowSourceURL) {
footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\``;
}
footer += "\n";
return footer;
}
Impact Analysis
- Maintainability: Fixes to wording, attribution, or safe-output links must be applied in three places. A missed update will silently produce inconsistent comments.
- Bug Risk: Future behavior changes (e.g., adding more context links) risk diverging between issue comments, PR review comments, and general comments.
- Code Bloat: Each file carries ~40 extra lines of duplicated helpers, obscuring the core logic.
Refactoring Recommendations
-
Extract shared helpers
- Move footer generation and repository URL computation into a new shared module (e.g.,
pkg/workflow/js/comment_helpers.cjs).
- Estimated effort: 2-3 hours to introduce the module, add exports, and update imports/tests.
- Benefits: Single point of truth for messaging and URL logic, easier future evolution.
-
Add coverage to avoid regressions
- Extend existing unit tests to cover the new helper module and confirm each consumer uses it.
- Estimated effort: 1 hour for focused tests around footer content and URL selection.
Implementation Checklist
Analysis Metadata
- Analyzed Files: 3 primary scripts (additional utilities inspected for comparison)
- Detection Method: Serena semantic code analysis (symbol + pattern search)
- Commit: 7292890
- Analysis Date: 2025-11-09
AI generated by Duplicate Code Detector
🔍 Duplicate Code Detected: Comment Output Helpers
Analysis of commit 7292890
Assignee:
@copilotSummary
Multiple comment-related safe-output scripts reimplement the same footer generation and repository URL helper logic. Keeping three divergent copies makes it easy to miss fixes (for example when updating footer text or URL logic) and inflates maintenance cost.
Duplication Details
Pattern: Repeated footer/repository helper functions across comment scripts
pkg/workflow/js/create_issue.cjs:19pkg/workflow/js/add_comment.cjs:17pkg/workflow/js/create_pr_review_comment.cjs:18pkg/workflow/js/create_pr_review_comment.cjs:51pkg/workflow/js/add_comment.cjs:142Impact Analysis
Refactoring Recommendations
Extract shared helpers
pkg/workflow/js/comment_helpers.cjs).Add coverage to avoid regressions
Implementation Checklist
Analysis Metadata