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

cleanup: make PullRequest, ReleasePullRequest, Version fields readonly #1150

Merged
merged 2 commits into from
Dec 21, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/plugins/cargo-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {ReleasePullRequest} from '../release-pull-request';
import {PullRequestTitle} from '../util/pull-request-title';
import {PullRequestBody} from '../util/pull-request-body';
import {BranchName} from '../util/branch-name';
import {PatchVersionUpdate} from '../versioning-strategy';

interface CrateInfo {
/**
Expand Down Expand Up @@ -160,8 +161,7 @@ export class CargoWorkspace extends WorkspacePlugin<CrateInfo> {

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

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 @@ -35,6 +35,7 @@ import {
DependencyNode,
WorkspacePluginOptions,
} from './workspace';
import {PatchVersionUpdate} from '../versioning-strategy';

class Package extends LernaPackage {
constructor(
Expand Down Expand Up @@ -143,8 +144,7 @@ export class NodeWorkspace extends WorkspacePlugin<Package> {

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

protected updateCandidate(
Expand Down
16 changes: 8 additions & 8 deletions src/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
// limitations under the License.

export interface PullRequest {
headBranchName: string;
baseBranchName: string;
number: number;
title: string;
body: string;
labels: string[];
files: string[];
sha?: string;
readonly headBranchName: string;
readonly baseBranchName: string;
readonly number: number;
readonly title: string;
readonly body: string;
readonly labels: string[];
readonly files: string[];
readonly sha?: string;
}
12 changes: 6 additions & 6 deletions src/release-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import {PullRequestBody} from './util/pull-request-body';
import {PullRequestTitle} from './util/pull-request-title';

export interface ReleasePullRequest {
title: PullRequestTitle;
body: PullRequestBody;
readonly title: PullRequestTitle;
readonly body: PullRequestBody;
readonly labels: string[];
readonly headRefName: string;
readonly version?: Version;
readonly draft: boolean;
updates: Update[];
labels: string[];
headRefName: string;
version?: Version;
draft: boolean;
}
10 changes: 5 additions & 5 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ const VERSION_REGEX =
* This data class is used to represent a SemVer version.
*/
export class Version {
major: number;
minor: number;
patch: number;
preRelease?: string;
build?: string;
readonly major: number;
readonly minor: number;
readonly patch: number;
readonly preRelease?: string;
readonly build?: string;

constructor(
major: number,
Expand Down
11 changes: 7 additions & 4 deletions src/versioning-strategies/java-add-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ class AddSnapshotVersionUpdate implements VersionUpdater {
}
bump(version: Version): Version {
const nextPatch = this.strategy.bump(version, [fakeCommit]);
nextPatch.preRelease = nextPatch.preRelease
? `${nextPatch.preRelease}-SNAPSHOT`
: 'SNAPSHOT';
return nextPatch;
return new Version(
nextPatch.major,
nextPatch.minor,
nextPatch.patch,
nextPatch.preRelease ? `${nextPatch.preRelease}-SNAPSHOT` : 'SNAPSHOT',
nextPatch.build
);
}
}

Expand Down