From 8d3b2894184611e9e6f9845481c5122e6c6f4170 Mon Sep 17 00:00:00 2001 From: wanhose Date: Sat, 24 Aug 2024 10:28:51 +0200 Subject: [PATCH] fix(api): existing issues logic --- packages/api/src/routes/v3/report.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/api/src/routes/v3/report.ts b/packages/api/src/routes/v3/report.ts index 1bc12e3..c467037 100644 --- a/packages/api/src/routes/v3/report.ts +++ b/packages/api/src/routes/v3/report.ts @@ -36,18 +36,17 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done: }, }, async (request, reply) => { - const issues = await octokit.request('GET /repos/{owner}/{repo}/issues', { - owner: environment.github.owner, - repo: environment.github.repo, - state: 'all', - }); const ua = new UAParser(request.body.userAgent ?? '').getResult(); const url = new URL(request.body.url).hostname .split('.') .slice(-3) .join('.') .replace('www.', ''); - const existingIssue = issues.data.find((issue) => issue.title.includes(url)); + const existingIssues = await octokit.request('GET /search/issues', { + per_page: 1, + q: `in:title+is:issue+repo:${environment.github.owner}/${environment.github.repo}+${url}`, + }); + const existingIssue = existingIssues.data.items[0]; try { if (existingIssue?.state === 'closed') {