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 = ({
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
* @param {Object} action containing or not arrays of string and integers representing approvers
......@@ -146,7 +167,7 @@ export const humanizeAction = (action) => {
const humanizeRule = (rule) => {
return sprintf(
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({
......@@ -160,11 +181,7 @@ const humanizeRule = (rule) => {
plural: s__('SecurityOrchestration|vulnerabilities'),
hasArticle: true,
}),
branches: humanizeItems({
items: rule.branches,
singular: s__('SecurityOrchestration|branch'),
plural: s__('SecurityOrchestration|branches'),
}),
branches: humanizeBranches(rule.branches),
},
);
};
......
......@@ -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', () => {
it('returns the empty rules message in an Array if no rules are specified', () => {
expect(humanizeRules([])).toStrictEqual([NO_RULE_MESSAGE]);
......@@ -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.',
]);
});
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', () => {
......
......@@ -31828,7 +31828,7 @@ msgstr ""
msgid "SecurityOrchestration|Status"
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 ""
msgid "SecurityOrchestration|There was a problem creating the new security policy"
......@@ -31852,6 +31852,9 @@ msgstr ""
msgid "SecurityOrchestration|a"
msgstr ""
msgid "SecurityOrchestration|all branches"
msgstr ""
msgid "SecurityOrchestration|an"
msgstr ""
......@@ -31879,6 +31882,9 @@ msgstr ""
msgid "SecurityOrchestration|scanners find"
msgstr ""
msgid "SecurityOrchestration|the %{branches}"
msgstr ""
msgid "SecurityOrchestration|user with id"
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