Commit 091f27bd authored by mfluharty's avatar mfluharty

Tidy up according to feedback

Return promise in action
Remove unnecessary "> 0"s and conditions
Use optional chaining to shorten parseCodeclimateMetrics
parent 6bddb9d7
...@@ -8,9 +8,9 @@ export const fetchReports = ({ state, dispatch, commit }) => { ...@@ -8,9 +8,9 @@ export const fetchReports = ({ state, dispatch, commit }) => {
commit(types.REQUEST_REPORTS); commit(types.REQUEST_REPORTS);
if (!state.basePath) { if (!state.basePath) {
dispatch('receiveReportsError'); return dispatch('receiveReportsError');
} else { }
Promise.all([axios.get(state.headPath), axios.get(state.basePath)]) return Promise.all([axios.get(state.headPath), axios.get(state.basePath)])
.then(results => .then(results =>
doCodeClimateComparison( doCodeClimateComparison(
parseCodeclimateMetrics(results[0].data, state.headBlobPath), parseCodeclimateMetrics(results[0].data, state.headBlobPath),
...@@ -19,7 +19,6 @@ export const fetchReports = ({ state, dispatch, commit }) => { ...@@ -19,7 +19,6 @@ export const fetchReports = ({ state, dispatch, commit }) => {
) )
.then(data => dispatch('receiveReportsSuccess', data)) .then(data => dispatch('receiveReportsSuccess', data))
.catch(() => dispatch('receiveReportsError')); .catch(() => dispatch('receiveReportsError'));
}
}; };
export const receiveReportsSuccess = ({ commit }, data) => { export const receiveReportsSuccess = ({ commit }, data) => {
......
import { LOADING, ERROR, SUCCESS } from '../../constants'; import { LOADING, ERROR, SUCCESS } from '../../constants';
import { sprintf, __, s__, n__ } from '~/locale'; import { sprintf, __, s__, n__ } from '~/locale';
export const hasCodequalityIssues = state => { export const hasCodequalityIssues = state =>
return state.newIssues?.length > 0 || state.resolvedIssues?.length > 0; Boolean(state.newIssues?.length || state.resolvedIssues?.length);
};
export const codequalityStatus = state => { export const codequalityStatus = state => {
if (state.isLoading) { if (state.isLoading) {
...@@ -22,14 +21,14 @@ export const codequalityText = state => { ...@@ -22,14 +21,14 @@ export const codequalityText = state => {
if (!newIssues.length && !resolvedIssues.length) { if (!newIssues.length && !resolvedIssues.length) {
text.push(s__('ciReport|No changes to code quality')); text.push(s__('ciReport|No changes to code quality'));
} else if (newIssues.length || resolvedIssues.length) { } else {
text.push(s__('ciReport|Code quality')); text.push(s__('ciReport|Code quality'));
if (resolvedIssues.length) { if (resolvedIssues.length) {
text.push(n__(' improved on %d point', ' improved on %d points', resolvedIssues.length)); text.push(n__(' improved on %d point', ' improved on %d points', resolvedIssues.length));
} }
if (newIssues.length > 0 && resolvedIssues.length > 0) { if (newIssues.length && resolvedIssues.length) {
text.push(__(' and')); text.push(__(' and'));
} }
......
...@@ -7,28 +7,20 @@ export const parseCodeclimateMetrics = (issues = [], path = '') => { ...@@ -7,28 +7,20 @@ export const parseCodeclimateMetrics = (issues = [], path = '') => {
name: issue.description, name: issue.description,
}; };
if (issue.location) { if (issue?.location?.path) {
let parseCodeQualityUrl; let parseCodeQualityUrl = `${path}/${issue.location.path}`;
if (issue.location.path) {
parseCodeQualityUrl = `${path}/${issue.location.path}`;
parsedIssue.path = issue.location.path; parsedIssue.path = issue.location.path;
if (issue.location.lines && issue.location.lines.begin) { if (issue?.location?.lines?.begin) {
parsedIssue.line = issue.location.lines.begin; parsedIssue.line = issue.location.lines.begin;
parseCodeQualityUrl += `#L${issue.location.lines.begin}`; parseCodeQualityUrl += `#L${issue.location.lines.begin}`;
} else if ( } else if (issue?.location?.positions?.begin?.line) {
issue.location.positions &&
issue.location.positions.begin &&
issue.location.positions.begin.line
) {
parsedIssue.line = issue.location.positions.begin.line; parsedIssue.line = issue.location.positions.begin.line;
parseCodeQualityUrl += `#L${issue.location.positions.begin.line}`; parseCodeQualityUrl += `#L${issue.location.positions.begin.line}`;
} }
parsedIssue.urlPath = parseCodeQualityUrl; parsedIssue.urlPath = parseCodeQualityUrl;
} }
}
return parsedIssue; return parsedIssue;
}); });
......
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