diff options
Diffstat (limited to 'app/assets/javascripts/reports/codequality_report/store')
5 files changed, 26 insertions, 8 deletions
diff --git a/app/assets/javascripts/reports/codequality_report/store/actions.js b/app/assets/javascripts/reports/codequality_report/store/actions.js index e5fb5caca2e..ddd1747899f 100644 --- a/app/assets/javascripts/reports/codequality_report/store/actions.js +++ b/app/assets/javascripts/reports/codequality_report/store/actions.js @@ -4,9 +4,20 @@ import { parseCodeclimateMetrics, doCodeClimateComparison } from './utils/codequ export const setPaths = ({ commit }, paths) => commit(types.SET_PATHS, paths); -export const fetchReports = ({ state, dispatch, commit }) => { +export const fetchReports = ({ state, dispatch, commit }, diffFeatureFlagEnabled) => { commit(types.REQUEST_REPORTS); + if (diffFeatureFlagEnabled) { + return axios + .get(state.reportsPath) + .then(({ data }) => { + return dispatch('receiveReportsSuccess', { + newIssues: parseCodeclimateMetrics(data.new_errors, state.headBlobPath), + resolvedIssues: parseCodeclimateMetrics(data.resolved_errors, state.baseBlobPath), + }); + }) + .catch((error) => dispatch('receiveReportsError', error)); + } if (!state.basePath) { return dispatch('receiveReportsError'); } @@ -18,13 +29,13 @@ export const fetchReports = ({ state, dispatch, commit }) => { ), ) .then((data) => dispatch('receiveReportsSuccess', data)) - .catch(() => dispatch('receiveReportsError')); + .catch((error) => dispatch('receiveReportsError', error)); }; export const receiveReportsSuccess = ({ commit }, data) => { commit(types.RECEIVE_REPORTS_SUCCESS, data); }; -export const receiveReportsError = ({ commit }) => { - commit(types.RECEIVE_REPORTS_ERROR); +export const receiveReportsError = ({ commit }, error) => { + commit(types.RECEIVE_REPORTS_ERROR, error); }; diff --git a/app/assets/javascripts/reports/codequality_report/store/getters.js b/app/assets/javascripts/reports/codequality_report/store/getters.js index e017bab976c..c6935291af2 100644 --- a/app/assets/javascripts/reports/codequality_report/store/getters.js +++ b/app/assets/javascripts/reports/codequality_report/store/getters.js @@ -1,6 +1,6 @@ -import { LOADING, ERROR, SUCCESS } from '../../constants'; -import { sprintf, __, s__, n__ } from '~/locale'; import { spriteIcon } from '~/lib/utils/common_utils'; +import { sprintf, __, s__, n__ } from '~/locale'; +import { LOADING, ERROR, SUCCESS } from '../../constants'; export const hasCodequalityIssues = (state) => Boolean(state.newIssues?.length || state.resolvedIssues?.length); diff --git a/app/assets/javascripts/reports/codequality_report/store/mutations.js b/app/assets/javascripts/reports/codequality_report/store/mutations.js index 7ef4f3ce2db..095e6637966 100644 --- a/app/assets/javascripts/reports/codequality_report/store/mutations.js +++ b/app/assets/javascripts/reports/codequality_report/store/mutations.js @@ -6,6 +6,7 @@ export default { state.headPath = paths.headPath; state.baseBlobPath = paths.baseBlobPath; state.headBlobPath = paths.headBlobPath; + state.reportsPath = paths.reportsPath; state.helpPath = paths.helpPath; }, [types.REQUEST_REPORTS](state) { @@ -13,12 +14,14 @@ export default { }, [types.RECEIVE_REPORTS_SUCCESS](state, data) { state.hasError = false; + state.statusReason = ''; state.isLoading = false; state.newIssues = data.newIssues; state.resolvedIssues = data.resolvedIssues; }, - [types.RECEIVE_REPORTS_ERROR](state) { + [types.RECEIVE_REPORTS_ERROR](state, error) { state.isLoading = false; state.hasError = true; + state.statusReason = error?.response?.data?.status_reason; }, }; diff --git a/app/assets/javascripts/reports/codequality_report/store/state.js b/app/assets/javascripts/reports/codequality_report/store/state.js index 38ab53b432e..b39ff4f9d66 100644 --- a/app/assets/javascripts/reports/codequality_report/store/state.js +++ b/app/assets/javascripts/reports/codequality_report/store/state.js @@ -1,12 +1,14 @@ export default () => ({ basePath: null, headPath: null, + reportsPath: null, baseBlobPath: null, headBlobPath: null, isLoading: false, hasError: false, + statusReason: '', newIssues: [], resolvedIssues: [], diff --git a/app/assets/javascripts/reports/codequality_report/store/utils/codequality_comparison.js b/app/assets/javascripts/reports/codequality_report/store/utils/codequality_comparison.js index fd775f52f7d..b252c8c9817 100644 --- a/app/assets/javascripts/reports/codequality_report/store/utils/codequality_comparison.js +++ b/app/assets/javascripts/reports/codequality_report/store/utils/codequality_comparison.js @@ -3,8 +3,10 @@ import CodeQualityComparisonWorker from '../../workers/codequality_comparison_wo export const parseCodeclimateMetrics = (issues = [], path = '') => { return issues.map((issue) => { const parsedIssue = { - ...issue, name: issue.description, + path: issue.file_path, + urlPath: `${path}/${issue.file_path}#L${issue.line}`, + ...issue, }; if (issue?.location?.path) { |