fix(api): return existing issue url when error
This commit is contained in:
parent
3265904128
commit
fb2d476388
@ -35,18 +35,19 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
async (request, reply) => {
|
async (request, reply) => {
|
||||||
try {
|
const issues = await octokit.request('GET /repos/{owner}/{repo}/issues', {
|
||||||
const issues = await octokit.request('GET /repos/{owner}/{repo}/issues', {
|
owner: environment.github.owner,
|
||||||
owner: environment.github.owner,
|
repo: environment.github.repo,
|
||||||
repo: environment.github.repo,
|
});
|
||||||
});
|
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));
|
||||||
|
|
||||||
if (issues.data.some((issue) => issue.title.includes(url))) {
|
try {
|
||||||
|
if (existingIssue) {
|
||||||
throw new Error('Issue already exists');
|
throw new Error('Issue already exists');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +74,7 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done:
|
|||||||
reply.send({
|
reply.send({
|
||||||
errors: [error.message],
|
errors: [error.message],
|
||||||
success: false,
|
success: false,
|
||||||
|
data: existingIssue?.html_url,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user