Skip to content

feat: deprecate github search api consumption #1037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions lib/find-sr-issues.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { uniqBy } from "lodash-es";
import { ISSUE_ID, RELEASE_FAIL_LABEL } from "./definitions/constants.js";

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

const {
Expand All @@ -18,25 +18,6 @@ export default async (octokit, logger, title, labels, 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) {
logger.log(
"An error occured fetching issue via fallback (with GH SearchAPI)",
);
}
}

const uniqueSRIssues = uniqBy(
issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID)),
"number",
Expand All @@ -46,7 +27,7 @@ export default async (octokit, logger, title, labels, owner, repo) => {
};

/**
* GraphQL Query to et the semantic-release issues for a repository.
* GraphQL Query to get the semantic-release issues for a repository.
*/
const loadGetSRIssuesQuery = `#graphql
query getSRIssues($owner: String!, $repo: String!, $filter: IssueFilters) {
Expand Down
9 changes: 1 addition & 8 deletions lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,7 @@ export default async function success(pluginConfig, context, { Octokit }) {
if (failComment === false || failTitle === false) {
logger.log("Skip closing issue.");
} else {
const srIssues = await findSRIssues(
octokit,
logger,
failTitle,
labels,
owner,
repo,
);
const srIssues = await findSRIssues(octokit, logger, labels, owner, repo);

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

Expand Down
42 changes: 0 additions & 42 deletions test/fail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ test("Open a new issue with the list of errors", async (t) => {
},
},
})
.getOnce(
`https://api.github.local/search/issues?q=${encodeURIComponent(
"in:title",
)}+${encodeURIComponent(
`repo:${redirectedOwner}/${redirectedRepo}`,
)}+${encodeURIComponent("type:issue")}+${encodeURIComponent(
"state:open",
)}+${encodeURIComponent(failTitle)}`,
{ items: [] },
)
.postOnce(
(url, { body }) => {
t.is(
Expand Down Expand Up @@ -136,14 +126,6 @@ test("Open a new issue with the list of errors and custom title and comment", as
},
},
})
.getOnce(
`https://api.github.local/search/issues?q=${encodeURIComponent(
"in:title",
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
"type:issue",
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
{ items: [] },
)
.postOnce(
`https://api.github.local/repos/${owner}/${repo}/issues`,
{ html_url: "https://github.com/issues/1", number: 1 },
Expand Down Expand Up @@ -211,14 +193,6 @@ test("Open a new issue with assignees and 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: [] },
)
.postOnce(
(url, { body }) => {
t.is(url, `https://api.github.local/repos/${owner}/${repo}/issues`);
Expand Down Expand Up @@ -291,14 +265,6 @@ test("Open a new issue without labels and 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: [] },
)
.postOnce(
(url, { body }) => {
t.is(url, `https://api.github.local/repos/${owner}/${repo}/issues`);
Expand Down Expand Up @@ -599,14 +565,6 @@ test(`Post new issue if none exists yet, but don't comment on existing issues wh
},
},
)
.getOnce(
`https://api.github.local/search/issues?q=${encodeURIComponent(
"in:title",
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
"type:issue",
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
{ items: [] },
)
.postOnce(
(url, { body }) => {
t.is(url, `https://api.github.local/repos/${owner}/${repo}/issues`);
Expand Down
92 changes: 1 addition & 91 deletions test/find-sr-issue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ test("Return empty array if not issues found", async (t) => {
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", {
Expand All @@ -78,15 +77,7 @@ test("Return empty array if not issues found", async (t) => {
issues: { nodes: [] },
},
},
})
.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 } }),
Expand Down Expand Up @@ -133,84 +124,3 @@ 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 = [];

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.true(
t.context.log.calledWith(
"An error occured fetching issue via fallback (with GH SearchAPI)",
),
);
t.log(t.context.log);
t.true(fetch.done());
});
40 changes: 0 additions & 40 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,6 @@ test("Comment and add labels on PR included in the releases", 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: [] },
);

await t.context.m.success(
Expand Down Expand Up @@ -590,14 +582,6 @@ test("Open a new 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: [] },
)
.postOnce(
(url, { body }) => {
t.is(url, `https://api.github.local/repos/${owner}/${repo}/issues`);
Expand Down Expand Up @@ -751,14 +735,6 @@ test("Verify, release and notify success", async (t) => {
{},
{ body: ["released"] },
)
.getOnce(
`https://api.github.local/search/issues?q=${encodeURIComponent(
"in:title",
)}+${encodeURIComponent(`repo:${owner}/${repo}`)}+${encodeURIComponent(
"type:issue",
)}+${encodeURIComponent("state:open")}+${encodeURIComponent(failTitle)}`,
{ items: [] },
)
.postOnce(
`${uploadOrigin}${uploadUri}?name=${encodeURIComponent("upload.txt")}&`,
{ browser_download_url: assetUrl },
Expand Down Expand Up @@ -938,14 +914,6 @@ test("Verify, update release and notify success", 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: [] },
);

await t.notThrowsAsync(
Expand Down Expand Up @@ -1036,14 +1004,6 @@ test("Verify and notify failure", 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: [] },
)
.postOnce(`https://api.github.local/repos/${owner}/${repo}/issues`, {
html_url: "https://github.com/issues/1",
number: 1,
Expand Down
Loading
Loading