diff --git a/packages/api/src/routes/v3/report.ts b/packages/api/src/routes/v3/report.ts index 14ed8b1..6073ef6 100644 --- a/packages/api/src/routes/v3/report.ts +++ b/packages/api/src/routes/v3/report.ts @@ -32,10 +32,10 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done: const ua = new UAParser(userAgent ?? '').getResult(); const hostname = new URL(url).hostname.split('.').slice(-3).join('.').replace('www.', ''); const existingIssues = await octokit.request('GET /search/issues', { - per_page: 1, + per_page: 50, q: `in:title+is:issue+repo:${environment.github.owner}/${environment.github.repo}+${hostname}`, }); - const existingIssue = existingIssues.data.items[0]; + const existingIssue = existingIssues.data.items.find((issue) => hostname === issue.title); try { if (existingIssue) { diff --git a/packages/api/src/routes/v4/issues.ts b/packages/api/src/routes/v4/issues.ts index 54d937c..2d11f53 100644 --- a/packages/api/src/routes/v4/issues.ts +++ b/packages/api/src/routes/v4/issues.ts @@ -23,17 +23,17 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done: try { const { hostname } = request.params; const existingIssues = await octokit.request('GET /search/issues', { - per_page: 1, + per_page: 50, q: `in:title+is:issue+repo:${environment.github.owner}/${environment.github.repo}+${hostname}`, }); - const existingIssue = existingIssues.data.items[0]; + const existingIssue = existingIssues.data.items.find( + (issue) => + hostname === issue.title && + (issue.state === 'open' || + (issue.state === 'closed' && issue.labels.some((label) => label.name === 'wontfix'))) + ); - if ( - existingIssue && - (existingIssue.state === 'open' || - (existingIssue.state === 'closed' && - existingIssue.labels.some((label) => label.name === 'wontfix'))) - ) { + if (existingIssue) { reply.send({ data: { flags: existingIssue.labels.map((label) => label.name),