Skip to content

Commit b3bd2d5

Browse files
authored
Merge pull request #240 from snyk/feat/add-tags-to-report-options
feat(report): add tags support to report options
2 parents 0423539 + 9ba5815 commit b3bd2d5

4 files changed

Lines changed: 95 additions & 0 deletions

File tree

src/http.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ export async function initReport(options: UploadReportOptions): Promise<Result<s
539539
targetName: options.report.targetName,
540540
targetRef: options.report.targetRef,
541541
remoteRepoUrl: options.report.remoteRepoUrl,
542+
tags: options.report.tags,
542543
},
543544
key: {
544545
type: 'file',

src/interfaces/analysis-options.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export interface ReportOptions {
6363
targetName?: string;
6464
targetRef?: string;
6565
remoteRepoUrl?: string;
66+
tags?: Array<{ key: string; value: string }>;
6667
}
6768

6869
export interface ScmReportOptions {

tests/http.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,66 @@ describe('HTTP', () => {
251251

252252
expect(spy).toHaveBeenCalledWith(jsonApiError, 422, 'initReport');
253253
});
254+
255+
it('should include tags in workflowData when provided', async () => {
256+
const makeRequestSpy = jest
257+
.spyOn(needle, 'makeRequest')
258+
.mockResolvedValue({ success: true, body: { reportId: 'test-report-id' } });
259+
260+
const tags = [
261+
{ key: 'env', value: 'prod' },
262+
{ key: 'team', value: 'security' },
263+
];
264+
265+
const optionsWithTags = {
266+
...options,
267+
report: {
268+
enabled: true,
269+
projectName: 'test-project',
270+
tags,
271+
},
272+
};
273+
274+
await initReport(optionsWithTags);
275+
276+
expect(makeRequestSpy).toHaveBeenCalledWith(
277+
expect.objectContaining({
278+
body: expect.objectContaining({
279+
workflowData: expect.objectContaining({
280+
projectName: 'test-project',
281+
tags,
282+
}),
283+
}),
284+
}),
285+
);
286+
});
287+
288+
it('should include undefined tags in workflowData when not provided', async () => {
289+
const makeRequestSpy = jest
290+
.spyOn(needle, 'makeRequest')
291+
.mockResolvedValue({ success: true, body: { reportId: 'test-report-id' } });
292+
293+
const optionsWithoutTags = {
294+
...options,
295+
report: {
296+
enabled: true,
297+
projectName: 'test-project',
298+
},
299+
};
300+
301+
await initReport(optionsWithoutTags);
302+
303+
expect(makeRequestSpy).toHaveBeenCalledWith(
304+
expect.objectContaining({
305+
body: expect.objectContaining({
306+
workflowData: expect.objectContaining({
307+
projectName: 'test-project',
308+
tags: undefined,
309+
}),
310+
}),
311+
}),
312+
);
313+
});
254314
});
255315

256316
describe('getReport', () => {

tests/report.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,39 @@ describe('Functional test for report', () => {
5454
expect(result).toHaveProperty('analysisResult');
5555
});
5656

57+
it('should pass tags through to initReport when provided', async () => {
58+
const tags = [
59+
{ key: 'env', value: 'production' },
60+
{ key: 'team', value: 'platform' },
61+
];
62+
63+
const reportConfig = {
64+
enabled: true,
65+
projectName: 'test-project',
66+
targetName: 'test-target',
67+
targetRef: 'test-ref',
68+
remoteRepoUrl: 'https://github.com/owner/repo',
69+
tags,
70+
};
71+
72+
const result = await reportBundle({
73+
bundleHash: 'dummy-bundle',
74+
...baseConfig,
75+
report: reportConfig,
76+
});
77+
78+
expect(mockInitReport).toHaveBeenCalledWith(
79+
expect.objectContaining({
80+
report: expect.objectContaining({
81+
tags,
82+
}),
83+
}),
84+
);
85+
86+
expect(result).not.toBeNull();
87+
expect(result.status).toBe('COMPLETE');
88+
});
89+
5790
it('should fail report if no project name was given', async () => {
5891
const reportConfig = {
5992
enabled: true,

0 commit comments

Comments
 (0)