Commit beecf50f authored by Miranda Fluharty's avatar Miranda Fluharty Committed by Natalia Tepluhina

Display codeclimate error when base_path is null

In the MR codeclimate widget
When the branch's base pipeline has no codeclimate artifact
Show the generic 'Failed to load codeclimate report' error message
parent ee5b6d70
...@@ -44,7 +44,7 @@ export default { ...@@ -44,7 +44,7 @@ export default {
}, },
shouldRenderCodeQuality() { shouldRenderCodeQuality() {
const { codeclimate } = this.mr || {}; const { codeclimate } = this.mr || {};
return codeclimate && codeclimate.head_path && codeclimate.base_path; return codeclimate && codeclimate.head_path;
}, },
shouldRenderLicenseReport() { shouldRenderLicenseReport() {
const { licenseManagement } = this.mr; const { licenseManagement } = this.mr;
...@@ -102,6 +102,23 @@ export default { ...@@ -102,6 +102,23 @@ export default {
return text.join(''); return text.join('');
}, },
codequalityPopover() {
const { codeclimate } = this.mr || {};
if (codeclimate && !codeclimate.base_path) {
return {
title: s__('ciReport|Base pipeline codequality artifact not found'),
content: sprintf(
s__('ciReport|%{linkStartTag}Learn more about codequality reports %{linkEndTag}'),
{
linkStartTag: `<a href="${this.mr.codequalityHelpPath}" target="_blank" rel="noopener noreferrer">`,
linkEndTag: '<i class="fa fa-external-link" aria-hidden="true"></i></a>',
},
false,
),
};
}
return {};
},
performanceText() { performanceText() {
const { improved, degraded } = this.mr.performanceMetrics; const { improved, degraded } = this.mr.performanceMetrics;
...@@ -174,11 +191,20 @@ export default { ...@@ -174,11 +191,20 @@ export default {
}; };
}, },
fetchCodeQuality() { fetchCodeQuality() {
const { head_path, base_path } = this.mr.codeclimate; const { codeclimate } = this.mr || {};
if (!codeclimate.base_path) {
this.isLoadingCodequality = false;
this.loadingCodequalityFailed = true;
return;
}
this.isLoadingCodequality = true; this.isLoadingCodequality = true;
Promise.all([this.service.fetchReport(head_path), this.service.fetchReport(base_path)]) Promise.all([
this.service.fetchReport(codeclimate.head_path),
this.service.fetchReport(codeclimate.base_path),
])
.then(values => .then(values =>
this.mr.compareCodeclimateMetrics( this.mr.compareCodeclimateMetrics(
values[0], values[0],
...@@ -251,6 +277,7 @@ export default { ...@@ -251,6 +277,7 @@ export default {
:resolved-issues="mr.codeclimateMetrics.resolvedIssues" :resolved-issues="mr.codeclimateMetrics.resolvedIssues"
:has-issues="hasCodequalityIssues" :has-issues="hasCodequalityIssues"
:component="$options.componentNames.CodequalityIssueBody" :component="$options.componentNames.CodequalityIssueBody"
:popover-options="codequalityPopover"
class="js-codequality-widget mr-widget-border-top mr-report" class="js-codequality-widget mr-widget-border-top mr-report"
/> />
<report-section <report-section
......
...@@ -21,6 +21,7 @@ export default class MergeRequestStore extends CEMergeRequestStore { ...@@ -21,6 +21,7 @@ export default class MergeRequestStore extends CEMergeRequestStore {
this.vulnerabilityFeedbackPath = data.vulnerability_feedback_path; this.vulnerabilityFeedbackPath = data.vulnerability_feedback_path;
this.vulnerabilityFeedbackHelpPath = data.vulnerability_feedback_help_path; this.vulnerabilityFeedbackHelpPath = data.vulnerability_feedback_help_path;
this.approvalsHelpPath = data.approvals_help_path; this.approvalsHelpPath = data.approvals_help_path;
this.codequalityHelpPath = data.codequality_help_path;
this.securityReportsPipelineId = data.pipeline_id; this.securityReportsPipelineId = data.pipeline_id;
this.createVulnerabilityFeedbackIssuePath = data.create_vulnerability_feedback_issue_path; this.createVulnerabilityFeedbackIssuePath = data.create_vulnerability_feedback_issue_path;
this.createVulnerabilityFeedbackMergeRequestPath = this.createVulnerabilityFeedbackMergeRequestPath =
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
window.gl.mrWidgetData.dependency_scanning_help_path = '#{help_page_path("user/application_security/dependency_scanning/index")}'; window.gl.mrWidgetData.dependency_scanning_help_path = '#{help_page_path("user/application_security/dependency_scanning/index")}';
window.gl.mrWidgetData.vulnerability_feedback_help_path = '#{help_page_path("user/application_security/index")}'; window.gl.mrWidgetData.vulnerability_feedback_help_path = '#{help_page_path("user/application_security/index")}';
window.gl.mrWidgetData.approvals_help_path = '#{help_page_path("user/project/merge_requests/merge_request_approvals")}'; window.gl.mrWidgetData.approvals_help_path = '#{help_page_path("user/project/merge_requests/merge_request_approvals")}';
window.gl.mrWidgetData.codequality_help_path = '#{help_page_path("user/project/merge_requests/code_quality", anchor: "code-quality-reports")}';
window.gl.mrWidgetData.visual_review_app_available = '#{@project.feature_available?(:visual_review_app)}' === 'true'; window.gl.mrWidgetData.visual_review_app_available = '#{@project.feature_available?(:visual_review_app)}' === 'true';
window.gl.mrWidgetData.license_management_comparison_path = '#{license_management_reports_project_merge_request_path(@project, @merge_request) if @project.feature_available?(:license_management)}' window.gl.mrWidgetData.license_management_comparison_path = '#{license_management_reports_project_merge_request_path(@project, @merge_request) if @project.feature_available?(:license_management)}'
window.gl.mrWidgetData.container_scanning_comparison_path = '#{container_scanning_reports_project_merge_request_path(@project, @merge_request) if @project.feature_available?(:container_scanning)}' window.gl.mrWidgetData.container_scanning_comparison_path = '#{container_scanning_reports_project_merge_request_path(@project, @merge_request) if @project.feature_available?(:container_scanning)}'
......
---
title: Display generic error in codeclimate MR widget when base_path is null
merge_request: 21666
author:
type: changed
...@@ -417,6 +417,37 @@ describe('ee merge request widget options', () => { ...@@ -417,6 +417,37 @@ describe('ee merge request widget options', () => {
}); });
}); });
describe('with a head_path but no base_path', () => {
beforeEach(() => {
vm = mountComponent(Component, { mrData: gl.mrWidgetData });
gl.mrWidgetData.codeclimate = {
head_path: 'head.json',
base_path: null,
};
vm.mr.codeclimate = gl.mrWidgetData.codeclimate;
});
it('should render error indicator', done => {
setTimeout(() => {
expect(
removeBreakLine(
vm.$el.querySelector('.js-codequality-widget .js-code-text').textContent,
),
).toContain('Failed to load codeclimate report');
done();
}, 0);
});
it('should render a help icon with more information', done => {
setTimeout(() => {
expect(vm.$el.querySelector('.js-codequality-widget .btn-help')).not.toBeNull();
expect(vm.codequalityPopover.title).toBe('Base pipeline codequality artifact not found');
done();
}, 0);
});
});
describe('with codeclimate comparison worker rejection', () => { describe('with codeclimate comparison worker rejection', () => {
beforeEach(() => { beforeEach(() => {
mock.onGet('head.json').reply(200, headIssues); mock.onGet('head.json').reply(200, headIssues);
......
...@@ -21791,6 +21791,9 @@ msgstr "" ...@@ -21791,6 +21791,9 @@ msgstr ""
msgid "ciReport|%{linkStartTag}Learn more about SAST %{linkEndTag}" msgid "ciReport|%{linkStartTag}Learn more about SAST %{linkEndTag}"
msgstr "" msgstr ""
msgid "ciReport|%{linkStartTag}Learn more about codequality reports %{linkEndTag}"
msgstr ""
msgid "ciReport|%{namespace} is affected by %{vulnerability}." msgid "ciReport|%{namespace} is affected by %{vulnerability}."
msgstr "" msgstr ""
...@@ -21879,6 +21882,9 @@ msgstr "" ...@@ -21879,6 +21882,9 @@ msgstr ""
msgid "ciReport|Automatically apply the patch in a new branch" msgid "ciReport|Automatically apply the patch in a new branch"
msgstr "" msgstr ""
msgid "ciReport|Base pipeline codequality artifact not found"
msgstr ""
msgid "ciReport|Class" msgid "ciReport|Class"
msgstr "" msgstr ""
......
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