From 034993fbb64c5a68d2004ba11c2f17bb36a9329b Mon Sep 17 00:00:00 2001 From: wanhose Date: Sat, 24 Aug 2024 10:51:26 +0200 Subject: [PATCH] feat(api): add new comment if issue exists with the new details --- packages/api/src/routes/v3/report.ts | 41 ++++++++++++++++++---------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/packages/api/src/routes/v3/report.ts b/packages/api/src/routes/v3/report.ts index c467037..b600ce6 100644 --- a/packages/api/src/routes/v3/report.ts +++ b/packages/api/src/routes/v3/report.ts @@ -58,6 +58,13 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done: state: 'open', }); + await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { + owner: environment.github.owner, + repo: environment.github.repo, + issue_number: existingIssue.number, + body: generateText(request.body, ua), + }); + reply.send({ data: existingIssue.html_url, success: true, @@ -67,21 +74,7 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done: const response = await octokit.request('POST /repos/{owner}/{repo}/issues', { assignees: [environment.github.owner], - body: [ - '## Specifications', - ...(ua.browser.name && ua.browser.version - ? ['#### Browser', `${ua.browser.name} (${ua.browser.version})`] - : []), - ...(ua.device.type && ua.device.vendor - ? ['#### Device', `${ua.device.vendor} (${ua.device.type})`] - : []), - '#### Reason', - request.body.reason ?? '-', - '#### URL', - request.body.url, - '#### Version', - request.body.version, - ].join('\n'), + body: generateText(request.body, ua), labels: ['bug'], owner: environment.github.owner, repo: environment.github.repo, @@ -103,3 +96,21 @@ export default (server: FastifyInstance, _options: RouteShorthandOptions, done: done(); }; + +function generateText(body: PostReportBody, ua: UAParser.IResult): string { + return [ + '## Issue information', + ...(ua.browser.name && ua.browser.version + ? ['#### 🖥️ Browser', `${ua.browser.name} (${ua.browser.version})`] + : []), + ...(ua.device.type && ua.device.vendor + ? ['#### 📱 Device', `${ua.device.vendor} (${ua.device.type})`] + : []), + '#### 📝 Reason', + body.reason ?? '-', + '#### 🔗 URL', + body.url, + '#### 🏷️ Version', + body.version, + ].join('\n'); +}