Skip to content

Commit

Permalink
fix(changelog): remove irrelevant versions and details (#939)
Browse files Browse the repository at this point in the history
excludes prerelease versions
removes lines marked as hidden by starting with .

fixes #925
  • Loading branch information
sleidig committed Aug 9, 2021
1 parent 56bea78 commit 1f925ff
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/app/core/latest-changes/latest-changes.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ import { LatestChangesService } from "./latest-changes.service";
* Displaying app version and changelog information to the user
* through components that can be used in other templates
* as well as automatic popups on updates (see {@link UpdateManagerService}, {@link LatestChangesService}).
*
* Changelogs are dynamically loaded from GitHub Releases through the GitHub API.
* pre-releases are excluded and individual lines in the body can be hidden by starting
* text (after markdown characters) with a ".".
*/
@NgModule({
imports: [
Expand Down
59 changes: 59 additions & 0 deletions src/app/core/latest-changes/latest-changes.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ describe("LatestChangesService", () => {
body: "A",
published_at: "2018-01-01",
},
{
name: "prerelease 1",
tag_name: "1.0-rc.1",
prerelease: true,
body: "A",
published_at: "2018-01-01",
},
];

beforeEach(() => {
Expand Down Expand Up @@ -122,4 +129,56 @@ describe("LatestChangesService", () => {
}
);
});

it("should not include prereleases", (done) => {
spyOn(http, "get").and.returnValue(of(testReleases));

service.getChangelogsBeforeVersion("1.1", 10).subscribe((result) => {
expect(result).toEqual([testReleases[2]]);
expect(result[0]["prerelease"]).toBeFalsy();
expect(result).not.toContain(testReleases[3]);
done();
});
});

it("should remove lines from release changelog body that are explicitly hidden by starting with a '.'", (done) => {
const testRelease = {
name: "test with notes",
tag_name: "3.0",
body: `changelog
### Bugs
* relevant fix
* .hidden fix
### .Hidden
`,
};

spyOn(http, "get").and.returnValue(of([testRelease]));

service.getChangelogsBetweenVersions("3.0", "2.9").subscribe((result) => {
expect(result[0].tag_name).toBe(testRelease.tag_name);
expect(result[0].body).toBe(`changelog
# Bugs
* relevant fix
`);
done();
});
});

it("should remove irrelevant details from release changelog body", (done) => {
const testRelease = {
name: "test with notes",
tag_name: "3.0",
body:
"* fix ([e03dcca](https://github.com/Aam-Digital/ndb-core/commit/e03dcca7d89e584b8f08cc7fe30621c1ad428dba))",
};

spyOn(http, "get").and.returnValue(of([testRelease]));

service.getChangelogsBetweenVersions("3.0", "2.9").subscribe((result) => {
expect(result[0].tag_name).toBe(testRelease.tag_name);
expect(result[0].body).toBe("* fix");
done();
});
});
});
33 changes: 24 additions & 9 deletions src/app/core/latest-changes/latest-changes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class LatestChangesService {
LatestChangesService.GITHUB_API + environment.repositoryId + "/releases"
)
.pipe(
map(excludePrereleases),
map(releaseFilter),
map((relevantReleases) =>
relevantReleases.map((r) => this.parseGithubApiRelease(r))
Expand All @@ -130,23 +131,37 @@ export class LatestChangesService {
return throwError("Could not load latest changes.");
})
);

function excludePrereleases(releases: any[]): Changelog[] {
return releases.filter(
(release) => !release.prerelease && !release.draft
);
}
}

private parseGithubApiRelease(githubResponse: any): Changelog {
const releaseNotesWithoutHeading = githubResponse.body.replace(
/#{1,2}[^###]*/,
""
);
const releaseNotesWithoutCommitRefs = releaseNotesWithoutHeading.replace(
/ \(\[\w{7}\]\([^\)]*\)\)/g,
""
);
const cleanedReleaseNotes = githubResponse.body
.replace(
// remove heading
/#{1,2}[^###]*/,
""
)
.replace(
// remove commit refs
/ \(\[\w{7}\]\([^\)]*\)\)/g,
""
)
.replace(
// remove lines starting with "." after markdown characters
/^(\*|\#)* *\.(.*)(\n|\r\n)/gm,
""
);

return {
tag_name: githubResponse.tag_name,
name: githubResponse.name,
published_at: githubResponse.published_at,
body: releaseNotesWithoutCommitRefs,
body: cleanedReleaseNotes,
};
}
}

0 comments on commit 1f925ff

Please sign in to comment.