Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bootstrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Bootstrapper {
this.targetBranch = targetBranch;
this.manifestFile = manifestFile;
this.configFile = configFile;
this.initialVersion = Version.parse(initialVersionString);
this.initialVersion = Version.parseOne(initialVersionString);
}

async bootstrap(path: string, config: ReleaserConfig): Promise<PullRequest> {
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,7 @@ async function parseReleasedVersions(
);
const releasedVersions: ReleasedVersions = {};
for (const path in manifestJson) {
releasedVersions[path] = Version.parse(manifestJson[path]);
releasedVersions[path] = Version.parseOne(manifestJson[path]);
}
return releasedVersions;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/cargo-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {
}

protected bumpVersion(pkg: CrateInfo): Version {
const version = Version.parse(pkg.version);
const version = Version.parseOne(pkg.version);
return new PatchVersionUpdate().bump(version);
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/maven-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class MavenWorkspace extends WorkspacePlugin<MavenArtifact> {
);
updatedVersions.set(
updatedArtifact.name,
Version.parse(updatedArtifact.version)
Version.parseOne(updatedArtifact.version)
);
}
} else {
Expand Down Expand Up @@ -334,7 +334,7 @@ export class MavenWorkspace extends WorkspacePlugin<MavenArtifact> {

protected bumpVersion(artifact: MavenArtifact): Version {
const strategy = new JavaSnapshot(new AlwaysBumpPatch());
return strategy.bump(Version.parse(artifact.version), [FAKE_COMMIT]);
return strategy.bump(Version.parseOne(artifact.version), [FAKE_COMMIT]);
}

protected updateCandidate(
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/node-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class NodeWorkspace extends WorkspacePlugin<Package> {
}

protected bumpVersion(pkg: Package): Version {
const version = Version.parse(pkg.version);
const version = Version.parseOne(pkg.version);
return new PatchVersionUpdate().bump(version);
}

Expand Down Expand Up @@ -267,7 +267,7 @@ export class NodeWorkspace extends WorkspacePlugin<Package> {
updatedVersions
);
const packageJson = updatedPackage.toJSON() as PackageJson;
const version = Version.parse(packageJson.version);
const version = Version.parseOne(packageJson.version);
const pullRequest: ReleasePullRequest = {
title: PullRequestTitle.ofTargetBranch(
this.targetBranch,
Expand Down
8 changes: 4 additions & 4 deletions src/strategies/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ export abstract class BaseStrategy implements Strategy {
this.logger.warn(
`Setting version for ${this.path} from release-as configuration`
);
newVersion = Version.parse(this.releaseAs);
newVersion = Version.parseOne(this.releaseAs);
} else if (releaseAsNote) {
newVersion = Version.parse(releaseAsNote.text);
newVersion = Version.parseOne(releaseAsNote.text);
} else if (latestRelease) {
newVersion = await this.versioningStrategy.bump(
latestRelease.tag.version,
Expand Down Expand Up @@ -749,10 +749,10 @@ If you instead want to use the version number \`${newVersion}\` generated from c
*/
protected initialReleaseVersion(): Version {
if (this.initialVersion) {
return Version.parse(this.initialVersion);
return Version.parseOne(this.initialVersion);
}

return Version.parse('0.0.1');
return Version.parseOne('0.0.1');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/expo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Expo extends Node {
async getExpoSDKVersion(): Promise<Version> {
const pkgJsonContents = await this.getPkgJsonContents();
const pkg = JSON.parse(pkgJsonContents.parsedContent);
return Version.parse(
return Version.parseOne(
pkg.dependencies?.expo ||
pkg.devDependencies?.expo ||
pkg.peerDependencies?.expo ||
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/java-yoshi-mono-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export class JavaYoshiMonoRepo extends Java {
continue;
}
if (isPromotion && isStableArtifact(versionKey)) {
versionsMap.set(versionKey, Version.parse('1.0.0'));
versionsMap.set(versionKey, Version.parseOne('1.0.0'));
} else {
const newVersion = await this.versioningStrategy.bump(
version,
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/java-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class JavaYoshi extends Java {
continue;
}
if (isPromotion && isStableArtifact(versionKey)) {
versionsMap.set(versionKey, Version.parse('1.0.0'));
versionsMap.set(versionKey, Version.parseOne('1.0.0'));
} else {
const newVersion = await this.versioningStrategy.bump(
version,
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/php-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class PHPYoshi extends BaseStrategy {
this.addPath(`${directory}/VERSION`),
this.changesBranch
);
const version = Version.parse(contents.parsedContent);
const version = Version.parseOne(contents.parsedContent);
const composer = await this.github.getFileJson<ComposerJson>(
this.addPath(`${directory}/composer.json`),
this.changesBranch
Expand Down
2 changes: 1 addition & 1 deletion src/updaters/java/versions-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class VersionsManifest extends JavaUpdate {
content.split(/\r?\n/).forEach(line => {
const match = line.match(/^([\w\-_]+):([^:]+):([^:]+)/);
if (match) {
versions.set(match[1], Version.parse(match[2]));
versions.set(match[1], Version.parseOne(match[2]));
}
});
return versions;
Expand Down
2 changes: 1 addition & 1 deletion src/util/branch-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class AutoreleaseBranchName extends BranchName {
const match = branchName.match(AUTORELEASE_PATTERN);
if (match?.groups) {
this.component = match.groups['component'];
this.version = Version.parse(match.groups['version']);
this.version = Version.parseOne(match.groups['version']);
}
}
toString(): string {
Expand Down
6 changes: 3 additions & 3 deletions src/util/pull-request-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function extractMultipleReleases(notes: string, logger: Logger): ReleaseData[] {
const notes = detail.textContent.trim();
data.push({
component: match.groups.component,
version: Version.parse(match.groups.version),
version: Version.parseOne(match.groups.version),
notes,
});
} else {
Expand All @@ -147,7 +147,7 @@ function extractMultipleReleases(notes: string, logger: Logger): ReleaseData[] {
detail.removeChild(summaryNode);
const notes = detail.textContent.trim();
data.push({
version: Version.parse(componentlessMatch.groups.version),
version: Version.parseOne(componentlessMatch.groups.version),
notes,
});
}
Expand All @@ -165,7 +165,7 @@ function extractSingleRelease(body: string, logger: Logger): ReleaseData[] {
}
return [
{
version: Version.parse(versionString),
version: Version.parseOne(versionString),
notes: body,
},
];
Expand Down
128 changes: 90 additions & 38 deletions src/util/pull-request-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,27 @@ import {Version} from '../version';
// at the script level are undefined, they are only defined inside function
// or instance methods/properties.

const DEFAULT_PR_TITLE_PATTERN =
'chore${scope}: release${component} ${version}';
export function generateMatchPattern(pullRequestTitlePattern?: string): RegExp {
const DEFAULT_PR_TITLE_PATTERN = 'release: ${componentsSegment}';

/**
* Default pattern for a component in the "components segment" of the release PR title
*/
const DEFAULT_PR_TITLE_PATTERN_SINGLE_COMPONENT_SEGMENT =
'${component} ${version}';

/**
* Default separator for components in the "component segment" of the release PR.
*/
const DEFAULT_PR_TITLE_PATTERN_COMPONENT_SEPARATOR = ',';

export function generateMatchPatternPRTitleComponentsSegment(
componentsSegmentPattern?: string
): RegExp {
return new RegExp(
`^${(pullRequestTitlePattern || DEFAULT_PR_TITLE_PATTERN)
`^${(
componentsSegmentPattern ||
DEFAULT_PR_TITLE_PATTERN_SINGLE_COMPONENT_SEGMENT
)
.replace('[', '\\[') // TODO: handle all regex escaping
.replace(']', '\\]')
.replace('(', '\\(')
Expand All @@ -39,24 +55,52 @@ export function generateMatchPattern(pullRequestTitlePattern?: string): RegExp {
);
}

export function generateMatchPatternPRTitle(
pullRequestTitlePattern?: string,
componentsSegmentPattern?: string,
componentsSegmentSeparator?: string
): RegExp {
const matchPatternComponentsSegment =
generateMatchPatternPRTitleComponentsSegment(
componentsSegmentPattern ||
DEFAULT_PR_TITLE_PATTERN_SINGLE_COMPONENT_SEGMENT
);
return new RegExp(
`^${(pullRequestTitlePattern || DEFAULT_PR_TITLE_PATTERN)
.replace('[', '\\[') // TODO: handle all regex escaping
.replace(']', '\\]')
.replace('(', '\\(')
.replace(')', '\\)')
.replace(
'${scope}',
'(\\((?<changesBranch>[\\w-./]+ => )?(?<branch>[\\w-./]+)\\))?'
)
// FIXME(sam): review + fix regexp for components segment, it should handle
// the separator.
.replace('${componentsSegment}', ` ${matchPatternComponentsSegment}`)
.replace('${changesBranch}', '(?<changesBranch>?[\\w-./]+)?')
.replace('${branch}', '(?<branch>[\\w-./]+)?')}$`
);
}

export class PullRequestTitle {
component?: string;
components?: string[];
changesBranch?: string;
targetBranch?: string;
version?: Version;
versions?: Version[];
pullRequestTitlePattern: string;
matchPattern: RegExp;

private constructor(opts: {
version?: Version;
component?: string;
versions?: Version[];
components?: string[];
targetBranch?: string;
changesBranch?: string;
pullRequestTitlePattern?: string;
logger?: Logger;
}) {
this.version = opts.version;
this.component = opts.component;
this.versions = opts.versions;
this.components = opts.components;
this.targetBranch = opts.targetBranch;
this.changesBranch = opts.changesBranch || this.targetBranch;
this.pullRequestTitlePattern =
Expand All @@ -73,10 +117,10 @@ export class PullRequestTitle {
const match = title.match(matchPattern);
if (match?.groups) {
return new PullRequestTitle({
version: match.groups['version']
? Version.parse(match.groups['version'])
versions: match.groups['versions']
? Version.parseMultiple(match.groups['versions'])
: undefined,
component: match.groups['component'],
components: match.groups['components'],
changesBranch: match.groups['changesBranch'],
targetBranch: match.groups['branch'],
pullRequestTitlePattern,
Expand All @@ -87,42 +131,46 @@ export class PullRequestTitle {
}

static ofComponentVersion(
component: string,
version: Version,
components: string[],
versions: Version[],
pullRequestTitlePattern?: string
): PullRequestTitle {
return new PullRequestTitle({version, component, pullRequestTitlePattern});
return new PullRequestTitle({
versions,
components,
pullRequestTitlePattern,
});
}
static ofVersion(
static ofSingleVersion(
version: Version,
pullRequestTitlePattern?: string
): PullRequestTitle {
return new PullRequestTitle({version, pullRequestTitlePattern});
return new PullRequestTitle({versions: [version], pullRequestTitlePattern});
}
static ofTargetBranchVersion(
targetBranch: string,
changesBranch: string,
version: Version,
versions: Version[],
pullRequestTitlePattern?: string
): PullRequestTitle {
return new PullRequestTitle({
version,
versions,
targetBranch,
changesBranch,
pullRequestTitlePattern,
});
}

static ofComponentTargetBranchVersion(
component?: string,
components?: string[],
targetBranch?: string,
changesBranch?: string,
version?: Version,
versions?: Version[],
pullRequestTitlePattern?: string
): PullRequestTitle {
return new PullRequestTitle({
version,
component,
versions,
components,
targetBranch,
changesBranch,
pullRequestTitlePattern,
Expand All @@ -144,14 +192,14 @@ export class PullRequestTitle {
getTargetBranch(): string | undefined {
return this.targetBranch;
}
getChangesBRanch(): string | undefined {
getChangesBranch(): string | undefined {
return this.changesBranch;
}
getComponent(): string | undefined {
return this.component;
getComponents(): string[] | undefined {
return this.components;
}
getVersion(): Version | undefined {
return this.version;
getVersions(): Version[] | undefined {
return this.versions;
}

toString(): string {
Expand All @@ -160,14 +208,18 @@ export class PullRequestTitle {
? `(${this.changesBranch} => ${this.targetBranch})`
: `(${this.targetBranch})`
: '';
const component = this.component ? ` ${this.component}` : '';
const version = this.version ?? '';
return this.pullRequestTitlePattern
.replace('${scope}', scope)
.replace('${component}', component)
.replace('${version}', version.toString())
.replace('${changesBranch}', this.changesBranch || '')
.replace('${branch}', this.targetBranch || '')
.trim();
const components = this.components ? ` ${this.components}` : '';
const versions = this.versions ?? '';

// FIXME(sam): replace template values using indices for versions and components
// Should look like: `releases: ${components[0]} ${versions[0]}, ${components[1]} ${versions[1]}`

// return this.pullRequestTitlePattern
// .replace('${scope}', scope)
// .replace('${component}', component)
// .replace('${version}', version.toString())
// .replace('${changesBranch}', this.changesBranch || '')
// .replace('${branch}', this.targetBranch || '')
// .trim();
}
}
2 changes: 1 addition & 1 deletion src/util/tag-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class TagName {
const match = tagName.match(TAG_PATTERN);
if (match?.groups) {
return new TagName(
Version.parse(match.groups.version),
Version.parseOne(match.groups.version),
match.groups.component,
match.groups.separator,
!!match.groups.v
Expand Down
Loading