Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resources: use named groups in RegExp #2840

Merged
merged 1 commit into from Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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