Skip to content

[duplicate-code] Duplicate Code: skip-if query handlers in setup JS #42911

Description

@github-actions

🔍 Duplicate Code Detected: skip-if query handlers

Analysis of commit 9866d47

Summary

actions/setup/js/check_skip_if_match.cjs and actions/setup/js/check_skip_if_no_match.cjs share the same control flow for validating env vars, running the GitHub search, and writing the denial summary. The only meaningful differences are the threshold comparison, env var name, output key, and message text.

Duplication Details

Pattern: skip-query threshold handlers

  • Severity: Medium
  • Occurrences: 2
  • Locations:
    • actions/setup/js/check_skip_if_match.cjs (lines 9-54)
    • actions/setup/js/check_skip_if_no_match.cjs (lines 9-54)
  • Code Sample:
const { GH_AW_SKIP_QUERY: skipQuery, GH_AW_WORKFLOW_NAME: workflowName, GH_AW_SKIP_MAX_MATCHES: maxMatchesStr = "1", GH_AW_SKIP_SCOPE: skipScope } = process.env;
...
const searchQuery = buildSearchQuery(skipQuery, skipScope);
...
const { data: { total_count: totalCount } } = await github.rest.search.issuesAndPullRequests({ q: searchQuery, per_page: 1 });
...
if (totalCount >= maxMatches) { ... }

Impact Analysis

  • Maintainability: Changes to validation, search behavior, or denial-summary formatting have to be mirrored in two places.
  • Bug Risk: One path can drift from the other and produce inconsistent skip behavior.
  • Code Bloat: The same handler skeleton is duplicated instead of parameterized.

Refactoring Recommendations

  1. Extract a shared runSkipQueryCheck helper.

    • Pass in env var names, comparison mode, output key, and user-facing messages.
    • Keep only the mode-specific wrapper in each file.
  2. Consolidate the shared search/validation flow into a small factory.

    • This makes the threshold semantics explicit and reduces copy-paste edits.

Implementation Checklist

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

Analysis Metadata

  • Analyzed Files: 4
  • Detection Method: Serena semantic code analysis
  • Commit: 9866d47
  • Analysis Date: 2026-07-02

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by 🔍 Duplicate Code Detector · 4.33 AIC · ⌖ 0.837 AIC · ⊞ 25.7K ·

  • expires on Jul 3, 2026, 10:32 PM UTC-08:00

Metadata

Metadata

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions