Skip to content

[duplicate-code] Duplicate Code: body update and attribution flow in safe-output handlers #51645

Description

@github-actions

🔍 Duplicate Code Detected: Update Body and Attribution Pipeline

Analysis of commit 2b4a6df88d5ea6216b577a0af184f9cecff96771

Assignee: @copilot

Duplicate update-handler report - 2026-08-09

Summary

executeIssueUpdate and executePRUpdate both implement the same multi-step body update pipeline: fetch current entity body, derive workflow attribution metadata, generate a history URL, call updateBody, and write the transformed body back into API payloads. The shared block is large enough that future footer or history-link changes are likely to drift.

Duplication Details

Pattern: body update and AI attribution flow in safe-output update handlers

  • Severity: Medium
  • Occurrences: 2
  • Locations:
    • actions/setup/js/update_issue.cjs (lines 33-117)
    • actions/setup/js/update_pull_request.cjs (lines 86-167)
  • Code Sample:
const workflowName = process.env.GH_AW_WORKFLOW_NAME || "GitHub Agentic Workflow";
const workflowId = process.env.GH_AW_WORKFLOW_ID || "";
const callerWorkflowId = process.env.GH_AW_CALLER_WORKFLOW_ID || "";
const workflowRepo = _workflowRepo || context.repo;
const runUrl = buildWorkflowRunUrl(context, workflowRepo);

const historyUrl =
  generateHistoryUrl({
    owner: context.repo.owner,
    repo: context.repo.repo,
    itemType: "...",
    workflowCallId: callerWorkflowId,
    workflowId,
    serverUrl: context.serverUrl,
  }) || undefined;

apiData.body = updateBody({
  currentBody,
  newContent: rawBody,
  operation,
  workflowName,
  runUrl,
  workflowId,
  includeFooter,
  historyUrl,
});

Impact Analysis

  • Maintainability: footer, history-link, or workflow metadata changes must be edited in multiple handlers.
  • Bug Risk: a subtle behavior fix in one handler can be missed in the other, especially around default operations and body fetch conditions.
  • Code Bloat: the duplicated orchestration obscures the entity-specific logic that actually differs.

Refactoring Recommendations

  1. Extract a shared body-update helper

    • Move current-body loading, workflow attribution assembly, and updateBody invocation behind a shared helper that accepts an entity fetcher and itemType.
    • Estimated effort: 2-3 hours
    • Benefits: one place to maintain footer and history-link behavior.
  2. Keep entity-specific hooks explicit

    • Preserve issue-only behavior such as temporary project replacement and label intent handling through optional pre/post hooks rather than duplicating the full pipeline.
    • Estimated effort: 1-2 hours
    • Benefits: shared flow without hiding real differences.

Implementation Checklist

  • Identify the exact shared inputs for issue and pull request body updates
  • Extract a helper for workflow metadata and updateBody assembly
  • Reintroduce issue-specific temporary project replacement as a hook
  • Re-run existing update handler tests for issue and pull request flows
  • Add one regression test that proves both handlers use the same footer/history behavior

Analysis Metadata

  • Analyzed Files: targeted review of 14 files within 1,599 eligible changed .go/.cjs paths in the shallow initial-import snapshot
  • Detection Method: Serena-guided analysis and targeted source inspection
  • Commit: 2b4a6df88d5ea6216b577a0af184f9cecff96771
  • Analysis Date: 2026-08-09T22:01:37Z

Generated by 🔍 Duplicate Code Detector · gpt54 · 103.8 AIC · ⊞ 12.8K ·

  • expires on Aug 11, 2026, 2:04 PM UTC-08:00

Activity

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions