-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.ts
More file actions
56 lines (53 loc) · 1.2 KB
/
utils.ts
File metadata and controls
56 lines (53 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* eslint-disable no-console */
import {env} from 'process'
import * as core from '@actions/core'
export enum LogLevel {
Info = 'Info',
Warn = 'Warn',
Error = 'Error'
}
export function log(message: string, level = LogLevel.Info): void {
if (env.GITHUB_ACTIONS === 'true') {
switch (level) {
case LogLevel.Info: {
core.info(message)
break
}
case LogLevel.Warn: {
core.warning(message)
break
}
case LogLevel.Error: {
core.error(message)
break
}
}
} else {
switch (level) {
case LogLevel.Info: {
console.info(message)
break
}
case LogLevel.Warn: {
console.warn(message)
break
}
case LogLevel.Error: {
console.error(message)
break
}
}
}
}
/**
* Normalize a CWE ID by removing leading zeros
* @param cweId - The CWE ID string (e.g., "099", "020", "89")
* @returns The normalized CWE ID string (e.g., "99", "20", "89") or null if invalid
*/
export function normalizeCweId(cweId: string): string | null {
const parsedCweId = parseInt(cweId, 10)
if (Number.isNaN(parsedCweId)) {
return null
}
return String(parsedCweId)
}