Skip to content

Commit

Permalink
Merge pull request #32 from snyk-tech-services/fix/createdFormat
Browse files Browse the repository at this point in the history
fix: created date
  • Loading branch information
mathild3r authored May 27, 2021
2 parents 16c1ac4 + c7442dc commit 9b4965f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/lib/generate-date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as debugLib from 'debug';
const debug = debugLib('snyk:generate-data-script');

export function getDate(): string {
let date: string;
const d = new Date();
debug('creating date');
date = d.getFullYear().toString() + '-';
date = date + d.getMonth().toString().padStart(2, '0') + '-';
date = date + d.getDay().toString().padStart(2, '0') + 'T';
date = date + d.getHours().toString().padStart(2, '0') + ':';
date = date + d.getMinutes().toString().padStart(2, '0') + ':';
date = date + d.getSeconds().toString().padStart(2, '0') + 'Z';

debug(date);

return date;
}
3 changes: 2 additions & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SnykIssue, SnykTestOutput, SPDXv3, Profile } from '../types';
import { convertSnykIssueToSpdx } from './convert-issue-to-spdx';
import { generateDocumentNameSpace } from './generate-document-namespace';
export { getInputData } from './get-input-data';
import { getDate } from './generate-date';

export function convertSnykTestOutputToSPDX(data: SnykTestOutput): SPDXv3 {
const outputFileName = data.projectName;
Expand All @@ -15,7 +16,7 @@ export function convertSnykTestOutputToSPDX(data: SnykTestOutput): SPDXv3 {
creator: 'Organization: Snyk Ltd',
documentNamespace: generateDocumentNameSpace(outputFileName),
description: `Snyk test result for project ${data.projectName} in SPDX SBOM format`,
created: Date.now().toString(),
created: getDate(),
vulnerabilities: data.vulnerabilities
.filter((i: SnykIssue) => i.type == undefined)
.map((i: SnykIssue) => convertSnykIssueToSpdx(i)),
Expand Down
3 changes: 2 additions & 1 deletion src/lib/snyk-to-spdx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SnykIssue, SnykTestOutput, SPDXv3, Profile } from '../types';
import { convertSnykIssueToSpdx } from './convert-issue-to-spdx';
import { generateDocumentNameSpace } from './generate-document-namespace';
import { getDate } from './generate-date';

export function convertSnykTestOutputToSPDX(data: SnykTestOutput): SPDXv3 {
const outputFileName = data.projectName;
Expand All @@ -13,7 +14,7 @@ export function convertSnykTestOutputToSPDX(data: SnykTestOutput): SPDXv3 {
creator: 'Organization: Snyk Ltd',
documentNamespace: generateDocumentNameSpace(outputFileName),
description: `Snyk test result for project ${data.projectName} in SPDX SBOM format`,
created: Date.now().toString(), // TODO: Check the format
created: getDate(), // YYYY-MM-DDThh:mm:ssZ
vulnerabilities: data.vulnerabilities.map((i: SnykIssue) =>
convertSnykIssueToSpdx(i),
),
Expand Down

0 comments on commit 9b4965f

Please sign in to comment.