Skip to content

Duplicate Code: Update Handler Pattern Across update_issue/update_pull_request/update_discussion #16739

@github-actions

Description

@github-actions

🔍 Duplicate Code Detected: Update Handler Pattern Across Safe Outputs

Analysis of commit 8859937

Assignee: @copilot

Summary

The update_* safe-output handlers share a repeated structure for resolving target numbers, building update payloads, formatting success results, and wiring the handler factory. The pattern appears in at least three files and spans >10 lines each, indicating a clear refactoring opportunity into a shared helper/factory layer.

Duplication Details

Pattern: Update handler skeleton (resolve/build/format + factory wiring)

  • Severity: Medium

  • Occurrences: 3

  • Locations:

  • actions/setup/js/update_issue.cjs:93

  • actions/setup/js/update_pull_request.cjs:70

  • actions/setup/js/update_discussion.cjs:70

  • Code Sample:

function resolveXNumber(item, updateTarget, context) {
  const targetResult = resolveTarget({
    targetConfig: updateTarget,
    item: { ...item, item_number: item.issue_number },
    context: context,
    itemType: "update_issue",
    supportsPR: false,
    supportsIssue: true,
  });
  if (!targetResult.success) {
    return { success: false, error: targetResult.error };
  }
  return { success: true, number: targetResult.number };
}

Impact Analysis

  • Maintainability: Changes to update handler behavior (validation, result formatting, or configuration defaults) must be applied manually across multiple files.
  • Bug Risk: Inconsistent updates can introduce subtle behavior drift between issue/PR/discussion updates.
  • Code Bloat: Repeated scaffolding adds noise and makes future modifications harder to review.

Refactoring Recommendations

  1. Extract a shared update-handler scaffold
  • Extract common resolve/build/format/factory wiring into a createStandardUpdateHandler helper in actions/setup/js/update_handler_factory.cjs.
  • Estimated effort: Medium (2-4 hours)
  • Benefits: One place to evolve defaults, validation, and structured responses.
  1. Introduce per-type configuration hooks
  • Use a per-type config object for item-specific differences (issue vs PR vs discussion), while the shared scaffold handles wiring and defaults.
  • Estimated effort: Low to Medium (1-3 hours)
  • Benefits: Removes repeated setup while preserving the custom per-type logic.

Implementation Checklist

  • Review duplication findings
  • Prioritize refactoring tasks
  • Create refactoring plan
  • Implement changes
  • Update tests
  • Verify no functionality broken

Analysis Metadata

  • Analyzed Files: 3
  • Detection Method: Serena semantic code analysis
  • Commit: 8859937
  • Analysis Date: 2026-02-19

Generated by Duplicate Code Detector

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions