Commit 8f3fe6b1 authored by Filipa Lacerda's avatar Filipa Lacerda Committed by Phil Hughes

Makes code quality requests in parallel

parent 9363a476
...@@ -111,20 +111,17 @@ export default { ...@@ -111,20 +111,17 @@ export default {
this.isLoading = true; this.isLoading = true;
Promise.all([
this.service.fetchCodeclimate(head_path) this.service.fetchCodeclimate(head_path)
.then(resp => resp.json()) .then(resp => resp.json()),
.then((data) => {
this.mr.setCodeclimateHeadMetrics(data);
this.service.fetchCodeclimate(base_path) this.service.fetchCodeclimate(base_path)
.then(response => response.json()) .then(resp => resp.json()),
.then(baseData => this.mr.setCodeclimateBaseMetrics(baseData)) ])
.then(() => this.mr.compareCodeclimateMetrics()) .then((values) => {
.then(() => { this.mr.compareCodeclimateMetrics(values[0], values[1]);
this.isLoading = false; this.isLoading = false;
}) })
.catch(() => this.handleError()); .catch(() => this.handleError());
})
.catch(() => this.handleError());
}, },
}; };
</script> </script>
......
...@@ -53,24 +53,12 @@ export default class MergeRequestStore extends CEMergeRequestStore { ...@@ -53,24 +53,12 @@ export default class MergeRequestStore extends CEMergeRequestStore {
initCodeclimate(data) { initCodeclimate(data) {
this.codeclimate = data.codeclimate; this.codeclimate = data.codeclimate;
this.codeclimateMetrics = { this.codeclimateMetrics = {
headIssues: [],
baseIssues: [],
newIssues: [], newIssues: [],
resolvedIssues: [], resolvedIssues: [],
}; };
} }
setCodeclimateHeadMetrics(data) { compareCodeclimateMetrics(headIssues, baseIssues) {
this.codeclimateMetrics.headIssues = data;
}
setCodeclimateBaseMetrics(data) {
this.codeclimateMetrics.baseIssues = data;
}
compareCodeclimateMetrics() {
const { headIssues, baseIssues } = this.codeclimateMetrics;
this.codeclimateMetrics.newIssues = this.filterByFingerprint(headIssues, baseIssues); this.codeclimateMetrics.newIssues = this.filterByFingerprint(headIssues, baseIssues);
this.codeclimateMetrics.resolvedIssues = this.filterByFingerprint(baseIssues, headIssues); this.codeclimateMetrics.resolvedIssues = this.filterByFingerprint(baseIssues, headIssues);
} }
......
...@@ -54,36 +54,9 @@ describe('MergeRequestStore', () => { ...@@ -54,36 +54,9 @@ describe('MergeRequestStore', () => {
}); });
}); });
describe('setCodeclimateHeadMetrics', () => {
it('should set defaults', () => {
expect(store.codeclimate).toEqual(mockData.codeclimate);
expect(store.codeclimateMetrics).toEqual({
headIssues: [],
baseIssues: [],
newIssues: [],
resolvedIssues: [],
});
});
it('should set the provided head metrics', () => {
store.setCodeclimateHeadMetrics(headIssues);
expect(store.codeclimateMetrics.headIssues).toEqual(headIssues);
});
});
describe('setCodeclimateBaseMetrics', () => {
it('should set the provided base metrics', () => {
store.setCodeclimateBaseMetrics(baseIssues);
expect(store.codeclimateMetrics.baseIssues).toEqual(baseIssues);
});
});
describe('compareCodeclimateMetrics', () => { describe('compareCodeclimateMetrics', () => {
beforeEach(() => { beforeEach(() => {
store.setCodeclimateHeadMetrics(headIssues); store.compareCodeclimateMetrics(headIssues, baseIssues);
store.setCodeclimateBaseMetrics(baseIssues);
store.compareCodeclimateMetrics();
}); });
it('should return the new issues', () => { it('should return the new issues', () => {
......
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