mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-05 20:40:16 -08:00
ci: skip undefined labels in discussion triage action (#9175)
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io> Co-authored-by: Itay <itay@itaysk.com>
This commit is contained in:
31
.github/actions/trivy-triage/helpers.js
vendored
31
.github/actions/trivy-triage/helpers.js
vendored
@@ -1,6 +1,11 @@
|
||||
const patterns = {
|
||||
Scanner: /### Scanner\r?\n\r?\n(.+)/,
|
||||
Target: /### Target\r?\n\r?\n(.+)/,
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
detectDiscussionLabels: (discussion, configDiscussionLabels) => {
|
||||
res = [];
|
||||
const res = [];
|
||||
const discussionId = discussion.id;
|
||||
const category = discussion.category.name;
|
||||
const body = discussion.body;
|
||||
@@ -8,15 +13,21 @@ module.exports = {
|
||||
console.log(`skipping discussion with category ${category} and body ${body}`);
|
||||
return [];
|
||||
}
|
||||
const scannerPattern = /### Scanner\n\n(.+)/;
|
||||
const scannerFound = body.match(scannerPattern);
|
||||
if (scannerFound && scannerFound.length > 1) {
|
||||
res.push(configDiscussionLabels[scannerFound[1]]);
|
||||
}
|
||||
const targetPattern = /### Target\n\n(.+)/;
|
||||
const targetFound = body.match(targetPattern);
|
||||
if (targetFound && targetFound.length > 1) {
|
||||
res.push(configDiscussionLabels[targetFound[1]]);
|
||||
|
||||
for (const key in patterns) {
|
||||
const match = body.match(patterns[key]);
|
||||
if (match && match.length > 1 && match[1] !== "None") {
|
||||
const val = configDiscussionLabels[match[1]];
|
||||
if (val === undefined && match[1]) {
|
||||
console.warn(
|
||||
`Value for ${key.toLowerCase()} key "${
|
||||
match[1]
|
||||
}" not found in configDiscussionLabels`
|
||||
);
|
||||
} else {
|
||||
res.push(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
21
.github/actions/trivy-triage/helpers.test.js
vendored
21
.github/actions/trivy-triage/helpers.test.js
vendored
@@ -62,6 +62,17 @@ describe('trivy-triage', async function() {
|
||||
assert(labels.includes('ContainerImageLabel'));
|
||||
assert(labels.includes('VulnerabilityLabel'));
|
||||
});
|
||||
it('detect scanner and target labels on windows', async function() {
|
||||
const discussion = {
|
||||
body: 'hello hello\r\nbla bla.\r\n### Scanner\r\n\r\nVulnerability\r\n### Target\r\n\r\nContainer Image\r\nbye bye.',
|
||||
category: {
|
||||
name: 'Ideas'
|
||||
}
|
||||
};
|
||||
const labels = detectDiscussionLabels(discussion, configDiscussionLabels);
|
||||
assert(labels.includes('ContainerImageLabel'));
|
||||
assert(labels.includes('VulnerabilityLabel'));
|
||||
});
|
||||
it('not detect other labels', async function() {
|
||||
const discussion = {
|
||||
body: 'hello hello\nbla bla.\n### Scanner\n\nVulnerability\n### Target\n\nContainer Image\nbye bye.',
|
||||
@@ -73,6 +84,16 @@ describe('trivy-triage', async function() {
|
||||
assert(!labels.includes('FilesystemLabel'));
|
||||
assert(!labels.includes('MisconfigurationLabel'));
|
||||
});
|
||||
it('ignores unmatched label values from body', async function() {
|
||||
const discussion = {
|
||||
body: '### Target\r\n\r\nNone\r\n\r\n### Scanner\r\n\r\nMisconfiguration',
|
||||
category: {
|
||||
name: 'Ideas'
|
||||
}
|
||||
};
|
||||
const labels = detectDiscussionLabels(discussion, configDiscussionLabels);
|
||||
assert.deepStrictEqual(labels, ['MisconfigurationLabel']);
|
||||
});
|
||||
it('process only relevant categories', async function() {
|
||||
const discussion = {
|
||||
body: 'hello world',
|
||||
|
||||
Reference in New Issue
Block a user