Commit fb95828f authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch 'sk/342695-update-policy-name' into 'master'

Add policy name to ScanExecutionPolicyCommit mutation

See merge request gitlab-org/gitlab!71994
parents 082c064d 35a53cae
......@@ -69,6 +69,7 @@ const createMergeRequest = async ({ projectPath, sourceBranch, targetBranch }) =
*/
const updatePolicy = async ({
action = SECURITY_POLICY_ACTIONS.APPEND,
name,
projectPath,
yamlEditorValue,
}) => {
......@@ -80,6 +81,7 @@ const updatePolicy = async ({
mutation: createScanExecutionPolicy,
variables: {
mode: action,
name,
projectPath,
policyYaml: yamlEditorValue,
},
......@@ -96,6 +98,7 @@ const updatePolicy = async ({
export const modifyPolicy = async ({
action,
assignedPolicyProject,
name,
projectPath,
yamlEditorValue,
}) => {
......@@ -109,6 +112,7 @@ export const modifyPolicy = async ({
const newPolicyCommitBranch = await updatePolicy({
action,
name,
projectPath,
yamlEditorValue,
});
......
......@@ -64,6 +64,11 @@ export default {
yamlEditorValue,
};
},
computed: {
originalName() {
return this.existingPolicy?.name;
},
},
methods: {
handleError(error) {
if (error.message.toLowerCase().includes('graphql')) {
......@@ -86,6 +91,7 @@ export default {
const { mergeRequest, policyProject } = await modifyPolicy({
action,
assignedPolicyProject: this.assignedPolicyProject,
name: this.originalName || fromYaml(this.yamlEditorValue)?.name,
projectPath: this.projectPath,
yamlEditorValue: this.yamlEditorValue,
});
......
mutation updatePolicy(
$projectPath: ID!
$mode: MutationOperationMode = APPEND
$name: String
$policyYaml: String!
) {
scanExecutionPolicyCommit(
input: { projectPath: $projectPath, operationMode: $mode, policyYaml: $policyYaml }
input: { name: $name, projectPath: $projectPath, operationMode: $mode, policyYaml: $policyYaml }
) {
branch
errors
......
......@@ -14,10 +14,12 @@ const newAssignedPolicyProject = {
branch: { rootRef: 'main' },
};
const projectPath = 'path/to/current-project';
const yamlEditorValue = 'some yaml';
const policyName = 'policy-01';
const yamlEditorValue = `\nname: ${policyName}\ndescription: some yaml`;
const createSavePolicyInput = (assignedPolicyProject = defaultAssignedPolicyProject, action) => ({
action,
assignedPolicyProject,
name: policyName,
projectPath,
yamlEditorValue,
});
......
......@@ -3,6 +3,7 @@ import { GlEmptyState } from '@gitlab/ui';
import PolicyEditorLayout from 'ee/threat_monitoring/components/policy_editor/policy_editor_layout.vue';
import {
DEFAULT_SCAN_EXECUTION_POLICY,
fromYaml,
modifyPolicy,
SECURITY_POLICY_ACTIONS,
} from 'ee/threat_monitoring/components/policy_editor/scan_execution_policy/lib';
......@@ -100,6 +101,10 @@ describe('ScanExecutionPolicyEditor', () => {
expect(modifyPolicy).toHaveBeenCalledWith({
action,
assignedPolicyProject: DEFAULT_ASSIGNED_POLICY_PROJECT,
name:
action === SECURITY_POLICY_ACTIONS.APPEND
? fromYaml(yamlEditorValue).name
: mockDastScanExecutionObject.name,
projectPath: defaultProjectPath,
yamlEditorValue,
});
......
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