Skip to content

Commit d260bfd

Browse files
authored
feat: remove github search api consumption (#1037)
BREAKING CHANGE: `@semantic-release/github` no longer consumes the GitHub Search API in the plugin Fixes #1022
1 parent 4c77952 commit d260bfd

File tree

6 files changed

+9
-395
lines changed

6 files changed

+9
-395
lines changed

lib/find-sr-issues.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { uniqBy } from "lodash-es";
22
import { ISSUE_ID, RELEASE_FAIL_LABEL } from "./definitions/constants.js";
33

4-
export default async (octokit, logger, title, labels, owner, repo) => {
4+
export default async (octokit, logger, labels, owner, repo) => {
55
let issues = [];
66

77
const {
@@ -18,25 +18,6 @@ export default async (octokit, logger, title, labels, owner, repo) => {
1818

1919
issues.push(...issueNodes);
2020

21-
/**
22-
* BACKWARD COMPATIBILITY: Fallback to the search API if the issue was not found in the GraphQL response.
23-
* This fallback will be removed in a future release
24-
*/
25-
if (issueNodes.length === 0) {
26-
try {
27-
const {
28-
data: { items: backwardIssues },
29-
} = await octokit.request("GET /search/issues", {
30-
q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`,
31-
});
32-
issues.push(...backwardIssues);
33-
} catch (error) {
34-
logger.log(
35-
"An error occured fetching issue via fallback (with GH SearchAPI)",
36-
);
37-
}
38-
}
39-
4021
const uniqueSRIssues = uniqBy(
4122
issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID)),
4223
"number",
@@ -46,7 +27,7 @@ export default async (octokit, logger, title, labels, owner, repo) => {
4627
};
4728

4829
/**
49-
* GraphQL Query to et the semantic-release issues for a repository.
30+
* GraphQL Query to get the semantic-release issues for a repository.
5031
*/
5132
const loadGetSRIssuesQuery = `#graphql
5233
query getSRIssues($owner: String!, $repo: String!, $filter: IssueFilters) {

lib/success.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,7 @@ export default async function success(pluginConfig, context, { Octokit }) {
266266
if (failComment === false || failTitle === false) {
267267
logger.log("Skip closing issue.");
268268
} else {
269-
const srIssues = await findSRIssues(
270-
octokit,
271-
logger,
272-
failTitle,
273-
labels,
274-
owner,
275-
repo,
276-
);
269+
const srIssues = await findSRIssues(octokit, logger, labels, owner, repo);
277270

278271
debug("found semantic-release issues: %O", srIssues);
279272

test/fail.test.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ test("Open a new issue with the list of errors", async (t) => {
4848
},
4949
},
5050
})
51-
.getOnce(
52-
`https://api.github.local/search/issues?q=${encodeURIComponent(
53-
"in:title",
54-
)}+${encodeURIComponent(
55-
`repo:${redirectedOwner}/${redirectedRepo}`,
56-
)}+${encodeURIComponent("type:issue")}+${encodeURIComponent(
57-
"state:open",
58-
)}+${encodeURIComponent(failTitle)}`,
59-
{ items: [] },
60-
)
6151
.postOnce(
6252
(url, { body }) => {
6353
t.is(
@@ -136,14 +126,6 @@ test("Open a new issue with the list of errors and custom title and comment", as
136126
},
137127
},
138128
})
139-
.getOnce(
140-
`https://api.github.local/search/issues?q=${encodeURIComponent(
141-
"in:title",
142-
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
143-
"type:issue",
144-
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
145-
{ items: [] },
146-
)
147129
.postOnce(
148130
`https://api.github.local/repos/${owner}/${repo}/issues`,
149131
{ html_url: "https://github.com/issues/1", number: 1 },
@@ -211,14 +193,6 @@ test("Open a new issue with assignees and the list of errors", async (t) => {
211193
},
212194
},
213195
})
214-
.getOnce(
215-
`https://api.github.local/search/issues?q=${encodeURIComponent(
216-
"in:title",
217-
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
218-
"type:issue",
219-
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
220-
{ items: [] },
221-
)
222196
.postOnce(
223197
(url, { body }) => {
224198
t.is(url, `https://api.github.local/repos/${owner}/${repo}/issues`);
@@ -291,14 +265,6 @@ test("Open a new issue without labels and the list of errors", async (t) => {
291265
},
292266
},
293267
})
294-
.getOnce(
295-
`https://api.github.local/search/issues?q=${encodeURIComponent(
296-
"in:title",
297-
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
298-
"type:issue",
299-
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
300-
{ items: [] },
301-
)
302268
.postOnce(
303269
(url, { body }) => {
304270
t.is(url, `https://api.github.local/repos/${owner}/${repo}/issues`);
@@ -599,14 +565,6 @@ test(`Post new issue if none exists yet, but don't comment on existing issues wh
599565
},
600566
},
601567
)
602-
.getOnce(
603-
`https://api.github.local/search/issues?q=${encodeURIComponent(
604-
"in:title",
605-
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
606-
"type:issue",
607-
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
608-
{ items: [] },
609-
)
610568
.postOnce(
611569
(url, { body }) => {
612570
t.is(url, `https://api.github.local/repos/${owner}/${repo}/issues`);

test/find-sr-issue.test.js

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ test("Return empty array if not issues found", async (t) => {
6969
const repo = "test_repo";
7070
const title = "The automated release is failing 🚨";
7171
const labels = [];
72-
const issues = [];
7372
const fetch = fetchMock
7473
.sandbox()
7574
.postOnce("https://api.github.local/graphql", {
@@ -78,15 +77,7 @@ test("Return empty array if not issues found", async (t) => {
7877
issues: { nodes: [] },
7978
},
8079
},
81-
})
82-
.getOnce(
83-
`https://api.github.local/search/issues?q=${encodeURIComponent(
84-
"in:title",
85-
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
86-
"type:issue",
87-
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(title)}`,
88-
{ items: issues },
89-
);
80+
});
9081

9182
const srIssues = await findSRIssues(
9283
new TestOctokit({ request: { fetch } }),
@@ -133,84 +124,3 @@ test("Return empty array if not issues has matching ID", async (t) => {
133124
t.deepEqual(srIssues, []);
134125
t.true(fetch.done());
135126
});
136-
137-
test("Handle error in searchAPI fallback", async (t) => {
138-
const owner = "test_user";
139-
const repo = "test_repo";
140-
const title = "The automated release is failing 🚨";
141-
const labels = [];
142-
const issues = [];
143-
144-
const response = new Response("Not Found", {
145-
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",
146-
status: 403,
147-
headers: {
148-
"access-control-allow-origin": "*",
149-
"access-control-expose-headers":
150-
"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",
151-
"content-encoding": "gzip",
152-
"content-security-policy": "default-repo 'none'",
153-
"content-type": "application/json; charset=utf-8",
154-
date: "Tue, 28 May 2024 19:49:00 GMT",
155-
"referrer-policy":
156-
"origin-when-cross-origin, strict-origin-when-cross-origin",
157-
server: "GitHub.com",
158-
"strict-transport-security":
159-
"max-age=31536000; includeSubdomains; preload",
160-
"transfer-encoding": "chunked",
161-
vary: "Accept-Encoding, Accept, X-Requested-With",
162-
"x-content-type-options": "nosniff",
163-
"x-frame-options": "deny",
164-
"x-github-api-version-selected": "2022-11-28",
165-
"x-github-media-type": "github.v3; format=json",
166-
"x-github-request-id": "2**0:29*****4:3868737:6*****3:6****52C",
167-
"x-ratelimit-limit": "30",
168-
"x-ratelimit-remaining": "30",
169-
"x-ratelimit-reset": "1716925800",
170-
"x-ratelimit-resource": "search",
171-
"x-ratelimit-used": "1",
172-
"x-xss-protection": "0",
173-
},
174-
data: {
175-
documentation_url:
176-
"https://docs.github.com/free-pro-team@latest/rest/overview/rate-limits-for-the-rest-api#about-secondary-rate-limits",
177-
message:
178-
"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.",
179-
},
180-
});
181-
182-
const fetch = fetchMock
183-
.sandbox()
184-
.postOnce("https://api.github.local/graphql", {
185-
data: {
186-
repository: {
187-
issues: { nodes: issues },
188-
},
189-
},
190-
})
191-
.getOnce(
192-
`https://api.github.local/search/issues?q=${encodeURIComponent(
193-
"in:title",
194-
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
195-
"type:issue",
196-
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(title)}`,
197-
response,
198-
);
199-
200-
const srIssues = await findSRIssues(
201-
new TestOctokit({ request: { fetch } }),
202-
t.context.logger,
203-
title,
204-
labels,
205-
owner,
206-
repo,
207-
);
208-
209-
t.true(
210-
t.context.log.calledWith(
211-
"An error occured fetching issue via fallback (with GH SearchAPI)",
212-
),
213-
);
214-
t.log(t.context.log);
215-
t.true(fetch.done());
216-
});

test/integration.test.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,6 @@ test("Comment and add labels on PR included in the releases", async (t) => {
517517
},
518518
},
519519
},
520-
)
521-
.getOnce(
522-
`https://api.github.local/search/issues?q=${encodeURIComponent(
523-
"in:title",
524-
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
525-
"type:issue",
526-
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
527-
{ items: [] },
528520
);
529521

530522
await t.context.m.success(
@@ -590,14 +582,6 @@ test("Open a new issue with the list of errors", async (t) => {
590582
},
591583
},
592584
})
593-
.getOnce(
594-
`https://api.github.local/search/issues?q=${encodeURIComponent(
595-
"in:title",
596-
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
597-
"type:issue",
598-
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
599-
{ items: [] },
600-
)
601585
.postOnce(
602586
(url, { body }) => {
603587
t.is(url, `https://api.github.local/repos/${owner}/${repo}/issues`);
@@ -751,14 +735,6 @@ test("Verify, release and notify success", async (t) => {
751735
{},
752736
{ body: ["released"] },
753737
)
754-
.getOnce(
755-
`https://api.github.local/search/issues?q=${encodeURIComponent(
756-
"in:title",
757-
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
758-
"type:issue",
759-
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
760-
{ items: [] },
761-
)
762738
.postOnce(
763739
`${uploadOrigin}${uploadUri}?name=${encodeURIComponent("upload.txt")}&`,
764740
{ browser_download_url: assetUrl },
@@ -938,14 +914,6 @@ test("Verify, update release and notify success", async (t) => {
938914
},
939915
},
940916
},
941-
)
942-
.getOnce(
943-
`https://api.github.local/search/issues?q=${encodeURIComponent(
944-
"in:title",
945-
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
946-
"type:issue",
947-
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
948-
{ items: [] },
949917
);
950918

951919
await t.notThrowsAsync(
@@ -1036,14 +1004,6 @@ test("Verify and notify failure", async (t) => {
10361004
},
10371005
},
10381006
})
1039-
.getOnce(
1040-
`https://api.github.local/search/issues?q=${encodeURIComponent(
1041-
"in:title",
1042-
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
1043-
"type:issue",
1044-
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
1045-
{ items: [] },
1046-
)
10471007
.postOnce(`https://api.github.local/repos/${owner}/${repo}/issues`, {
10481008
html_url: "https://github.com/issues/1",
10491009
number: 1,

0 commit comments

Comments
 (0)