Skip to content

Commit 8ee2744

Browse files
authoredJul 19, 2024··
fix: invalid GraphQL query generated when no release commits are found (#876)
1 parent 500240b commit 8ee2744

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed
 

‎lib/success.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export default async function success(pluginConfig, context, { Octokit }) {
5454

5555
const errors = [];
5656

57-
if (successComment === false) {
57+
if (successComment === false || isEmpty(commits)) {
58+
if (isEmpty(commits)) {
59+
logger.log("No commits found in release");
60+
}
5861
logger.log("Skip commenting on issues and pull requests.");
5962
} else {
6063
const parser = issueParser(

‎test/success.test.js

+55
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,61 @@ test("Do not add comment and labels if no PR is associated with release commits"
806806
t.true(fetch.done());
807807
});
808808

809+
test("Do not add comment and labels if no commits is found for release", async (t) => {
810+
const owner = "test_user";
811+
const repo = "test_repo";
812+
const env = { GITHUB_TOKEN: "github_token" };
813+
const failTitle = "The automated release is failing 🚨";
814+
const pluginConfig = { failTitle };
815+
const options = {
816+
branch: "master",
817+
repositoryUrl: `https://github.com/${owner}/${repo}.git`,
818+
};
819+
const commits = [];
820+
const nextRelease = { version: "1.1.0" };
821+
const releases = [
822+
{ name: "GitHub release", url: "https://github.com/release" },
823+
];
824+
825+
const fetch = fetchMock
826+
.sandbox()
827+
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
828+
full_name: `${owner}/${repo}`,
829+
})
830+
.getOnce(
831+
`https://api.github.local/search/issues?q=${encodeURIComponent(
832+
"in:title",
833+
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
834+
"type:issue",
835+
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
836+
{ items: [] },
837+
);
838+
839+
await success(
840+
pluginConfig,
841+
{
842+
env,
843+
options,
844+
commits,
845+
nextRelease,
846+
releases,
847+
logger: t.context.logger,
848+
},
849+
{
850+
Octokit: TestOctokit.defaults((options) => ({
851+
...options,
852+
request: { ...options.request, fetch },
853+
})),
854+
},
855+
);
856+
857+
t.true(fetch.done());
858+
t.true(t.context.log.calledWith("No commits found in release"));
859+
t.true(
860+
t.context.log.calledWith("Skip commenting on issues and pull requests."),
861+
);
862+
});
863+
809864
test("Do not add comment and labels to PR/issues from other repo", async (t) => {
810865
const owner = "test_user";
811866
const repo = "test_repo";

0 commit comments

Comments
 (0)
Please sign in to comment.