1
0
mirror of synced 2025-12-21 02:46:50 -05:00
Files
docs/script/deployment/parse-pr-url.js
Kevin Heis 8a56437c93 Pretty format (#20352)
* Update prettier flow to include JS

* Run prettier

* ...run prettier
2021-07-14 14:35:01 -07:00

22 lines
559 B
JavaScript

#!/usr/bin/env node
const USERNAME_FORMAT = '([A-Za-z0-9-]+)'
const REPO_NAME_FORMAT = '([A-Za-z0-9._-]+)'
const PR_NUMBER_FORMAT = '(\\d+)'
const ALLOWED_PR_URL_FORMAT = new RegExp(
'^' +
'[\'"]?' +
`https://github\\.com/${USERNAME_FORMAT}/${REPO_NAME_FORMAT}/pull/${PR_NUMBER_FORMAT}` +
'[\'"]?' +
'$'
)
export default function parsePullRequestUrl(prUrl) {
const [, /* fullMatch */ owner, repo, pr] = (prUrl || '').match(ALLOWED_PR_URL_FORMAT) || []
return {
owner,
repo,
pullNumber: parseInt(pr, 10) || undefined,
}
}