Skip to content

Commit

Permalink
fix: invalid GraphQL query generated when no release commits are found (
Browse files Browse the repository at this point in the history
  • Loading branch information
babblebey authored Jul 19, 2024
1 parent 500240b commit 8ee2744
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
55 changes: 55 additions & 0 deletions test/success.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 8ee2744

Please sign in to comment.