Commit 63718b04 authored by Zamir Martins Filho's avatar Zamir Martins Filho

Add text for all branches

on scan result policy drawer.

EE: true
Changelog: changed
parent 99be341f
...@@ -64,6 +64,27 @@ const humanizeItems = ({ ...@@ -64,6 +64,27 @@ const humanizeItems = ({
return finalSentence.join(''); return finalSentence.join('');
}; };
/**
* Create a human-readable version of the branches
* @param {Array} branches
* @returns {String}
*/
const humanizeBranches = (branches) => {
const hasNoBranch = branches.length === 0;
if (hasNoBranch) {
return s__('SecurityOrchestration|all branches');
}
return sprintf(s__('SecurityOrchestration|the %{branches}'), {
branches: humanizeItems({
items: branches,
singular: s__('SecurityOrchestration|branch'),
plural: s__('SecurityOrchestration|branches'),
}),
});
};
/** /**
* Create a human-readable string, adding the necessary punctuation and conjunctions * Create a human-readable string, adding the necessary punctuation and conjunctions
* @param {Object} action containing or not arrays of string and integers representing approvers * @param {Object} action containing or not arrays of string and integers representing approvers
...@@ -146,7 +167,7 @@ export const humanizeAction = (action) => { ...@@ -146,7 +167,7 @@ export const humanizeAction = (action) => {
const humanizeRule = (rule) => { const humanizeRule = (rule) => {
return sprintf( return sprintf(
s__( s__(
'SecurityOrchestration|The %{scanners} %{severities} in an open merge request targeting the %{branches}.', 'SecurityOrchestration|The %{scanners} %{severities} in an open merge request targeting %{branches}.',
), ),
{ {
scanners: humanizeItems({ scanners: humanizeItems({
...@@ -160,11 +181,7 @@ const humanizeRule = (rule) => { ...@@ -160,11 +181,7 @@ const humanizeRule = (rule) => {
plural: s__('SecurityOrchestration|vulnerabilities'), plural: s__('SecurityOrchestration|vulnerabilities'),
hasArticle: true, hasArticle: true,
}), }),
branches: humanizeItems({ branches: humanizeBranches(rule.branches),
items: rule.branches,
singular: s__('SecurityOrchestration|branch'),
plural: s__('SecurityOrchestration|branches'),
}),
}, },
); );
}; };
......
...@@ -59,6 +59,15 @@ const mockRules = [ ...@@ -59,6 +59,15 @@ const mockRules = [
}, },
]; ];
const mockRulesEmptyBranch = {
type: 'scan_finding',
branches: [],
scanners: ['sast'],
vulnerabilities_allowed: 1,
severity_levels: ['critical'],
vulnerability_states: ['newly_detected'],
};
describe('humanizeRules', () => { describe('humanizeRules', () => {
it('returns the empty rules message in an Array if no rules are specified', () => { it('returns the empty rules message in an Array if no rules are specified', () => {
expect(humanizeRules([])).toStrictEqual([NO_RULE_MESSAGE]); expect(humanizeRules([])).toStrictEqual([NO_RULE_MESSAGE]);
...@@ -76,6 +85,12 @@ describe('humanizeRules', () => { ...@@ -76,6 +85,12 @@ describe('humanizeRules', () => {
'The dast or sast scanners find info or critical vulnerabilities in an open merge request targeting the master or main branches.', 'The dast or sast scanners find info or critical vulnerabilities in an open merge request targeting the master or main branches.',
]); ]);
}); });
it('returns a single rule as a human-readable string for all branches', () => {
expect(humanizeRules([mockRulesEmptyBranch])).toStrictEqual([
'The sast scanner finds a critical vulnerability in an open merge request targeting all branches.',
]);
});
}); });
describe('humanizeAction', () => { describe('humanizeAction', () => {
......
...@@ -31828,7 +31828,7 @@ msgstr "" ...@@ -31828,7 +31828,7 @@ msgstr ""
msgid "SecurityOrchestration|Status" msgid "SecurityOrchestration|Status"
msgstr "" msgstr ""
msgid "SecurityOrchestration|The %{scanners} %{severities} in an open merge request targeting the %{branches}." msgid "SecurityOrchestration|The %{scanners} %{severities} in an open merge request targeting %{branches}."
msgstr "" msgstr ""
msgid "SecurityOrchestration|There was a problem creating the new security policy" msgid "SecurityOrchestration|There was a problem creating the new security policy"
...@@ -31852,6 +31852,9 @@ msgstr "" ...@@ -31852,6 +31852,9 @@ msgstr ""
msgid "SecurityOrchestration|a" msgid "SecurityOrchestration|a"
msgstr "" msgstr ""
msgid "SecurityOrchestration|all branches"
msgstr ""
msgid "SecurityOrchestration|an" msgid "SecurityOrchestration|an"
msgstr "" msgstr ""
...@@ -31879,6 +31882,9 @@ msgstr "" ...@@ -31879,6 +31882,9 @@ msgstr ""
msgid "SecurityOrchestration|scanners find" msgid "SecurityOrchestration|scanners find"
msgstr "" msgstr ""
msgid "SecurityOrchestration|the %{branches}"
msgstr ""
msgid "SecurityOrchestration|user with id" msgid "SecurityOrchestration|user with id"
msgstr "" msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment