Skip to content

Commit

Permalink
fix: wrong context.commits when have multiple releases commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iporsut authored and antongolub committed Feb 1, 2021
1 parent 5ce8eca commit f82f125
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/createInlinePluginCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ function createInlinePluginCreator(packages, multiContext, synchronizer, flags)
updateManifestDeps(pkg);
pkg._depsUpdated = true;

// Set context.commits so analyzeCommits does correct analysis.
// We need to redo this because context is a different instance each time.
context.commits = commits;

const res = await plugins.prepare(context);
pkg._prepared = true;

Expand Down
17 changes: 17 additions & 0 deletions test/helpers/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,22 @@ function gitGetConfig(cwd, name) {
execa.sync("git", ["config", name], { cwd }).stdout;
}

/**
* Get the commit message log of given commit SHA or branch name.
*
* @param {string} cwd The CWD of the Git repository.
* @param {integer} number Limit the number of commits to output.
* @param {string} hash The commit SHA or branch name.
* @return {Promise<string>} Promise that resolve to commit log message.
*/
function gitGetLog(cwd, number, hash) {
check(cwd, "cwd: absolute");
check(number, "number: integer");
check(hash, "hash: string+");

// Run command.
return execa.sync("git", ["log", `-${number}`, hash], { cwd }).stdout;
}
// Exports.
module.exports = {
gitInit,
Expand All @@ -323,4 +339,5 @@ module.exports = {
gitGetTagHash,
gitConfig,
gitGetConfig,
gitGetLog,
};
51 changes: 51 additions & 0 deletions test/lib/multiSemanticRelease.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
gitPush,
gitTag,
gitGetTags,
gitGetLog,
} = require("../helpers/git");

// Clear mocks before tests.
Expand Down Expand Up @@ -925,6 +926,56 @@ describe("multiSemanticRelease()", () => {
expect(plugin.success).toBeCalledTimes(1);
expect(plugin.fail).not.toBeCalled();
});
test("Bot commit release note should filetered", async () => {
// Create Git repo.
const cwd = gitInit();
// Initial commit.
copyDirectory(`test/fixtures/yarnWorkspaces/`, cwd);
const sha1 = gitCommitAll(cwd, "feat: Initial release");
gitTag(cwd, "[email protected]");
gitTag(cwd, "[email protected]");
gitTag(cwd, "[email protected]");
gitTag(cwd, "[email protected]");
// Second commit.
writeFileSync(`${cwd}/packages/a/aaa.txt`, "AAA");
const sha2 = gitCommitAll(cwd, "feat(aaa): Add missing text file");

// Third commit.
writeFileSync(`${cwd}/packages/b/bbb.txt`, "BBB");
const sha3 = gitCommitAll(cwd, "feat(bbb): Add missing text file");

const url = gitInitOrigin(cwd);
gitPush(cwd);

// Capture output.
const stdout = new WritableStreamBuffer();
const stderr = new WritableStreamBuffer();

// Call multiSemanticRelease()
// Include "@semantic-release/git" for made the git head changed
const multiSemanticRelease = require("../../");
const result = await multiSemanticRelease(
[
`packages/c/package.json`,
`packages/d/package.json`,
`packages/b/package.json`,
`packages/a/package.json`,
],
{
plugins: [
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/git",
],
analyzeCommits: ["@semantic-release/commit-analyzer"],
},
{ cwd, stdout, stderr },
{ deps: {}, dryRun: false }
);

const logOutput = gitGetLog(cwd, 3, "HEAD");
expect(logOutput).not.toMatch(/.*aaa.*Add missing text file.*\n.*bbb.*Add missing text file.*/);
});
test("Deep errors (e.g. in plugins) bubble up and out", async () => {
// Create Git repo with copy of Yarn workspaces fixture.
const cwd = gitInit();
Expand Down

0 comments on commit f82f125

Please sign in to comment.