Skip to content

[code-simplifier] refactor: extract duplicate GitHub repo path regex to named constant - #24449

Merged
pelikhan merged 1 commit into
mainfrom
code-simplifier/2026-04-04-6f6793512de15120
Apr 4, 2026
Merged

pelikhan merged 1 commit into
mainfrom
code-simplifier/2026-04-04-6f6793512de15120

Conversation

@github-actions

@github-actions github-actions Bot commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Simplification of recently modified code from PR #24433.

The regex /^([^/]+)\/([^/]+)\/.+?(?:@(.+))?$/ was introduced in two places within check_workflow_timestamp_api.cjs by PR #24433:

  1. Line 60: parsing GITHUB_WORKFLOW_REF to extract owner/repo/ref
  2. Line 126: parsing a referenced_workflows path entry to extract owner/repo/ref

Both uses serve the same purpose — extracting owner, repo, and optional ref from a GitHub path like org/repo/.github/workflows/file.yml@refs/heads/main.

Files Simplified

  • actions/setup/js/check_workflow_timestamp_api.cjs — extracted duplicate regex to GITHUB_REPO_PATH_RE module-level constant

Improvements Made

  1. Reduced Duplication — identical regex appeared twice; now defined once
  2. Enhanced Clarity — named constant GITHUB_REPO_PATH_RE with a comment documents the pattern's purpose
  3. Easier Maintenance — any future change to the regex only needs to be made in one place

Changes Based On

Recent changes from:

Testing

  • ✅ All 42 tests pass (vitest run check_workflow_timestamp_api.test.cjs)
  • ✅ Linting passes (make lint-cjs)
  • ✅ Formatting passes (make fmt-cjs)
  • ✅ No functional changes — behavior is identical

Review Focus

Please verify:

  • Functionality is preserved
  • Named constant name and comment are clear
  • No unintended side effects

Automated by Code Simplifier Agent — analyzing code from the last 24 hours

Note

🔒 Integrity filter blocked 1 item

The following item were blocked because they don't meet the GitHub integrity level.

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Code Simplifier · ● 2.8M · ◷

  • expires on Apr 5, 2026, 6:06 AM UTC

Extract the repeated regex /^([^/]+)\/([^/]+)\/.+?(?:@(.+))?$/ (used in
both initial workflow ref parsing and referenced_workflows entry parsing)
to a module-level named constant GITHUB_REPO_PATH_RE.

This eliminates duplication added in PR #24433 and makes the intent of the
pattern explicit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review April 4, 2026 06:37
Copilot AI review requested due to automatic review settings April 4, 2026 06:37
@pelikhan
pelikhan merged commit 00656d1 into main Apr 4, 2026
51 checks passed
@pelikhan
pelikhan deleted the code-simplifier/2026-04-04-6f6793512de15120 branch April 4, 2026 06:37
@github-actions github-actions Bot mentioned this pull request Apr 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors check_workflow_timestamp_api.cjs to remove duplication by extracting the GitHub repo/workflow ref parsing regex into a single named module-level constant.

Changes:

  • Introduced GITHUB_REPO_PATH_RE (with an explanatory comment) to centralize the workflow ref parsing pattern.
  • Updated both call sites to use the shared constant instead of duplicating the same regex literal.
Show a summary per file
File Description
actions/setup/js/check_workflow_timestamp_api.cjs Deduplicates the owner/repo/ref extraction regex by introducing GITHUB_REPO_PATH_RE and reusing it in both parsing locations.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants