From d8fb827e63093ddeeb4d4c71bff5e82849d073ad Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 12:35:40 +0100 Subject: [PATCH 01/29] feat: add graphql query loader `loadGetSRIssuesQuery` to fetch SRIssues --- lib/find-sr-issues.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index d0fe8760..46cfb4bc 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -9,3 +9,20 @@ export default async (octokit, title, owner, repo) => { return issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID)); }; + +/** + * GraphQL Query to et the semantic-release issues for a repository. + */ +const loadGetSRIssuesQuery = `#graphql + query getSRIssues($owner: String!, $repo: String!, $labels: [String] | String) { + repository(owner: $owner, name: $repo) { + issues(first: 100, states: OPEN, filterBy: { labels: $labels }) { + nodes { + number + title + bodyText + } + } + } + } +`; \ No newline at end of file From 8945a63b8ed6ee480f5c3ac718300592ffb53ab3 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 13:33:28 +0100 Subject: [PATCH 02/29] chore: add new `RELEASE_FAIL_LABEL` constant --- lib/definitions/constants.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/definitions/constants.js b/lib/definitions/constants.js index dc22169a..cf2140cf 100644 --- a/lib/definitions/constants.js +++ b/lib/definitions/constants.js @@ -1,3 +1,5 @@ export const ISSUE_ID = ""; export const RELEASE_NAME = "GitHub release"; + +export const RELEASE_FAIL_LABEL = "release-failing"; \ No newline at end of file From 70ca54f3a6ed2e7edab12b2c514f14ec231c46ca Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 13:34:10 +0100 Subject: [PATCH 03/29] feat: integrate issues fetch with graphql --- lib/find-sr-issues.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index 46cfb4bc..e750ef90 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -1,12 +1,22 @@ -import { ISSUE_ID } from "./definitions/constants.js"; +import { ISSUE_ID, RELEASE_FAIL_LABEL } from "./definitions/constants.js"; export default async (octokit, title, owner, repo) => { + let issues = []; + const { - data: { items: issues }, - } = await octokit.request("GET /search/issues", { - q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`, + data: { + repository: { + issues: { nodes: issueNodes }, + }, + }, + } = await octokit.graphql(loadGetSRIssuesQuery, { + owner, + repo, + labels: RELEASE_FAIL_LABEL, }); + issues.push(...issueNodes); + return issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID)); }; @@ -20,7 +30,7 @@ const loadGetSRIssuesQuery = `#graphql nodes { number title - bodyText + body: bodyText } } } From 7f9875a364bb0ab90f008b88230c0324cb48fd1a Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 13:43:17 +0100 Subject: [PATCH 04/29] feat: add fallback to searchAPI for backward compatibility --- lib/find-sr-issues.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index e750ef90..c5ed28a0 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -16,6 +16,23 @@ export default async (octokit, title, owner, repo) => { }); issues.push(...issueNodes); + + /** + * BACKWARD COMPATIBILITY: Fallback to the search API if the issue was not found in the GraphQL response. + * This fallback will be removed in a future release + */ + if (issueNodes.length === 0) { + try { + const { + data: { items: backwardIssues }, + } = await octokit.request("GET /search/issues", { + q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`, + }); + issues.push(...backwardIssues); + } catch (error) { + console.log("Error: ", error); + } + } return issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID)); }; From f2c9b84a4237ec5a5df338a869a1d5754ce08612 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 16:07:36 +0100 Subject: [PATCH 05/29] feat: integrated config label in SRIssues search --- lib/find-sr-issues.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index c5ed28a0..34b68024 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -1,6 +1,6 @@ import { ISSUE_ID, RELEASE_FAIL_LABEL } from "./definitions/constants.js"; -export default async (octokit, title, owner, repo) => { +export default async (octokit, title, labels, owner, repo) => { let issues = []; const { @@ -12,7 +12,7 @@ export default async (octokit, title, owner, repo) => { } = await octokit.graphql(loadGetSRIssuesQuery, { owner, repo, - labels: RELEASE_FAIL_LABEL, + labels: (labels || []).concat([RELEASE_FAIL_LABEL]), }); issues.push(...issueNodes); From f8160f3f37b7a00d66044930429bbd26bcfb1203 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 16:08:43 +0100 Subject: [PATCH 06/29] fix: error `getSRIssue` graphql query label param type --- lib/find-sr-issues.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index 34b68024..a88ba548 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -41,7 +41,7 @@ export default async (octokit, title, labels, owner, repo) => { * GraphQL Query to et the semantic-release issues for a repository. */ const loadGetSRIssuesQuery = `#graphql - query getSRIssues($owner: String!, $repo: String!, $labels: [String] | String) { + query getSRIssues($owner: String!, $repo: String!, $labels: [String!]) { repository(owner: $owner, name: $repo) { issues(first: 100, states: OPEN, filterBy: { labels: $labels }) { nodes { From 63c1dc5133e96a4a3561a9aae1471dc124905ccd Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 16:09:54 +0100 Subject: [PATCH 07/29] fix: undefined `data` property destructed from graphql reponse --- lib/find-sr-issues.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index a88ba548..9fe3bd66 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -4,11 +4,9 @@ export default async (octokit, title, labels, owner, repo) => { let issues = []; const { - data: { - repository: { - issues: { nodes: issueNodes }, - }, - }, + repository: { + issues: { nodes: issueNodes }, + } } = await octokit.graphql(loadGetSRIssuesQuery, { owner, repo, From 9189ccf69bf4d4abddac5d378db27d7aa8eaaf3b Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 16:11:12 +0100 Subject: [PATCH 08/29] refactor: modified wrong `body` property in query --- lib/find-sr-issues.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index 9fe3bd66..4a170d48 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -45,7 +45,7 @@ const loadGetSRIssuesQuery = `#graphql nodes { number title - body: bodyText + body } } } From a478a2b7c63ed65578045caadad6132621c4da03 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 16:12:12 +0100 Subject: [PATCH 09/29] refactor: remove conditions from searchAPI fallback logic --- lib/find-sr-issues.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index 4a170d48..ca2b7756 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -19,17 +19,15 @@ export default async (octokit, title, labels, owner, repo) => { * BACKWARD COMPATIBILITY: Fallback to the search API if the issue was not found in the GraphQL response. * This fallback will be removed in a future release */ - if (issueNodes.length === 0) { - try { - const { - data: { items: backwardIssues }, - } = await octokit.request("GET /search/issues", { - q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`, - }); - issues.push(...backwardIssues); - } catch (error) { - console.log("Error: ", error); - } + try { + const { + data: { items: backwardIssues }, + } = await octokit.request("GET /search/issues", { + q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`, + }); + issues.push(...backwardIssues); + } catch (error) { + console.log("Error: ", error); } return issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID)); From 4bf11b0c9901298ccfd55c317b3866fbc2c69cef Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 16:23:05 +0100 Subject: [PATCH 10/29] refactor: replace `getSRIssues` graphql query `label` param with `filter` --- lib/find-sr-issues.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index ca2b7756..2e8c6670 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -10,7 +10,9 @@ export default async (octokit, title, labels, owner, repo) => { } = await octokit.graphql(loadGetSRIssuesQuery, { owner, repo, - labels: (labels || []).concat([RELEASE_FAIL_LABEL]), + filter: { + labels: (labels || []).concat([RELEASE_FAIL_LABEL]) + }, }); issues.push(...issueNodes); @@ -37,9 +39,9 @@ export default async (octokit, title, labels, owner, repo) => { * GraphQL Query to et the semantic-release issues for a repository. */ const loadGetSRIssuesQuery = `#graphql - query getSRIssues($owner: String!, $repo: String!, $labels: [String!]) { + query getSRIssues($owner: String!, $repo: String!, $filter: IssueFilters) { repository(owner: $owner, name: $repo) { - issues(first: 100, states: OPEN, filterBy: { labels: $labels }) { + issues(first: 100, states: OPEN, filterBy: $filter) { nodes { number title From 7be5548a3c6e91c6b46394e5e44fa880db301001 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 16:40:13 +0100 Subject: [PATCH 11/29] feat: implement unique issue sorting to address fallback `backwardIssues` conflict --- lib/find-sr-issues.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index 2e8c6670..8039e846 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -1,3 +1,4 @@ +import { uniqBy } from "lodash-es"; import { ISSUE_ID, RELEASE_FAIL_LABEL } from "./definitions/constants.js"; export default async (octokit, title, labels, owner, repo) => { @@ -6,17 +7,17 @@ export default async (octokit, title, labels, owner, repo) => { const { repository: { issues: { nodes: issueNodes }, - } + }, } = await octokit.graphql(loadGetSRIssuesQuery, { owner, repo, filter: { - labels: (labels || []).concat([RELEASE_FAIL_LABEL]) + labels: (labels || []).concat([RELEASE_FAIL_LABEL]), }, }); issues.push(...issueNodes); - + /** * BACKWARD COMPATIBILITY: Fallback to the search API if the issue was not found in the GraphQL response. * This fallback will be removed in a future release @@ -32,7 +33,12 @@ export default async (octokit, title, labels, owner, repo) => { console.log("Error: ", error); } - return issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID)); + const uniqueSRIssues = uniqBy( + issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID)), + "number", + ); + + return uniqueSRIssues; }; /** @@ -50,4 +56,4 @@ const loadGetSRIssuesQuery = `#graphql } } } -`; \ No newline at end of file +`; From c95a52f456b6ef62d391720ce80bc323b293dc0e Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 16:44:42 +0100 Subject: [PATCH 12/29] feat: modify `findSRIssue` integration in `success` script; add `logger` to its params; --- lib/find-sr-issues.js | 4 ++-- lib/success.js | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index 8039e846..d58dff53 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -1,7 +1,7 @@ import { uniqBy } from "lodash-es"; import { ISSUE_ID, RELEASE_FAIL_LABEL } from "./definitions/constants.js"; -export default async (octokit, title, labels, owner, repo) => { +export default async (octokit, logger, title, labels, owner, repo) => { let issues = []; const { @@ -30,7 +30,7 @@ export default async (octokit, title, labels, owner, repo) => { }); issues.push(...backwardIssues); } catch (error) { - console.log("Error: ", error); + logger.error("Error fetching issue via fallback (with GH SearchAPI): ", error); } const uniqueSRIssues = uniqBy( diff --git a/lib/success.js b/lib/success.js index 59ab8d0f..cc64858d 100644 --- a/lib/success.js +++ b/lib/success.js @@ -28,6 +28,7 @@ export default async function success(pluginConfig, context, { Octokit }) { githubApiPathPrefix, githubApiUrl, proxy, + labels, successComment, failComment, failTitle, @@ -217,7 +218,14 @@ export default async function success(pluginConfig, context, { Octokit }) { if (failComment === false || failTitle === false) { logger.log("Skip closing issue."); } else { - const srIssues = await findSRIssues(octokit, failTitle, owner, repo); + const srIssues = await findSRIssues( + octokit, + logger, + failTitle, + labels, + owner, + repo, + ); debug("found semantic-release issues: %O", srIssues); From 5c184933c48a2c65eabf19c28c6369741a8d153d Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 16:46:11 +0100 Subject: [PATCH 13/29] feat: integrate opinionated `RELEASE_FAIL_LABEL` into `fail` script --- lib/fail.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fail.js b/lib/fail.js index 9439b87a..50846dd4 100644 --- a/lib/fail.js +++ b/lib/fail.js @@ -2,7 +2,7 @@ import { template } from "lodash-es"; import debugFactory from "debug"; import parseGithubUrl from "./parse-github-url.js"; -import { ISSUE_ID } from "./definitions/constants.js"; +import { ISSUE_ID, RELEASE_FAIL_LABEL } from "./definitions/constants.js"; import resolveConfig from "./resolve-config.js"; import { toOctokitOptions } from "./octokit.js"; import findSRIssues from "./find-sr-issues.js"; @@ -69,7 +69,7 @@ export default async function fail(pluginConfig, context, { Octokit }) { repo, title: failTitle, body: `${body}\n\n${ISSUE_ID}`, - labels: labels || [], + labels: (labels || []).concat([RELEASE_FAIL_LABEL]), assignees, }; debug("create issue: %O", newIssue); From cf6f182830a6f465beffada264f005840098e6a0 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 28 Aug 2024 16:48:45 +0100 Subject: [PATCH 14/29] chore: Questions and lint fixes --- lib/definitions/constants.js | 2 +- lib/find-sr-issues.js | 5 ++++- lib/resolve-config.js | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/definitions/constants.js b/lib/definitions/constants.js index cf2140cf..15e78a89 100644 --- a/lib/definitions/constants.js +++ b/lib/definitions/constants.js @@ -2,4 +2,4 @@ export const ISSUE_ID = ""; export const RELEASE_NAME = "GitHub release"; -export const RELEASE_FAIL_LABEL = "release-failing"; \ No newline at end of file +export const RELEASE_FAIL_LABEL = "release-failing"; diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index d58dff53..99c65d7c 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -30,7 +30,10 @@ export default async (octokit, logger, title, labels, owner, repo) => { }); issues.push(...backwardIssues); } catch (error) { - logger.error("Error fetching issue via fallback (with GH SearchAPI): ", error); + logger.error( + "Error fetching issue via fallback (with GH SearchAPI): %s", + error, + ); } const uniqueSRIssues = uniqBy( diff --git a/lib/resolve-config.js b/lib/resolve-config.js index b8081c88..6ab9eb48 100644 --- a/lib/resolve-config.js +++ b/lib/resolve-config.js @@ -34,6 +34,7 @@ export default function resolveConfig( ? "The automated release is failing 🚨" : failTitle, failComment, + // ATTN??? We opinionated :(??? labels: isNil(labels) ? ["semantic-release"] : labels === false From 9373a704d7c85657b8bdf336e4f4e11534f51255 Mon Sep 17 00:00:00 2001 From: babblebey Date: Thu, 29 Aug 2024 13:47:43 +0100 Subject: [PATCH 15/29] refactor: modified `findSRIssues` integration in `fail` script --- lib/fail.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/fail.js b/lib/fail.js index 50846dd4..1c90d873 100644 --- a/lib/fail.js +++ b/lib/fail.js @@ -50,7 +50,14 @@ export default async function fail(pluginConfig, context, { Octokit }) { const body = failComment ? template(failComment)({ branch, errors }) : getFailComment(branch, errors); - const [srIssue] = await findSRIssues(octokit, failTitle, owner, repo); + const [srIssue] = await findSRIssues( + octokit, + logger, + failTitle, + labels, + owner, + repo, + ); if (srIssue) { logger.log("Found existing semantic-release issue #%d.", srIssue.number); From cbe47c789143a801fb28c8e051f0280d2a3b7199 Mon Sep 17 00:00:00 2001 From: babblebey Date: Thu, 29 Aug 2024 15:44:56 +0100 Subject: [PATCH 16/29] test: fixed `findSRIssue` units test --- test/find-sr-issue.test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/find-sr-issue.test.js b/test/find-sr-issue.test.js index b6e4cefd..41992917 100644 --- a/test/find-sr-issue.test.js +++ b/test/find-sr-issue.test.js @@ -17,6 +17,7 @@ test("Filter out issues without ID", async (t) => { const owner = "test_user"; const repo = "test_repo"; const title = "The automated release is failing 🚨"; + const labels = []; const issues = [ { number: 1, body: "Issue 1 body", title }, { number: 2, body: `Issue 2 body\n\n${ISSUE_ID}`, title }, @@ -25,6 +26,13 @@ test("Filter out issues without ID", async (t) => { const fetch = fetchMock .sandbox() + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: issues }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -36,7 +44,9 @@ test("Filter out issues without ID", async (t) => { const srIssues = await findSRIssues( new TestOctokit({ request: { fetch } }), + t.context.logger, title, + labels, owner, repo, ); @@ -61,9 +71,17 @@ test("Return empty array if not issues found", async (t) => { const owner = "test_user"; const repo = "test_repo"; const title = "The automated release is failing 🚨"; + const labels = []; const issues = []; const fetch = fetchMock .sandbox() + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -75,7 +93,9 @@ test("Return empty array if not issues found", async (t) => { const srIssues = await findSRIssues( new TestOctokit({ request: { fetch } }), + t.context.logger, title, + labels, owner, repo, ); @@ -89,12 +109,20 @@ test("Return empty array if not issues has matching ID", async (t) => { const owner = "test_user"; const repo = "test_repo"; const title = "The automated release is failing 🚨"; + const labels = []; const issues = [ { number: 1, body: "Issue 1 body", title }, { number: 2, body: "Issue 2 body", title }, ]; const fetch = fetchMock .sandbox() + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: issues }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -106,7 +134,9 @@ test("Return empty array if not issues has matching ID", async (t) => { const srIssues = await findSRIssues( new TestOctokit({ request: { fetch } }), + t.context.logger, title, + labels, owner, repo, ); From 2efba0e2273998ba8c2abb5db81be12d2ed7deba Mon Sep 17 00:00:00 2001 From: babblebey Date: Thu, 29 Aug 2024 15:45:19 +0100 Subject: [PATCH 17/29] test: fixed `fail` unit tests --- test/fail.test.js | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/test/fail.test.js b/test/fail.test.js index 9b7caee9..99a49387 100644 --- a/test/fail.test.js +++ b/test/fail.test.js @@ -3,7 +3,7 @@ import sinon from "sinon"; import test from "ava"; import fetchMock from "fetch-mock"; -import { ISSUE_ID } from "../lib/definitions/constants.js"; +import { ISSUE_ID, RELEASE_FAIL_LABEL } from "../lib/definitions/constants.js"; import { TestOctokit } from "./helpers/test-octokit.js"; /* eslint camelcase: ["error", {properties: "never"}] */ @@ -36,6 +36,13 @@ test("Open a new issue with the list of errors", async (t) => { .getOnce("https://api.github.local/repos/test_user/test_repo", { full_name: `${redirectedOwner}/${redirectedRepo}`, }) + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -59,7 +66,7 @@ test("Open a new issue with the list of errors", async (t) => { data.body, /---\n\n### Error message 1\n\nError 1 details\n\n---\n\n### Error message 2\n\nError 2 details\n\n---\n\n### Error message 3\n\nError 3 details\n\n---/, ); - t.deepEqual(data.labels, ["semantic-release"]); + t.deepEqual(data.labels, ["semantic-release", RELEASE_FAIL_LABEL]); return true; }, { @@ -117,6 +124,13 @@ test("Open a new issue with the list of errors and custom title and comment", as full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -132,7 +146,7 @@ test("Open a new issue with the list of errors and custom title and comment", as body: { title: failTitle, body: `branch master Error message 1 Error message 2 Error message 3\n\n${ISSUE_ID}`, - labels: ["semantic-release"], + labels: ["semantic-release", RELEASE_FAIL_LABEL], }, }, ); @@ -185,6 +199,13 @@ test("Open a new issue with assignees and the list of errors", async (t) => { full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -203,7 +224,7 @@ test("Open a new issue with assignees and the list of errors", async (t) => { data.body, /---\n\n### Error message 1\n\nError 1 details\n\n---\n\n### Error message 2\n\nError 2 details\n\n---/, ); - t.deepEqual(data.labels, ["semantic-release"]); + t.deepEqual(data.labels, ["semantic-release", RELEASE_FAIL_LABEL]); t.deepEqual(data.assignees, ["user1", "user2"]); return true; }, @@ -258,6 +279,13 @@ test("Open a new issue without labels and the list of errors", async (t) => { full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -276,7 +304,7 @@ test("Open a new issue without labels and the list of errors", async (t) => { data.body, /---\n\n### Error message 1\n\nError 1 details\n\n---\n\n### Error message 2\n\nError 2 details\n\n---/, ); - t.deepEqual(data.labels, []); + t.deepEqual(data.labels, [RELEASE_FAIL_LABEL]); return true; }, { html_url: "https://github.com/issues/1", number: 1 }, @@ -335,6 +363,13 @@ test("Update the first existing issue with the list of errors", async (t) => { full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: issues }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", From 91dec1cf053139c5e60ab5212653b0aeed3fa017 Mon Sep 17 00:00:00 2001 From: babblebey Date: Thu, 29 Aug 2024 16:06:37 +0100 Subject: [PATCH 18/29] test: fix integrations test --- test/integration.test.js | 156 +++++++++++++++++++++++++++++---------- 1 file changed, 117 insertions(+), 39 deletions(-) diff --git a/test/integration.test.js b/test/integration.test.js index 68afd4a9..c5a38dc4 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -2,6 +2,7 @@ import test from "ava"; import sinon from "sinon"; import SemanticReleaseError from "@semantic-release/error"; import fetchMock from "fetch-mock"; +import { RELEASE_FAIL_LABEL } from "../lib/definitions/constants.js"; import { TestOctokit } from "./helpers/test-octokit.js"; @@ -450,22 +451,29 @@ test("Comment and add labels on PR included in the releases", async (t) => { repeat: 2, }, ) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -491,6 +499,20 @@ test("Comment and add labels on PR included in the releases", async (t) => { body: ["released"], }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -556,6 +578,13 @@ test("Open a new issue with the list of errors", async (t) => { }, { repeat: 2 }, ) + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -573,7 +602,7 @@ test("Open a new issue with the list of errors", async (t) => { data.body, /---\n\n### Error message 1\n\nError 1 details\n\n---\n\n### Error message 2\n\nError 2 details\n\n---\n\n### Error message 3\n\nError 3 details\n\n---/, ); - t.deepEqual(data.labels, ["semantic-release"]); + t.deepEqual(data.labels, ["semantic-release", RELEASE_FAIL_LABEL]); return true; }, @@ -653,6 +682,29 @@ test("Verify, release and notify success", async (t) => { repeat: 2, }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], + }, + }, + }, + }, + }, + ) .postOnce( `https://api.github.local/repos/${owner}/${repo}/releases`, { @@ -675,22 +727,6 @@ test("Verify, release and notify success", async (t) => { { html_url: releaseUrl }, { body: { draft: false } }, ) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, - }, - nodes: [prs[0]], - }, - }, - }, - }, - }) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -700,6 +736,20 @@ test("Verify, release and notify success", async (t) => { {}, { body: ["released"] }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -834,22 +884,29 @@ test("Verify, update release and notify success", async (t) => { }, }, ) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -867,6 +924,20 @@ test("Verify, update release and notify success", async (t) => { body: ["released"], }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -957,6 +1028,13 @@ test("Verify and notify failure", async (t) => { repeat: 2, }, ) + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", From ba214dea9900e815fb6cf1be759fe69c1549efc1 Mon Sep 17 00:00:00 2001 From: babblebey Date: Thu, 29 Aug 2024 17:18:01 +0100 Subject: [PATCH 19/29] test: fixed `success` unit tests --- test/success.test.js | 1019 +++++++++++++++++++++++++++++------------- 1 file changed, 716 insertions(+), 303 deletions(-) diff --git a/test/success.test.js b/test/success.test.js index 97fcb787..a793d59d 100644 --- a/test/success.test.js +++ b/test/success.test.js @@ -59,32 +59,39 @@ test("Add comment and labels to PRs associated with release commits and issues s full_name: `${redirectedOwner}/${redirectedRepo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, - }, - commit456: { - oid: "456", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commit456: { + oid: "456", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[1]], }, - nodes: [prs[1]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${redirectedOwner}/${redirectedRepo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -131,6 +138,20 @@ test("Add comment and labels to PRs associated with release commits and issues s {}, { body: ["released"] }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -332,6 +353,20 @@ test("Add comment and labels to PRs associated with release commits and issues ( {}, { body: ["released"] }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -430,32 +465,39 @@ test("Add comment and labels to PRs associated with release commits and issues c .getOnce(`https://custom-url.com/prefix/repos/${owner}/${repo}`, { full_name: `${owner}/${repo}`, }) - .postOnce("https://custom-url.com/prefix/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://custom-url.com/prefix/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, - }, - commit456: { - oid: "456", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commit456: { + oid: "456", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[1]], }, - nodes: [prs[1]], }, }, }, }, - }) + ) .getOnce( `https://custom-url.com/prefix/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -508,6 +550,20 @@ test("Add comment and labels to PRs associated with release commits and issues c {}, { body: ["released on @next"] }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://custom-url.com/prefix/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://custom-url.com/prefix/search/issues?q=${encodeURIComponent( "in:title", @@ -632,72 +688,79 @@ test("Make multiple search queries if necessary", async (t) => { full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .post("https://api.github.local/graphql", { - data: { - repository: { - commitaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: { - oid: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commitaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: { + oid: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, - }, - commitbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: { - oid: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commitbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb: { + oid: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[1]], }, - nodes: [prs[1]], }, - }, - commitcccccccccccccccccccccccccccccccccccccccccc: { - oid: "cccccccccccccccccccccccccccccccccccccccccc", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commitcccccccccccccccccccccccccccccccccccccccccc: { + oid: "cccccccccccccccccccccccccccccccccccccccccc", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[2]], }, - nodes: [prs[2]], }, - }, - commiteeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee: { - oid: "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commiteeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee: { + oid: "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[3]], }, - nodes: [prs[3]], }, - }, - commitffffffffffffffffffffffffffffffffffffffffff: { - oid: "ffffffffffffffffffffffffffffffffffffffffff", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commitffffffffffffffffffffffffffffffffffffffffff: { + oid: "ffffffffffffffffffffffffffffffffffffffffff", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[4]], }, - nodes: [prs[4]], }, - }, - commitgggggggggggggggggggggggggggggggggggggggggg: { - oid: "gggggggggggggggggggggggggggggggggggggggggg", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commitgggggggggggggggggggggggggggggggggggggggggg: { + oid: "gggggggggggggggggggggggggggggggggggggggggg", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[5]], }, - nodes: [prs[5]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -788,6 +851,20 @@ test("Make multiple search queries if necessary", async (t) => { body: ["released"], }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -907,32 +984,39 @@ test("Do not add comment and labels for unrelated PR returned by search (compare full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, - }, - commit456: { - oid: "456", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commit456: { + oid: "456", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[1]], }, - nodes: [prs[1]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: "rebased_sha" }], @@ -958,6 +1042,20 @@ test("Do not add comment and labels for unrelated PR returned by search (compare {}, { body: ["released"] }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -1020,22 +1118,43 @@ test("Do not add comment and labels if no PR is associated with release commits" full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [], }, - nodes: [], }, }, }, }, - }) + ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -1088,6 +1207,13 @@ test("Do not add comment and labels if no commits is found for release", async ( full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -1148,42 +1274,49 @@ test("Do not add comment and labels to PR/issues from other repo", async (t) => full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, - }, - nodes: [], + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [], + }, }, - }, - commit456: { - oid: "456", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commit456: { + oid: "456", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [], }, - nodes: [], }, - }, - commit789: { - oid: "789", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commit789: { + oid: "789", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [], }, - nodes: [], }, }, }, }, - }) + ) .postOnce( `https://api.github.local/repos/${owner}/${repo}/issues/2/comments`, { html_url: "https://github.com/successcomment-2" }, @@ -1193,6 +1326,20 @@ test("Do not add comment and labels to PR/issues from other repo", async (t) => {}, { body: ["released"] }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -1264,42 +1411,49 @@ test("Ignore missing and forbidden issues/PRs", async (t) => { full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, - }, - commit456: { - oid: "456", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commit456: { + oid: "456", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[1]], }, - nodes: [prs[1]], }, - }, - commit789: { - oid: "789", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commit789: { + oid: "789", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[2]], }, - nodes: [prs[2]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -1347,6 +1501,20 @@ test("Ignore missing and forbidden issues/PRs", async (t) => { {}, { body: ["released"] }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -1449,22 +1617,29 @@ test("Add custom comment and labels", async (t) => { full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -1483,6 +1658,20 @@ test("Add custom comment and labels", async (t) => { {}, { body: ["released on @next", "released from master"] }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -1550,22 +1739,29 @@ test("Add custom label", async (t) => { full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -1579,6 +1775,20 @@ test("Add custom label", async (t) => { {}, { body: ["custom label"] }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -1646,22 +1856,29 @@ test("Comment on issue/PR without ading a label", async (t) => { full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -1670,6 +1887,20 @@ test("Comment on issue/PR without ading a label", async (t) => { `https://api.github.local/repos/${owner}/${repo}/issues/1/comments`, { html_url: "https://github.com/successcomment-1" }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -1745,22 +1976,29 @@ test("Editing the release to include all release links at the bottom", async (t) full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -1769,6 +2007,20 @@ test("Editing the release to include all release links at the bottom", async (t) `https://api.github.local/repos/${owner}/${repo}/issues/1/comments`, { html_url: "https://github.com/successcomment-1" }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -1855,22 +2107,29 @@ test("Editing the release to include all release links at the top", async (t) => full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -1879,6 +2138,20 @@ test("Editing the release to include all release links at the top", async (t) => `https://api.github.local/repos/${owner}/${repo}/issues/1/comments`, { html_url: "https://github.com/successcomment-1" }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -1962,22 +2235,29 @@ test("Editing the release to include all release links with no additional releas full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -1986,6 +2266,20 @@ test("Editing the release to include all release links with no additional releas `https://api.github.local/repos/${owner}/${repo}/issues/1/comments`, { html_url: "https://github.com/successcomment-1" }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -2058,22 +2352,29 @@ test("Editing the release to include all release links with no additional releas full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -2082,6 +2383,20 @@ test("Editing the release to include all release links with no additional releas `https://api.github.local/repos/${owner}/${repo}/issues/1/comments`, { html_url: "https://github.com/successcomment-1" }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -2147,22 +2462,29 @@ test("Editing the release to include all release links with no releases", async full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -2171,6 +2493,20 @@ test("Editing the release to include all release links with no releases", async `https://api.github.local/repos/${owner}/${repo}/issues/1/comments`, { html_url: "https://github.com/successcomment-1" }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -2238,22 +2574,29 @@ test("Editing the release with no ID in the release", async (t) => { full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -2262,6 +2605,20 @@ test("Editing the release with no ID in the release", async (t) => { `https://api.github.local/repos/${owner}/${repo}/issues/1/comments`, { html_url: "https://github.com/successcomment-1" }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -2334,32 +2691,39 @@ test("Ignore errors when adding comments and closing issues", async (t) => { full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, - }, - commit456: { - oid: "456", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + commit456: { + oid: "456", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[1]], }, - nodes: [prs[1]], }, }, }, }, - }) + ) .getOnce( `https://api.github.local/repos/${owner}/${repo}/pulls/1/commits`, [{ sha: commits[0].hash }], @@ -2381,6 +2745,20 @@ test("Ignore errors when adding comments and closing issues", async (t) => { {}, { body: ["released"] }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -2478,22 +2856,43 @@ test("Close open issues when a release is successful", async (t) => { full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); + return true; + }, + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [], }, - nodes: [], }, }, }, }, - }) + ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: issues }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -2584,6 +2983,20 @@ test('Skip commention on issues/PR if "successComment" is "false"', async (t) => full_name: `${owner}/${repo}`, clone_url: `https://api.github.local/${owner}/${repo}.git`, }) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", From 50c3f9ce87337f435b35d67e752862077af23de9 Mon Sep 17 00:00:00 2001 From: babblebey Date: Thu, 29 Aug 2024 17:58:50 +0100 Subject: [PATCH 20/29] test: `Verify, release and notify success` fix attempt --- test/integration.test.js | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/test/integration.test.js b/test/integration.test.js index c5a38dc4..d39ffd37 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -682,29 +682,22 @@ test("Verify, release and notify success", async (t) => { repeat: 2, }, ) - .postOnce( - (url, { body }) => { - t.is(url, "https://api.github.local/graphql"); - t.regex(JSON.parse(body).query, /query getAssociatedPRs\(/); - return true; - }, - { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, - }, - nodes: [prs[0]], + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, }, + nodes: [prs[0]], }, }, }, }, - ) + }) .postOnce( `https://api.github.local/repos/${owner}/${repo}/releases`, { @@ -737,8 +730,7 @@ test("Verify, release and notify success", async (t) => { { body: ["released"] }, ) .postOnce( - (url, { body }) => { - t.is(url, "https://api.github.local/graphql"); + (_, { body }) => { t.regex(JSON.parse(body).query, /query getSRIssues\(/); return true; }, From 2f2b1548de9bf716c8c7779a7fcd638b6dd37df6 Mon Sep 17 00:00:00 2001 From: babblebey Date: Fri, 30 Aug 2024 21:15:49 +0100 Subject: [PATCH 21/29] test: addressed `"Verify, release and notify success"` case in `integrations` --- test/integration.test.js | 52 +++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/test/integration.test.js b/test/integration.test.js index d39ffd37..4d4d8506 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -682,22 +682,39 @@ test("Verify, release and notify success", async (t) => { repeat: 2, }, ) - .postOnce("https://api.github.local/graphql", { - data: { - repository: { - commit123: { - oid: "123", - associatedPullRequests: { - pageInfo: { - endCursor: "NI", - hasNextPage: false, + .postOnce( + (url, { body }) => + url === "https://api.github.local/graphql" && + JSON.parse(body).query.includes("query getAssociatedPRs("), + { + data: { + repository: { + commit123: { + oid: "123", + associatedPullRequests: { + pageInfo: { + endCursor: "NI", + hasNextPage: false, + }, + nodes: [prs[0]], }, - nodes: [prs[0]], }, }, }, }, - }) + ) + .postOnce( + (url, { body }) => + url === "https://api.github.local/graphql" && + JSON.parse(body).query.includes("query getSRIssues("), + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .postOnce( `https://api.github.local/repos/${owner}/${repo}/releases`, { @@ -729,19 +746,6 @@ test("Verify, release and notify success", async (t) => { {}, { body: ["released"] }, ) - .postOnce( - (_, { body }) => { - t.regex(JSON.parse(body).query, /query getSRIssues\(/); - return true; - }, - { - data: { - repository: { - issues: { nodes: [] }, - }, - }, - }, - ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", From a0ac832b4a5e0c1b5f7388bb4471235e76ed0e14 Mon Sep 17 00:00:00 2001 From: babblebey Date: Mon, 2 Sep 2024 19:15:28 +0100 Subject: [PATCH 22/29] test: fix `success` units --- test/success.test.js | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/success.test.js b/test/success.test.js index dbdf57c7..d34923d2 100644 --- a/test/success.test.js +++ b/test/success.test.js @@ -3436,6 +3436,13 @@ test('Does not comment/label on issues/PR if "successCommentCondition" is "false .getOnce(`https://api.github.local/repos/${owner}/${repo}`, { full_name: `${owner}/${repo}`, }) + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -3643,6 +3650,18 @@ test('Add comment and label to found issues/associatedPR using the "successComme `https://api.github.local/repos/${owner}/${repo}/pulls/5/commits`, [{ sha: commits[1].hash }], ) + .postOnce( + (url, { body }) => + url === "https://api.github.local/graphql" && + JSON.parse(body).query.includes("query getSRIssues("), + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -3973,6 +3992,20 @@ test('Does not comment/label associatedPR and relatedIssues created by "Bots"', {}, { body: ["released"] }, ) + .postOnce( + (url, { body }) => { + t.is(url, "https://api.github.local/graphql"); + t.regex(JSON.parse(body).query, /query getSRIssues\(/); + return true; + }, + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -4164,6 +4197,18 @@ test('Does not comment/label "associatedPR" when "successCommentCondition" disab {}, { body: ["released"] }, ) + .postOnce( + (url, { body }) => + url === "https://api.github.local/graphql" && + JSON.parse(body).query.includes("query getSRIssues("), + { + data: { + repository: { + issues: { nodes: issues }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", From f3a6bd63d0ea72e8f84a3fd08634376b26b122b6 Mon Sep 17 00:00:00 2001 From: babblebey Date: Mon, 2 Sep 2024 19:15:43 +0100 Subject: [PATCH 23/29] test: fix `fail` units --- test/fail.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/fail.test.js b/test/fail.test.js index c9417107..b95e3c76 100644 --- a/test/fail.test.js +++ b/test/fail.test.js @@ -536,6 +536,18 @@ test('Does not post comments on existing issues when "failCommentCondition" is " .getOnce(`https://api.github.local/repos/${owner}/${repo}`, { full_name: `${owner}/${repo}`, }) + .postOnce( + (url, { body }) => + url === "https://api.github.local/graphql" && + JSON.parse(body).query.includes("query getSRIssues("), + { + data: { + repository: { + issues: { nodes: issues }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", @@ -586,6 +598,18 @@ test(`Post new issue if none exists yet, but don't comment on existing issues wh .getOnce(`https://api.github.local/repos/${owner}/${repo}`, { full_name: `${owner}/${repo}`, }) + .postOnce( + (url, { body }) => + url === "https://api.github.local/graphql" && + JSON.parse(body).query.includes("query getSRIssues("), + { + data: { + repository: { + issues: { nodes: [] }, + }, + }, + }, + ) .getOnce( `https://api.github.local/search/issues?q=${encodeURIComponent( "in:title", From 5a6d6ddf041822da7cc9b36d2cf6eb2312d952c3 Mon Sep 17 00:00:00 2001 From: babblebey Date: Mon, 2 Sep 2024 19:16:14 +0100 Subject: [PATCH 24/29] refactor: remove error object from searchAPI fallback error handle --- lib/find-sr-issues.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index 99c65d7c..13bf8be4 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -30,9 +30,8 @@ export default async (octokit, logger, title, labels, owner, repo) => { }); issues.push(...backwardIssues); } catch (error) { - logger.error( - "Error fetching issue via fallback (with GH SearchAPI): %s", - error, + logger.log( + "An error occured fetching issue via fallback (with GH SearchAPI)", ); } From 0e3c2dc20b401b009bc7ede98882753a23245eed Mon Sep 17 00:00:00 2001 From: babblebey Date: Mon, 2 Sep 2024 19:16:59 +0100 Subject: [PATCH 25/29] test: add new case `"Handle error in searchAPI fallback"` --- test/find-sr-issue.test.js | 96 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/test/find-sr-issue.test.js b/test/find-sr-issue.test.js index 41992917..2f8125e8 100644 --- a/test/find-sr-issue.test.js +++ b/test/find-sr-issue.test.js @@ -144,3 +144,99 @@ test("Return empty array if not issues has matching ID", async (t) => { t.deepEqual(srIssues, []); t.true(fetch.done()); }); + +test("Handle error in searchAPI fallback", async (t) => { + const owner = "test_user"; + const repo = "test_repo"; + const title = "The automated release is failing 🚨"; + const labels = []; + const issues = [ + { number: 1, body: "Issue 1 body", title }, + { number: 2, body: `Issue 2 body\n\n${ISSUE_ID}`, title }, + { number: 3, body: `Issue 3 body\n\n${ISSUE_ID}`, title }, + ]; + const response = new Response("Not Found", { + url: "https://api.github.com/search/issues?q=in%3Atitle+repo%3Aourorg%2Frepo+type%3Aissue+state%3Aopen+The%20automated%20release%20is%20failing%20%F0%9F%9A%A8", + status: 403, + headers: { + "access-control-allow-origin": "*", + "access-control-expose-headers": + "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset", + "content-encoding": "gzip", + "content-security-policy": "default-repo 'none'", + "content-type": "application/json; charset=utf-8", + date: "Tue, 28 May 2024 19:49:00 GMT", + "referrer-policy": + "origin-when-cross-origin, strict-origin-when-cross-origin", + server: "GitHub.com", + "strict-transport-security": + "max-age=31536000; includeSubdomains; preload", + "transfer-encoding": "chunked", + vary: "Accept-Encoding, Accept, X-Requested-With", + "x-content-type-options": "nosniff", + "x-frame-options": "deny", + "x-github-api-version-selected": "2022-11-28", + "x-github-media-type": "github.v3; format=json", + "x-github-request-id": "2**0:29*****4:3868737:6*****3:6****52C", + "x-ratelimit-limit": "30", + "x-ratelimit-remaining": "30", + "x-ratelimit-reset": "1716925800", + "x-ratelimit-resource": "search", + "x-ratelimit-used": "1", + "x-xss-protection": "0", + }, + data: { + documentation_url: + "https://docs.github.com/free-pro-team@latest/rest/overview/rate-limits-for-the-rest-api#about-secondary-rate-limits", + message: + "You have exceeded a secondary rate limit. Please wait a few minutes before you try again. If you reach out to GitHub Support for help, please include the request ID 2840:295B44:3868737:64A2183:6232352C.", + }, + }); + + const fetch = fetchMock + .sandbox() + .postOnce("https://api.github.local/graphql", { + data: { + repository: { + issues: { nodes: issues }, + }, + }, + }) + .getOnce( + `https://api.github.local/search/issues?q=${encodeURIComponent( + "in:title", + )}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent( + "type:issue", + )}+${encodeURIComponent("state:open")}+${encodeURIComponent(title)}`, + response, + ); + + const srIssues = await findSRIssues( + new TestOctokit({ request: { fetch } }), + t.context.logger, + title, + labels, + owner, + repo, + ); + + t.deepEqual(srIssues, [ + { + number: 2, + body: "Issue 2 body\n\n", + title, + }, + { + number: 3, + body: "Issue 3 body\n\n", + title, + }, + ]); + t.true( + t.context.log.calledWith( + "An error occured fetching issue via fallback (with GH SearchAPI)", + ), + ); + t.log(t.context.log); + t.true(fetch.done()); +}); From 1065e0840071bf45c7ed5d13a6b6574f01db1eec Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 11 Sep 2024 20:00:07 +0100 Subject: [PATCH 26/29] Revert "refactor: remove conditions from searchAPI fallback logic" This reverts commit a478a2b7c63ed65578045caadad6132621c4da03. --- lib/find-sr-issues.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/find-sr-issues.js b/lib/find-sr-issues.js index 13bf8be4..47af4104 100644 --- a/lib/find-sr-issues.js +++ b/lib/find-sr-issues.js @@ -22,17 +22,19 @@ export default async (octokit, logger, title, labels, owner, repo) => { * BACKWARD COMPATIBILITY: Fallback to the search API if the issue was not found in the GraphQL response. * This fallback will be removed in a future release */ - try { - const { - data: { items: backwardIssues }, - } = await octokit.request("GET /search/issues", { - q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`, - }); - issues.push(...backwardIssues); - } catch (error) { - logger.log( - "An error occured fetching issue via fallback (with GH SearchAPI)", - ); + if (issueNodes.length === 0) { + try { + const { + data: { items: backwardIssues }, + } = await octokit.request("GET /search/issues", { + q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`, + }); + issues.push(...backwardIssues); + } catch (error) { + logger.log( + "An error occured fetching issue via fallback (with GH SearchAPI)", + ); + } } const uniqueSRIssues = uniqBy( From 2ce3efecf7104011e4780648e2fcd24b71d740a6 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 11 Sep 2024 20:02:22 +0100 Subject: [PATCH 27/29] modified `RELEASE_FAIL_LABEL` value to `semantic-release` --- lib/definitions/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/definitions/constants.js b/lib/definitions/constants.js index 15e78a89..c0400947 100644 --- a/lib/definitions/constants.js +++ b/lib/definitions/constants.js @@ -2,4 +2,4 @@ export const ISSUE_ID = ""; export const RELEASE_NAME = "GitHub release"; -export const RELEASE_FAIL_LABEL = "release-failing"; +export const RELEASE_FAIL_LABEL = "semantic-release"; From b5957431778f598b0a77b9adca5797755db346c2 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 11 Sep 2024 20:12:11 +0100 Subject: [PATCH 28/29] test: fix cases for conditional `searchAPI` fallback consumption --- test/fail.test.js | 16 ---------------- test/find-sr-issue.test.js | 39 ++++---------------------------------- test/success.test.js | 16 ---------------- 3 files changed, 4 insertions(+), 67 deletions(-) diff --git a/test/fail.test.js b/test/fail.test.js index b95e3c76..37ceb6bd 100644 --- a/test/fail.test.js +++ b/test/fail.test.js @@ -370,14 +370,6 @@ test("Update the first existing issue with the list of errors", async (t) => { }, }, }) - .getOnce( - `https://api.github.local/search/issues?q=${encodeURIComponent( - "in:title", - )}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent( - "type:issue", - )}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`, - { items: issues }, - ) .postOnce( (url, { body }) => { t.is( @@ -547,14 +539,6 @@ test('Does not post comments on existing issues when "failCommentCondition" is " }, }, }, - ) - .getOnce( - `https://api.github.local/search/issues?q=${encodeURIComponent( - "in:title", - )}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent( - "type:issue", - )}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`, - { items: issues }, ); await fail( diff --git a/test/find-sr-issue.test.js b/test/find-sr-issue.test.js index 2f8125e8..fc10c2f0 100644 --- a/test/find-sr-issue.test.js +++ b/test/find-sr-issue.test.js @@ -32,15 +32,7 @@ test("Filter out issues without ID", async (t) => { issues: { nodes: issues }, }, }, - }) - .getOnce( - `https://api.github.local/search/issues?q=${encodeURIComponent( - "in:title", - )}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent( - "type:issue", - )}+${encodeURIComponent("state:open")}+${encodeURIComponent(title)}`, - { items: issues }, - ); + }); const srIssues = await findSRIssues( new TestOctokit({ request: { fetch } }), @@ -122,15 +114,7 @@ test("Return empty array if not issues has matching ID", async (t) => { issues: { nodes: issues }, }, }, - }) - .getOnce( - `https://api.github.local/search/issues?q=${encodeURIComponent( - "in:title", - )}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent( - "type:issue", - )}+${encodeURIComponent("state:open")}+${encodeURIComponent(title)}`, - { items: issues }, - ); + }); const srIssues = await findSRIssues( new TestOctokit({ request: { fetch } }), @@ -150,11 +134,8 @@ test("Handle error in searchAPI fallback", async (t) => { const repo = "test_repo"; const title = "The automated release is failing 🚨"; const labels = []; - const issues = [ - { number: 1, body: "Issue 1 body", title }, - { number: 2, body: `Issue 2 body\n\n${ISSUE_ID}`, title }, - { number: 3, body: `Issue 3 body\n\n${ISSUE_ID}`, title }, - ]; + const issues = []; + const response = new Response("Not Found", { url: "https://api.github.com/search/issues?q=in%3Atitle+repo%3Aourorg%2Frepo+type%3Aissue+state%3Aopen+The%20automated%20release%20is%20failing%20%F0%9F%9A%A8", status: 403, @@ -220,18 +201,6 @@ test("Handle error in searchAPI fallback", async (t) => { repo, ); - t.deepEqual(srIssues, [ - { - number: 2, - body: "Issue 2 body\n\n", - title, - }, - { - number: 3, - body: "Issue 3 body\n\n", - title, - }, - ]); t.true( t.context.log.calledWith( "An error occured fetching issue via fallback (with GH SearchAPI)", diff --git a/test/success.test.js b/test/success.test.js index b76fedf9..29f0c892 100644 --- a/test/success.test.js +++ b/test/success.test.js @@ -3272,14 +3272,6 @@ test("Close open issues when a release is successful", async (t) => { }, }, ) - .getOnce( - `https://api.github.local/search/issues?q=${encodeURIComponent( - "in:title", - )}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent( - "type:issue", - )}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`, - { items: issues }, - ) .patchOnce( `https://api.github.local/repos/${owner}/${repo}/issues/2`, { html_url: "https://github.com/issues/2" }, @@ -4205,14 +4197,6 @@ test('Does not comment/label "associatedPR" when "successCommentCondition" disab }, }, ) - .getOnce( - `https://api.github.local/search/issues?q=${encodeURIComponent( - "in:title", - )}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent( - "type:issue", - )}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`, - { items: issues }, - ) .patchOnce( `https://api.github.local/repos/${owner}/${repo}/issues/1`, { html_url: "https://github.com/issues/1" }, From 9329cbc0b8577ba2fd68732924cd05eba42d4cf0 Mon Sep 17 00:00:00 2001 From: Olabode Lawal-Shittabey Date: Fri, 20 Sep 2024 18:15:13 +0100 Subject: [PATCH 29/29] Update lib/resolve-config.js --- lib/resolve-config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/resolve-config.js b/lib/resolve-config.js index 5b4fe8e4..578a945e 100644 --- a/lib/resolve-config.js +++ b/lib/resolve-config.js @@ -38,7 +38,6 @@ export default function resolveConfig( : failTitle, failComment, failCommentCondition, - // ATTN??? We opinionated :(??? labels: isNil(labels) ? ["semantic-release"] : labels === false