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,18 +8,17 @@ export const fetchReports = ({ state, dispatch, commit }) => {
commit(types.REQUEST_REPORTS);
if (!state.basePath) {
dispatch('receiveReportsError');
} else {
Promise.all([axios.get(state.headPath), axios.get(state.basePath)])
.then(results =>
doCodeClimateComparison(
parseCodeclimateMetrics(results[0].data, state.headBlobPath),
parseCodeclimateMetrics(results[1].data, state.baseBlobPath),
),
)
.then(data => dispatch('receiveReportsSuccess', data))
.catch(() => dispatch('receiveReportsError'));
return dispatch('receiveReportsError');
}
return Promise.all([axios.get(state.headPath), axios.get(state.basePath)])
.then(results =>
doCodeClimateComparison(
parseCodeclimateMetrics(results[0].data, state.headBlobPath),
parseCodeclimateMetrics(results[1].data, state.baseBlobPath),
),
)
.then(data => dispatch('receiveReportsSuccess', data))
.catch(() => dispatch('receiveReportsError'));
};
export const receiveReportsSuccess = ({ commit }, data) => {
......
import { LOADING, ERROR, SUCCESS } from '../../constants';
import { sprintf, __, s__, n__ } from '~/locale';
export const hasCodequalityIssues = state => {
return state.newIssues?.length > 0 || state.resolvedIssues?.length > 0;
};
export const hasCodequalityIssues = state =>
Boolean(state.newIssues?.length || state.resolvedIssues?.length);
export const codequalityStatus = state => {
if (state.isLoading) {
......@@ -22,14 +21,14 @@ export const codequalityText = state => {
if (!newIssues.length && !resolvedIssues.length) {
text.push(s__('ciReport|No changes to code quality'));
} else if (newIssues.length || resolvedIssues.length) {
} else {
text.push(s__('ciReport|Code quality'));
if (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'));
}
......
......@@ -7,27 +7,19 @@ export const parseCodeclimateMetrics = (issues = [], path = '') => {
name: issue.description,
};
if (issue.location) {
let parseCodeQualityUrl;
if (issue?.location?.path) {
let parseCodeQualityUrl = `${path}/${issue.location.path}`;
parsedIssue.path = issue.location.path;
if (issue.location.path) {
parseCodeQualityUrl = `${path}/${issue.location.path}`;
parsedIssue.path = issue.location.path;
if (issue.location.lines && issue.location.lines.begin) {
parsedIssue.line = issue.location.lines.begin;
parseCodeQualityUrl += `#L${issue.location.lines.begin}`;
} else if (
issue.location.positions &&
issue.location.positions.begin &&
issue.location.positions.begin.line
) {
parsedIssue.line = issue.location.positions.begin.line;
parseCodeQualityUrl += `#L${issue.location.positions.begin.line}`;
}
parsedIssue.urlPath = parseCodeQualityUrl;
if (issue?.location?.lines?.begin) {
parsedIssue.line = issue.location.lines.begin;
parseCodeQualityUrl += `#L${issue.location.lines.begin}`;
} else if (issue?.location?.positions?.begin?.line) {
parsedIssue.line = issue.location.positions.begin.line;
parseCodeQualityUrl += `#L${issue.location.positions.begin.line}`;
}
parsedIssue.urlPath = parseCodeQualityUrl;
}
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