fix(api): issue #1124

This commit is contained in:
wanhose 2024-10-06 18:01:03 +02:00
parent 7a5f08cf83
commit 0821d179df
2 changed files with 10 additions and 10 deletions

View File

@ -32,10 +32,10 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done:
const ua = new UAParser(userAgent ?? '').getResult(); const ua = new UAParser(userAgent ?? '').getResult();
const hostname = new URL(url).hostname.split('.').slice(-3).join('.').replace('www.', ''); const hostname = new URL(url).hostname.split('.').slice(-3).join('.').replace('www.', '');
const existingIssues = await octokit.request('GET /search/issues', { 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}`, 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 { try {
if (existingIssue) { if (existingIssue) {

View File

@ -23,17 +23,17 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done:
try { try {
const { hostname } = request.params; const { hostname } = request.params;
const existingIssues = await octokit.request('GET /search/issues', { 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}`, 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 ( if (existingIssue) {
existingIssue &&
(existingIssue.state === 'open' ||
(existingIssue.state === 'closed' &&
existingIssue.labels.some((label) => label.name === 'wontfix')))
) {
reply.send({ reply.send({
data: { data: {
flags: existingIssue.labels.map((label) => label.name), flags: existingIssue.labels.map((label) => label.name),