Commit f1020edd authored by Mark Florian's avatar Mark Florian

Extract FEEDBACK_TYPE constants

It was [suggested][1] in a previous MR to extract these strings into
constants. Since it turns out these strings appear multiple times, it's
time to implement that suggestion!

[1]: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/47067#note_445054667
parent 41dff601
export const FEEDBACK_TYPE_DISMISSAL = 'dismissal';
export const FEEDBACK_TYPE_ISSUE = 'issue';
export const FEEDBACK_TYPE_MERGE_REQUEST = 'merge_request';
import pollUntilComplete from '~/lib/utils/poll_until_complete';
import axios from '~/lib/utils/axios_utils';
import {
FEEDBACK_TYPE_DISMISSAL,
FEEDBACK_TYPE_ISSUE,
FEEDBACK_TYPE_MERGE_REQUEST,
} from '../constants';
export const fetchDiffData = (state, endpoint, category) => {
const requests = [pollUntilComplete(endpoint)];
......@@ -24,21 +29,21 @@ export const enrichVulnerabilityWithFeedback = (vulnerability, feedback = []) =>
feedback
.filter(fb => fb.project_fingerprint === vulnerability.project_fingerprint)
.reduce((vuln, fb) => {
if (fb.feedback_type === 'dismissal') {
if (fb.feedback_type === FEEDBACK_TYPE_DISMISSAL) {
return {
...vuln,
isDismissed: true,
dismissalFeedback: fb,
};
}
if (fb.feedback_type === 'issue' && fb.issue_iid) {
if (fb.feedback_type === FEEDBACK_TYPE_ISSUE && fb.issue_iid) {
return {
...vuln,
hasIssue: true,
issue_feedback: fb,
};
}
if (fb.feedback_type === 'merge_request' && fb.merge_request_iid) {
if (fb.feedback_type === FEEDBACK_TYPE_MERGE_REQUEST && fb.merge_request_iid) {
return {
...vuln,
hasMergeRequest: true,
......
......@@ -6,6 +6,11 @@ import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
import { s__, n__, sprintf } from '~/locale';
import { deprecatedCreateFlash as createFlash } from '~/flash';
import toast from '~/vue_shared/plugins/global_toast';
import {
FEEDBACK_TYPE_DISMISSAL,
FEEDBACK_TYPE_ISSUE,
FEEDBACK_TYPE_MERGE_REQUEST,
} from '~/vue_shared/security_reports/constants';
import * as types from './mutation_types';
/**
......@@ -83,7 +88,7 @@ export const createIssue = ({ dispatch }, { vulnerability, flashError }) => {
axios
.post(vulnerability.create_vulnerability_feedback_issue_path, {
vulnerability_feedback: {
feedback_type: 'issue',
feedback_type: FEEDBACK_TYPE_ISSUE,
category: vulnerability.report_type,
project_fingerprint: vulnerability.project_fingerprint,
vulnerability_data: {
......@@ -147,7 +152,7 @@ export const dismissSelectedVulnerabilities = ({ dispatch, state }, { comment }
vulnerability_feedback: {
category: vulnerability.report_type,
comment,
feedback_type: 'dismissal',
feedback_type: FEEDBACK_TYPE_DISMISSAL,
project_fingerprint: vulnerability.project_fingerprint,
vulnerability_data: {
id: vulnerability.id,
......@@ -232,7 +237,7 @@ export const dismissVulnerability = (
vulnerability_feedback: {
category: vulnerability.report_type,
comment,
feedback_type: 'dismissal',
feedback_type: FEEDBACK_TYPE_DISMISSAL,
pipeline_id: state.pipelineId,
project_fingerprint: vulnerability.project_fingerprint,
vulnerability_data: {
......@@ -434,7 +439,7 @@ export const createMergeRequest = ({ state, dispatch }, { vulnerability, flashEr
axios
.post(create_vulnerability_feedback_merge_request_path, {
vulnerability_feedback: {
feedback_type: 'merge_request',
feedback_type: FEEDBACK_TYPE_MERGE_REQUEST,
category: report_type,
project_fingerprint,
vulnerability_data: {
......
......@@ -6,6 +6,11 @@ import { s__, sprintf } from '~/locale';
import { visitUrl } from '~/lib/utils/url_utility';
import toast from '~/vue_shared/plugins/global_toast';
import { fetchDiffData } from '~/vue_shared/security_reports/store/utils';
import {
FEEDBACK_TYPE_DISMISSAL,
FEEDBACK_TYPE_ISSUE,
FEEDBACK_TYPE_MERGE_REQUEST,
} from '~/vue_shared/security_reports/constants';
import * as types from './mutation_types';
/**
......@@ -199,7 +204,7 @@ export const dismissVulnerability = ({ state, dispatch }, comment) => {
vulnerability_feedback: {
category: state.modal.vulnerability.category,
comment,
feedback_type: 'dismissal',
feedback_type: FEEDBACK_TYPE_DISMISSAL,
pipeline_id: state.pipelineId,
project_fingerprint: state.modal.vulnerability.project_fingerprint,
vulnerability_data: state.modal.vulnerability,
......@@ -362,7 +367,7 @@ export const createNewIssue = ({ state, dispatch }) => {
axios
.post(state.createVulnerabilityFeedbackIssuePath, {
vulnerability_feedback: {
feedback_type: 'issue',
feedback_type: FEEDBACK_TYPE_ISSUE,
category: state.modal.vulnerability.category,
project_fingerprint: state.modal.vulnerability.project_fingerprint,
pipeline_id: state.pipelineId,
......@@ -393,7 +398,7 @@ export const createMergeRequest = ({ state, dispatch }) => {
axios
.post(state.createVulnerabilityFeedbackMergeRequestPath, {
vulnerability_feedback: {
feedback_type: 'merge_request',
feedback_type: FEEDBACK_TYPE_MERGE_REQUEST,
category,
project_fingerprint,
vulnerability_data: vulnerability,
......
import { s__ } from '~/locale';
import {
FEEDBACK_TYPE_ISSUE,
FEEDBACK_TYPE_MERGE_REQUEST,
} from '~/vue_shared/security_reports/constants';
export const VULNERABILITY_STATE_OBJECTS = {
detected: {
......@@ -49,8 +53,8 @@ export const HEADER_ACTION_BUTTONS = {
};
export const FEEDBACK_TYPES = {
ISSUE: 'issue',
MERGE_REQUEST: 'merge_request',
ISSUE: FEEDBACK_TYPE_ISSUE,
MERGE_REQUEST: FEEDBACK_TYPE_MERGE_REQUEST,
};
export const RELATED_ISSUES_ERRORS = {
......
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