Skip to content

Refactor: Extract shared missing issue handler logic into missing_issue_helpers.cjs#17644

Merged
pelikhan merged 2 commits intomainfrom
copilot/refactor-duplicate-issue-handlers
Feb 22, 2026
Merged

Refactor: Extract shared missing issue handler logic into missing_issue_helpers.cjs#17644
pelikhan merged 2 commits intomainfrom
copilot/refactor-duplicate-issue-handlers

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

create_missing_data_issue.cjs and create_missing_tool_issue.cjs duplicated ~200 lines each — the entire handler pipeline (config parsing, search-or-create, comment/body construction, max-count enforcement) was identical except for field names and item renderers.

Changes

  • missing_issue_helpers.cjs (new) — exports buildMissingIssueHandler(options), parameterized over the parts that actually differ:

    • itemsField / templatePath / templateListKey — field and template routing
    • buildCommentHeader(runUrl) — header lines for existing-issue comments
    • renderCommentItem(item, index) / renderIssueItem(item, index) — item-level rendering
  • create_missing_data_issue.cjs — reduced from 228 → 43 lines; delegates to buildMissingIssueHandler with data-specific renderers (data_type, optional context)

  • create_missing_tool_issue.cjs — reduced from 221 → 42 lines; delegates with tool-specific renderers (backtick-formatted tool name)

  • missing_issue_helpers.test.cjs (new) — 14 tests covering validation, max-count, config extraction, comment-on-existing, create-new, labels, and API errors

const main = buildMissingIssueHandler({
  handlerType: HANDLER_TYPE,
  defaultTitlePrefix: "[missing data]",
  itemsField: "missing_data",
  templatePath: "/opt/gh-aw/prompts/missing_data_issue.md",
  templateListKey: "missing_data_list",
  buildCommentHeader: (runUrl) => [`## Missing Data Reported`, ``, `...during [workflow run](${runUrl}):`, ``],
  renderCommentItem: (item, index) => { /* data_type, reason, context, alternatives */ },
  renderIssueItem:   (item, index) => { /* same + timestamp */ },
});

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/github/gh-aw/contents/.github%2Fworkflows%2Faudit-workflows.md
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/dist/workers/forks.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Duplicate Code: Missing Issue Handlers in Actions Setup</issue_title>
<issue_description># 🔍 Duplicate Code Detected: Missing Issue Handlers

Analysis of commit 964cbd7

Assignee: @copilot

Summary

The handler logic for creating/updating “missing data” issues and “missing tool” issues is nearly identical across two action scripts. The duplication spans the full handler pipeline (config parsing, search-or-create issue, comment/issue body construction, and max-count enforcement), with only template paths and item-specific field names differing.

Duplication Details

Pattern: Missing issue handler pipeline

  • Severity: Medium
  • Occurrences: 2
  • Locations:
    • actions/setup/js/create_missing_data_issue.cjs:21
    • actions/setup/js/create_missing_tool_issue.cjs:21
  • Code Sample:
    async function main(config = {}) {
      const titlePrefix = config.title_prefix || "[missing data]";
      const envLabels = config.labels ? (Array.isArray(config.labels) ? config.labels : config.labels.split(",")).map(label => String(label).trim()).filter(label => label) : [];
      const maxCount = config.max || 1;
      // ... shared search-or-create issue logic ...
    }

Impact Analysis

  • Maintainability: Changes to issue/comment formatting, limits, or search strategy must be duplicated in two files.
  • Bug Risk: Fixes or improvements may diverge between the “missing data” and “missing tool” handlers.
  • Code Bloat: ~200+ lines duplicated across two scripts.

Refactoring Recommendations

  1. Extract shared handler builder

    • Move common logic to actions/setup/js/missing_issue_helpers.cjs (or similar).
    • Parameterize: title prefix default, template path, item list renderers, and message field keys.
    • Estimated effort: 2-4 hours
    • Benefits: single source of truth for issue creation workflow and formatting.
  2. Define item-specific renderers

    • Provide small functions that build comment/issue list entries from item objects (data vs tool).
    • Estimated effort: 1-2 hours
    • Benefits: isolates the only real differences and keeps core logic stable.

Implementation Checklist

  • Review duplication findings
  • Prioritize refactoring tasks
  • Create refactoring plan
  • Implement shared helper module
  • Update handlers to use shared helper
  • Update tests
  • Verify no functionality broken

Analysis Metadata

  • Analyzed Files: 2
  • Detection Method: Serena semantic code analysis
  • Commit: 964cbd7
  • Analysis Date: February 22, 2026

Generated by Duplicate Code Detector

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ue_helpers.cjs

- Create missing_issue_helpers.cjs with buildMissingIssueHandler() factory
- Refactor create_missing_data_issue.cjs to use shared helper
- Refactor create_missing_tool_issue.cjs to use shared helper
- Add missing_issue_helpers.test.cjs with 14 tests

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicate issue handlers in actions setup Refactor: Extract shared missing issue handler logic into missing_issue_helpers.cjs Feb 22, 2026
@pelikhan pelikhan marked this pull request as ready for review February 22, 2026 04:23
Copilot AI review requested due to automatic review settings February 22, 2026 04:23
@pelikhan pelikhan merged commit 1eae5af into main Feb 22, 2026
116 checks passed
@pelikhan pelikhan deleted the copilot/refactor-duplicate-issue-handlers branch February 22, 2026 04:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request successfully refactors duplicate code from create_missing_data_issue.cjs and create_missing_tool_issue.cjs into a shared helper module, reducing code duplication by approximately 200 lines per file.

Changes:

  • Created missing_issue_helpers.cjs with a parameterized buildMissingIssueHandler factory function that encapsulates the common issue creation/update pipeline
  • Refactored create_missing_data_issue.cjs from 228 lines to 42 lines by delegating to the new helper
  • Refactored create_missing_tool_issue.cjs from 221 lines to 42 lines by delegating to the new helper
  • Added comprehensive test coverage with 14 tests in missing_issue_helpers.test.cjs

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
actions/setup/js/missing_issue_helpers.cjs New shared helper module exporting buildMissingIssueHandler factory function that parameterizes item fields, templates, and renderers
actions/setup/js/missing_issue_helpers.test.cjs New comprehensive test suite covering validation, max count enforcement, config extraction, comment/issue creation, labels, and error handling
actions/setup/js/create_missing_data_issue.cjs Refactored to use buildMissingIssueHandler with data-specific renderers for data_type and optional context fields
actions/setup/js/create_missing_tool_issue.cjs Refactored to use buildMissingIssueHandler with tool-specific renderers for backtick-formatted tool names
Comments suppressed due to low confidence (1)

actions/setup/js/missing_issue_helpers.cjs:170

  • The JSDoc comment should include the resolvedTemporaryIds parameter to match the MessageHandlerFunction signature. Update the comment to:
/**
 * Message handler function that processes a single missing-issue message
 * @param {Object} message - The message to process
 * @param {Object} resolvedTemporaryIds - Resolved temporary IDs
 * @returns {Promise<Object>} Result with success/error status and issue details
 */
    /**
     * Message handler function that processes a single missing-issue message
     * @param {Object} message - The message to process
     * @returns {Promise<Object>} Result with success/error status and issue details
     */

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* @param {Object} message - The message to process
* @returns {Promise<Object>} Result with success/error status and issue details
*/
return async function handleMissingIssue(message) {
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned handler function should accept both message and resolvedTemporaryIds parameters to match the MessageHandlerFunction type signature and be consistent with all other handlers in the codebase. Currently it only accepts the message parameter.

Update the function signature to:

return async function handleMissingIssue(message, resolvedTemporaryIds) {

Even if resolvedTemporaryIds is not used in this handler, it must be included in the signature for API consistency.

This issue also appears on line 166 of the same file.

Suggested change
return async function handleMissingIssue(message) {
return async function handleMissingIssue(message, resolvedTemporaryIds) {

Copilot uses AI. Check for mistakes.
Comment on lines +210 to +213
if (result.success) {
processedIssues.push(result);
}

Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The processedIssues array is declared and populated but never used or returned. This appears to be dead code that was carried over from the original implementations. Consider removing it to reduce clutter, or if it's intended for future use, add a comment explaining its purpose.

Suggested change
if (result.success) {
processedIssues.push(result);
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate Code: Missing Issue Handlers in Actions Setup

3 participants