fix(api): existing issues logic

This commit is contained in:
wanhose 2024-08-24 10:28:51 +02:00
parent 24f0951e60
commit 8d3b289418

View File

@ -36,18 +36,17 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done:
}, },
}, },
async (request, reply) => { 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 ua = new UAParser(request.body.userAgent ?? '').getResult();
const url = new URL(request.body.url).hostname const url = new URL(request.body.url).hostname
.split('.') .split('.')
.slice(-3) .slice(-3)
.join('.') .join('.')
.replace('www.', ''); .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 { try {
if (existingIssue?.state === 'closed') { if (existingIssue?.state === 'closed') {