Skip to content

Commit 54ee6a1

Browse files
committed
Add optional debugContext field
1 parent e7618cd commit 54ee6a1

4 files changed

Lines changed: 31 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ docker run -it -p 3001:3001 \
101101

102102
- `POST /issues` → Create a new GitHub issue
103103
- **Required:** `title`, `contactName`, `contactEmail`, `description`, `environment`, `expectedBehavior`, `actualBehavior`, `reproducibility`
104-
- **Optional:** `attachments[]` (array of URLs)
104+
- **Optional:** `attachments[]` (array of URLs), `debugContext` (URL/context of the page the report was filed from)
105105

106106
### 📣 Complaints
107107

src/controllers/issues.controller.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@ import { maskEmail } from '../utils/maskEmail.js';
99
*/
1010
export async function createIssue(request, reply) {
1111
try {
12-
const { title, contactName, contactEmail, description, environment, expectedBehavior, actualBehavior, reproducibility, attachments, debug } =
13-
request.body;
12+
const {
13+
title,
14+
contactName,
15+
contactEmail,
16+
description,
17+
environment,
18+
debugContext,
19+
expectedBehavior,
20+
actualBehavior,
21+
reproducibility,
22+
attachments,
23+
debug,
24+
} = request.body;
1425

1526
if (debug === true) {
1627
request.log.info('Debug mode: returning fake GitHub issue data');
@@ -44,7 +55,7 @@ export async function createIssue(request, reply) {
4455
}
4556

4657
// Create the body for the GitHub issue
47-
const body = `## Contact Information\n**Contact Name:** ${contactName}\n**Contact Email:** ${maskedEmail}\n\n## Issue Details\n**Description:** \n${description}\n\n**Environment:** ${environment}\n\n**Expected Behavior:** \n${expectedBehavior}\n\n**Actual Behavior:** \n${actualBehavior}\n\n**Reproducibility:** ${reproducibility}\n\n${attachments && attachments.length > 0 ? `## Attachments\n${attachments.map((url) => `- ${url}`).join('\n')}` : ''}\n\n---\n*Issue created via API on ${new Date().toISOString()}*`;
58+
const body = `## Contact Information\n**Contact Name:** ${contactName}\n**Contact Email:** ${maskedEmail}\n\n## Issue Details\n**Description:** \n${description}\n\n**Environment:** ${environment}\n\n**Expected Behavior:** \n${expectedBehavior}\n\n**Actual Behavior:** \n${actualBehavior}\n\n**Reproducibility:** ${reproducibility}\n${debugContext ? `\n\n**Debug Context:** ${debugContext}` : ''}\n\n${attachments && attachments.length > 0 ? `## Attachments\n${attachments.map((url) => `- ${url}`).join('\n')}` : ''}\n\n---\n*Issue created via API on ${new Date().toISOString()}*`;
4859
const labels = ['REPORTED-BY-USER'];
4960
// Create the GitHub issue
5061
const response = await ky.post(`https://api.github.com/repos/${repoOwner}/${repoName}/issues`, {

src/schemas/issues.schema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const createIssueSchema = {
2929
.prop('contactEmail', S.string().format('email').description('Email of the person reporting the issue'))
3030
.prop('description', S.string().minLength(10).maxLength(5000).description('Detailed description of the issue'))
3131
.prop('environment', S.string().minLength(1).maxLength(200).description('Environment where the issue occurred'))
32+
.prop('debugContext', S.string().maxLength(2000).description('Optional debug context URL, e.g. the page the user was on when reporting'))
3233
.prop('expectedBehavior', S.string().minLength(5).maxLength(1000).description('What was expected to happen'))
3334
.prop('actualBehavior', S.string().minLength(5).maxLength(1000).description('What actually happened'))
3435
.prop('reproducibility', S.string().enum(['always', 'sometimes', 'rarely', 'once']).description('How often the issue can be reproduced'))

tests/issues.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,24 @@ describe('createIssue', () => {
9494
expect(options.headers['Content-Type']).to.equal('application/json');
9595
});
9696

97+
it('should include debug context in the GitHub issue body when provided', async () => {
98+
request.body.debugContext = 'https://example.com/some-page';
99+
100+
const mockResponse = createMockGitHubResponse(1, 'Test Issue');
101+
102+
post.resolves(mockResponse);
103+
104+
await createIssue(request, reply);
105+
106+
const [, options] = post.firstCall.args;
107+
108+
expect(options.json.body).to.include('**Debug Context:** https://example.com/some-page');
109+
});
110+
97111
it('should work with missing optional fields', async () => {
98112
request.body.attachments = undefined;
99113
request.body.environment = undefined;
114+
request.body.debugContext = undefined;
100115
request.body.expectedBehavior = undefined;
101116
request.body.actualBehavior = undefined;
102117
request.body.reproducibility = undefined;

0 commit comments

Comments
 (0)