Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Fix OrgsUpdater identifying new releases as old #516

Merged
merged 3 commits into from
May 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class GenerateChangelog extends SfdxCommand {
description: messages.getMessage('repoUrlFlagDescription')
}),
branchname: flags.string({
required: true,
required: false,
char: "b",
description: messages.getMessage('branchNameFlagDescription'),
deprecated: { messageOverride: "--branchname has been deprecated" },
Expand Down
44 changes: 18 additions & 26 deletions packages/sfpowerscripts-cli/src/impl/changelog/OrgsUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,24 @@ import { ReleaseChangelog, Release, ReleaseId } from "./ReleaseChangelogInterfac
import lodash = require("lodash");

export default class OrgsUpdater {
private isNewRelease: boolean;
private releaseWithMatchingHashId: ReleaseId;
private latestReleaseId: ReleaseId;
private idOfReleaseWithMatchingHashId: ReleaseId;

constructor(
private releaseChangelog: ReleaseChangelog,
private latestRelease: Release,
private org: string
private org: string,
private releaseWithMatchingHashId: Release
) {
this.isNewRelease = true;
if (releaseChangelog.releases.length > 0) {
for (let release of releaseChangelog.releases) {
if (release.hashId === latestRelease.hashId) {
console.log(`Found previous release with identical hash Id ${release.hashId}`);
this.isNewRelease = false;
this.releaseWithMatchingHashId = this.convertReleaseToId(release);
break;
}
}
}

this.latestReleaseId = this.convertReleaseToId(this.latestRelease);

if (this.releaseWithMatchingHashId) {
this.idOfReleaseWithMatchingHashId = this.convertReleaseToId(this.releaseWithMatchingHashId);
}
}

update(): void {
if (this.isNewRelease) {
if (!this.idOfReleaseWithMatchingHashId) {
if (this.releaseChangelog.orgs) {
let org = this.releaseChangelog.orgs.find((org) => org.name === this.org);

Expand All @@ -48,36 +40,36 @@ export default class OrgsUpdater {
let org = this.releaseChangelog.orgs.find((org) => org.name === this.org);

if (org) {
let indexOfReleaseToOrg = org.releases.findIndex((orgRelease) => orgRelease.hashId === this.releaseWithMatchingHashId.hashId);
if (org.latestRelease.hashId !== this.releaseWithMatchingHashId.hashId) {
let indexOfReleaseToOrg = org.releases.findIndex((orgRelease) => orgRelease.hashId === this.idOfReleaseWithMatchingHashId.hashId);
if (org.latestRelease.hashId !== this.idOfReleaseWithMatchingHashId.hashId) {
if ( indexOfReleaseToOrg >= 0 ) {
// Update release names in releases to org
org.releases[indexOfReleaseToOrg] = this.releaseWithMatchingHashId;
org.releases[indexOfReleaseToOrg] = this.idOfReleaseWithMatchingHashId;
} else {
// Add releaseId in releases to org
org.releases.push(this.releaseWithMatchingHashId);
org.releases.push(this.idOfReleaseWithMatchingHashId);
}

// Update latest release
org.latestRelease = this.releaseWithMatchingHashId;
org.latestRelease = this.idOfReleaseWithMatchingHashId;
org.retryCount = 0;
} else {
if (lodash.isEqual(org.releases[indexOfReleaseToOrg], this.releaseWithMatchingHashId)) {
if (lodash.isEqual(org.releases[indexOfReleaseToOrg], this.idOfReleaseWithMatchingHashId)) {
org.retryCount++;
} else {
org.retryCount = 0;
}

// Update releases names in releases to org & latestRelease
org.releases[indexOfReleaseToOrg] = this.releaseWithMatchingHashId;
org.latestRelease = this.releaseWithMatchingHashId;
org.releases[indexOfReleaseToOrg] = this.idOfReleaseWithMatchingHashId;
org.latestRelease = this.idOfReleaseWithMatchingHashId;
}

console.log(`Updating ${this.org} org with`, org.latestRelease.names[org.latestRelease.names.length - 1] + "-" + org.latestRelease.buildNumber + `(${org.retryCount})`);
} else {
// new org
this.releaseChangelog.orgs.push({ name: this.org, releases: [this.releaseWithMatchingHashId], latestRelease: this.releaseWithMatchingHashId, retryCount: 0 });
console.log(`Updating ${this.org} org with`, `${this.releaseWithMatchingHashId.names[this.releaseWithMatchingHashId.names.length - 1]}-${this.releaseWithMatchingHashId.buildNumber}(0)`);
this.releaseChangelog.orgs.push({ name: this.org, releases: [this.idOfReleaseWithMatchingHashId], latestRelease: this.idOfReleaseWithMatchingHashId, retryCount: 0 });
console.log(`Updating ${this.org} org with`, `${this.idOfReleaseWithMatchingHashId.names[this.idOfReleaseWithMatchingHashId.names.length - 1]}-${this.idOfReleaseWithMatchingHashId.buildNumber}(0)`);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export default class ReleaseChangelogUpdater {

this.releaseChangelog.releases.push(latestRelease);
} else {

if (!this.containsLatestReleaseName(releaseWithMatchingHashId.names, latestRelease.names[0])) {
// append latestReleaseName
releaseWithMatchingHashId.names.push(latestRelease.names[0]);
Expand All @@ -73,7 +72,8 @@ export default class ReleaseChangelogUpdater {
new OrgsUpdater(
this.releaseChangelog,
latestRelease,
this.org
this.org,
releaseWithMatchingHashId
).update();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe("Given an OrgsUpdater", () => {
new OrgsUpdater(
releaseChangelog,
newRelease,
"DEV"
"DEV",
null
).update()

let newReleaseId = convertReleaseToId(newRelease);
Expand All @@ -46,7 +47,8 @@ describe("Given an OrgsUpdater", () => {
new OrgsUpdater(
releaseChangelog,
newRelease,
"DEV"
"DEV",
null
).update();

let newReleaseId = convertReleaseToId(newRelease);
Expand Down Expand Up @@ -92,7 +94,8 @@ describe("Given an OrgsUpdater", () => {
new OrgsUpdater(
releaseChangelog,
oldRelease1,
"SIT"
"SIT",
releaseChangelog.releases[1]
).update();

expect(releaseChangelog).toEqual(expectedResult);
Expand All @@ -116,7 +119,8 @@ describe("Given an OrgsUpdater", () => {
new OrgsUpdater(
releaseChangelog,
oldRelease2,
"DEV"
"DEV",
releaseChangelog.releases[0]
).update();

expect(releaseChangelog).toEqual(expectedResult);
Expand Down