Skip to content

Commit 00656d1

Browse files
refactor: extract duplicate GitHub repo path regex to named constant (#24449)
1 parent b8af502 commit 00656d1

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

actions/setup/js/check_workflow_timestamp_api.cjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const { extractHashFromLockFile, computeFrontmatterHash, createGitHubFileReader
2222
const { getFileContent } = require("./github_api_helpers.cjs");
2323
const { ERR_CONFIG } = require("./error_codes.cjs");
2424

25+
// Matches GitHub workflow ref paths of the form "owner/repo/...[@ref]"
26+
// and captures: [1] owner, [2] repo, [3] optional ref
27+
const GITHUB_REPO_PATH_RE = /^([^/]+)\/([^/]+)\/.+?(?:@(.+))?$/;
28+
2529
async function main() {
2630
const workflowFile = process.env.GH_AW_WORKFLOW_FILE;
2731

@@ -57,7 +61,7 @@ async function main() {
5761
// Parse owner, repo, and optional ref from GITHUB_WORKFLOW_REF as a single unit so that
5862
// repo and ref are always consistent with each other. The @ref segment may be absent (e.g.
5963
// when the env var was set without a ref suffix), so treat it as optional.
60-
const workflowRefMatch = workflowEnvRef.match(/^([^/]+)\/([^/]+)\/.+?(?:@(.+))?$/);
64+
const workflowRefMatch = workflowEnvRef.match(GITHUB_REPO_PATH_RE);
6165

6266
// Use the workflow source repo if parseable, otherwise fall back to context.repo
6367
let owner = workflowRefMatch ? workflowRefMatch[1] : context.repo.owner;
@@ -123,7 +127,7 @@ async function main() {
123127
});
124128

125129
if (matchingEntry) {
126-
const pathMatch = matchingEntry.path.match(/^([^/]+)\/([^/]+)\/.+?(?:@(.+))?$/);
130+
const pathMatch = matchingEntry.path.match(GITHUB_REPO_PATH_RE);
127131
if (pathMatch) {
128132
owner = pathMatch[1];
129133
repo = pathMatch[2];

0 commit comments

Comments
 (0)