diff --git a/lib/success.js b/lib/success.js index 49ad22e1..8c2d4583 100644 --- a/lib/success.js +++ b/lib/success.js @@ -54,7 +54,10 @@ export default async function success(pluginConfig, context, { Octokit }) { const errors = []; - if (successComment === false) { + if (successComment === false || isEmpty(commits)) { + if (isEmpty(commits)) { + logger.log("No commits found in release"); + } logger.log("Skip commenting on issues and pull requests."); } else { const parser = issueParser( diff --git a/test/success.test.js b/test/success.test.js index 5ef815ad..8d87dccd 100644 --- a/test/success.test.js +++ b/test/success.test.js @@ -806,6 +806,61 @@ test("Do not add comment and labels if no PR is associated with release commits" t.true(fetch.done()); }); +test("Do not add comment and labels if no commits is found for release", async (t) => { + const owner = "test_user"; + const repo = "test_repo"; + const env = { GITHUB_TOKEN: "github_token" }; + const failTitle = "The automated release is failing 🚨"; + const pluginConfig = { failTitle }; + const options = { + branch: "master", + repositoryUrl: `https://github.com/${owner}/${repo}.git`, + }; + const commits = []; + const nextRelease = { version: "1.1.0" }; + const releases = [ + { name: "GitHub release", url: "https://github.com/release" }, + ]; + + const fetch = fetchMock + .sandbox() + .getOnce(`https://api.github.local/repos/${owner}/${repo}`, { + full_name: `${owner}/${repo}`, + }) + .getOnce( + `https://api.github.local/search/issues?q=${encodeURIComponent( + "in:title", + )}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent( + "type:issue", + )}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`, + { items: [] }, + ); + + await success( + pluginConfig, + { + env, + options, + commits, + nextRelease, + releases, + logger: t.context.logger, + }, + { + Octokit: TestOctokit.defaults((options) => ({ + ...options, + request: { ...options.request, fetch }, + })), + }, + ); + + t.true(fetch.done()); + t.true(t.context.log.calledWith("No commits found in release")); + t.true( + t.context.log.calledWith("Skip commenting on issues and pull requests."), + ); +}); + test("Do not add comment and labels to PR/issues from other repo", async (t) => { const owner = "test_user"; const repo = "test_repo";