Skip to content

Commit

Permalink
fix: make PullRequest, ReleasePullRequest, Version fields readonly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 authored Dec 21, 2021
1 parent b30a91b commit 9659c1c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
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

0 comments on commit 9659c1c

Please sign in to comment.