Skip to content

Commit

Permalink
feat: add util getSeverityFromPriorityGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
UlisesGascon committed Dec 7, 2024
1 parent 55eaac5 commit c28403e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
20 changes: 19 additions & 1 deletion __tests__/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { validateGithubUrl, ensureGithubToken } = require('../src/utils/index')
const { validateGithubUrl, ensureGithubToken, getSeverityFromPriorityGroup } = require('../src/utils/index')

describe('ensureGithubToken', () => {
let originalGithubToken
Expand Down Expand Up @@ -43,3 +43,21 @@ describe('validateGithubUrl', () => {
expect(validateGithubUrl(url)).toBe(false)
})
})

describe('getSeverityFromPriorityGroup', () => {
it('should return the correct severity based on the priority group', () => {
expect(getSeverityFromPriorityGroup('P0')).toBe('critical')
expect(getSeverityFromPriorityGroup('P1')).toBe('critical')
expect(getSeverityFromPriorityGroup('P2')).toBe('critical')
expect(getSeverityFromPriorityGroup('P3')).toBe('high')
expect(getSeverityFromPriorityGroup('P4')).toBe('high')
expect(getSeverityFromPriorityGroup('P5')).toBe('medium')
expect(getSeverityFromPriorityGroup('P6')).toBe('medium')
expect(getSeverityFromPriorityGroup('P7')).toBe('medium')
expect(getSeverityFromPriorityGroup('P8')).toBe('low')
expect(getSeverityFromPriorityGroup('P20')).toBe('low')
// Recommendations always have 'info' severity
expect(getSeverityFromPriorityGroup('R1')).toBe('info')
expect(getSeverityFromPriorityGroup('R11')).toBe('info')
})
})
20 changes: 20 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,28 @@ const logger = {
log: defineLog('log')
}

const getSeverityFromPriorityGroup = (priorityGroup) => {
const priorityType = priorityGroup[0]
const priorityValue = parseInt(priorityGroup.slice(1), 10)
// Recommendations (Rxx)
if (priorityType === 'R') {
return 'info'
}
// Priorities (Pxx)
if (priorityValue >= 0 && priorityValue <= 2) {
return 'critical'
} else if (priorityValue >= 3 && priorityValue <= 4) {
return 'high'
} else if (priorityValue >= 5 && priorityValue <= 7) {
return 'medium'
} else if (priorityValue >= 8) {
return 'low'
}
}

module.exports = {
validateGithubUrl,
ensureGithubToken,
getSeverityFromPriorityGroup,
logger
}

0 comments on commit c28403e

Please sign in to comment.