Skip to content

Commit

Permalink
dont omit unreleased commits
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Apr 7, 2020
1 parent 249a2cb commit 2c4d2b8
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
43 changes: 43 additions & 0 deletions packages/core/src/__tests__/__snapshots__/release.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,49 @@ Array [
]
`;

exports[`Release getCommits should not omit commits in next branch 1`] = `
Array [
Object {
"authorEmail": "adam@dierkens.com",
"authorName": "Adam Dierkens",
"authors": Array [
Object {
"email": "adam@dierkens.com",
"name": "Adam Dierkens",
},
],
"files": Array [],
"hash": "foo",
"labels": Array [],
"pullRequest": Object {
"number": 124,
},
"subject": "Feature",
},
Object {
"authorEmail": "adam@dierkens.com",
"authorName": "Adam Dierkens",
"authors": Array [
Object {
"email": "adam@dierkens.com",
"hash": "1a2b",
"name": "Adam Dierkens",
},
],
"files": Array [],
"hash": "1a2b",
"labels": Array [
"skip-release",
"minor",
],
"pullRequest": Object {
"number": 123,
},
"subject": "I wasn't released previously",
},
]
`;

exports[`Release getCommits should not resolve authors with no PR commits 1`] = `
Array [
Object {
Expand Down
34 changes: 34 additions & 0 deletions packages/core/src/__tests__/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,40 @@ describe("Release", () => {
expect(await gh.getCommits("12345", "1234")).toMatchSnapshot();
});

test("should not omit commits in next branch", async () => {
const gh = new Release(git);

jest.spyOn(console, "log").mockImplementationOnce(() => {});
getLatestReleaseInfo.mockReturnValueOnce({
published_at: "2019-01-16",
});
searchRepo.mockReturnValueOnce({ items: [{ number: 123 }] });
getPullRequest.mockReturnValueOnce({
data: {
number: 123,
merge_commit_sha: "1a2b",
labels: [{ name: "skip-release" }, { name: "minor" }],
},
});
getGitLog.mockReturnValueOnce(
await logParse.normalizeCommits([
makeCommitFromMsg("Feature (#124)"),
makeCommitFromMsg("I wasn't released previously", {
hash: "1a2b",
}),
])
);
exec.mockReturnValueOnce("0");
exec.mockImplementationOnce(() => {
throw new Error();
});
exec.mockImplementationOnce(() => {
throw new Error();
});

expect(await gh.getCommits("12345", "1234")).toMatchSnapshot();
});

test("should include PR opener in authors (in case of external rebase)", async () => {
const gh = new Release(git);

Expand Down
16 changes: 13 additions & 3 deletions packages/core/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,19 @@ export default class Release {
});
released = false;
} catch (error) {
// --is-ancestor returned false so the commit is **before** "from"
// so do not release this commit again
released = true;
try {
// --is-ancestor returned false so the commit might be **before** "from"
// so test if it is and do not release this commit again
// This determines: Is this commit an ancestor of this commit?
// ↓ ↓
execSync(`git merge-base --is-ancestor ${commit.hash} ${from}`, {
encoding: "utf8",
});
released = true;
} catch (error) {
// neither commit is a parent of the other so include it
released = false;
}
}

if (released) {
Expand Down

0 comments on commit 2c4d2b8

Please sign in to comment.