Skip to content

Commit

Permalink
resources: use named groups in RegExp (graphql#2840)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored and yaacovCR committed Apr 11, 2021
1 parent 19dcea7 commit 2096e2b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions resources/build-npm.js
Expand Up @@ -59,12 +59,12 @@ function buildPackageJSON() {
delete packageJSON.engines_on_npm;

const { version } = packageJSON;
const versionMatch = /^\d+\.\d+\.\d+-?(.*)?$/.exec(version);
const versionMatch = /^\d+\.\d+\.\d+-?(?<preReleaseTag>.*)?$/.exec(version);
if (!versionMatch) {
throw new Error('Version does not match semver spec: ' + version);
}

const [, preReleaseTag] = versionMatch;
const { preReleaseTag } = versionMatch.groups;

if (preReleaseTag != null) {
const [tag] = preReleaseTag.split('.');
Expand Down
8 changes: 4 additions & 4 deletions resources/gen-changelog.js
Expand Up @@ -47,14 +47,14 @@ if (!packageJSON.repository || typeof packageJSON.repository.url !== 'string') {
process.exit(1);
}

const repoURLMatch = /https:\/\/github.com\/([^/]+)\/([^/]+).git/.exec(
const repoURLMatch = /https:\/\/github.com\/(?<githubOrg>[^/]+)\/(?<githubRepo>[^/]+).git/.exec(
packageJSON.repository.url,
);
if (repoURLMatch == null) {
console.error('Cannot extract organization and repo name from repo URL!');
process.exit(1);
}
const [, githubOrg, githubRepo] = repoURLMatch;
const { githubOrg, githubRepo } = repoURLMatch.groups;

getChangeLog()
.then((changelog) => process.stdout.write(changelog))
Expand Down Expand Up @@ -275,9 +275,9 @@ function commitsInfoToPRs(commits) {
(pr) => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`,
);
if (associatedPRs.length === 0) {
const match = / \(#([0-9]+)\)$/m.exec(commit.message);
const match = / \(#(?<prNumber>[0-9]+)\)$/m.exec(commit.message);
if (match) {
prs[parseInt(match[1], 10)] = true;
prs[parseInt(match.groups.prNumber, 10)] = true;
continue;
}
throw new Error(
Expand Down

0 comments on commit 2096e2b

Please sign in to comment.