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

Fix issue with similarly named packages matching the wrong package in the generated changelog. #24

Merged
merged 3 commits into from
May 22, 2024
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
25 changes: 25 additions & 0 deletions src/changelog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ describe("Changelog", () => {
}
});

describe("packageFromPath with similarly named packages", () => {
const MockedChangelog = require("./changelog").default;

const TESTS = [
["", ""],
["/ember-fastboot/package.json", "ember-fastboot"],
["/ember-fastboot-2-fast-2-furious/package.json", "ember-fastboot-2-fast-2-furious"],
["/ember-fastboot-tokyo-drift/package.json", "ember-fastboot-tokyo-drift"],
];

for (let [input, expected] of TESTS) {
it(`${input} -> ${expected}`, () => {
const changelog = new MockedChangelog({
rootPath: "/",
packages: [
{ name: "ember-fastboot", path: "/ember-fastboot" },
{ name: "ember-fastboot-2-fast-2-furious", path: "/ember-fastboot-2-fast-2-furious" },
{ name: "ember-fastboot-tokyo-drift", path: "/ember-fastboot-tokyo-drift" },
],
});
expect(changelog.packageFromPath(input)).toEqual(expected);
});
}
});

describe("getCommitInfos", () => {
beforeEach(() => {
require("./fetch").__resetMockResponses();
Expand Down
15 changes: 12 additions & 3 deletions src/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const pMap = require("p-map");
const { resolve } = require("path");
const { resolve, sep } = require("path");

import progressBar from "./progress-bar";
import { Configuration } from "./configuration";
Expand Down Expand Up @@ -73,7 +73,9 @@ export default class Changelog {
}

private async getListOfUniquePackages(sha: string): Promise<string[]> {
return (await Git.changedPaths(sha))
let changedPaths = await Git.changedPaths(sha);

return changedPaths
.map(path => this.packageFromPath(path))
.filter(Boolean)
.filter(onlyUnique);
Expand All @@ -84,7 +86,14 @@ export default class Changelog {
// use the discovered packages
const absolutePath = resolve(this.config.rootPath, path);

const foundPackage = this.config.packages.find(p => absolutePath.startsWith(p.path));
// Sometimes multiple packages may exist with the same prefix:
// ember-fastboot
// ember-fastboot-2-fast-2-furious
const foundPackage = this.config.packages.find(p => {
let withSlash = p.path.endsWith(sep) ? p.path : `${p.path}${sep}`;

return absolutePath.startsWith(withSlash);
});

if (foundPackage) {
return foundPackage.name;
Expand Down
Loading