Skip to content
Snippets Groups Projects
Commit 2916ea82 authored by Sam Rose's avatar Sam Rose Committed by Sam Rose
Browse files

Update pipeline and commit URL and text on CI status change

parent 40a82435
No related branches found
No related tags found
No related merge requests found
Loading
@@ -154,12 +154,22 @@
Loading
@@ -154,12 +154,22 @@
return; return;
} }
if (data.environments && data.environments.length) _this.renderEnvironments(data.environments); if (data.environments && data.environments.length) _this.renderEnvironments(data.environments);
if (data.status !== _this.opts.ci_status && (data.status != null)) { if (data.status !== _this.opts.ci_status ||
data.sha !== _this.opts.ci_sha ||
data.pipeline !== _this.opts.ci_pipeline) {
_this.opts.ci_status = data.status; _this.opts.ci_status = data.status;
_this.showCIStatus(data.status); _this.showCIStatus(data.status);
if (data.coverage) { if (data.coverage) {
_this.showCICoverage(data.coverage); _this.showCICoverage(data.coverage);
} }
if (data.pipeline) {
_this.opts.ci_pipeline = data.pipeline;
_this.updatePipelineUrls(data.pipeline);
}
if (data.sha) {
_this.opts.ci_sha = data.sha;
_this.updateCommitUrls(data.sha);
}
if (showNotification) { if (showNotification) {
status = _this.ciLabelForStatus(data.status); status = _this.ciLabelForStatus(data.status);
if (status === "preparing") { if (status === "preparing") {
Loading
@@ -248,6 +258,16 @@
Loading
@@ -248,6 +258,16 @@
return $('.js-merge-button,.accept-action .dropdown-toggle').removeClass('btn-danger btn-info btn-create').addClass(css_class); return $('.js-merge-button,.accept-action .dropdown-toggle').removeClass('btn-danger btn-info btn-create').addClass(css_class);
}; };
   
MergeRequestWidget.prototype.updatePipelineUrls = function(id) {
const pipelineUrl = this.opts.pipeline_path;
$('.pipeline').text(`#${id}`).attr('href', [pipelineUrl, id].join('/'));
};
MergeRequestWidget.prototype.updateCommitUrls = function(id) {
const commitsUrl = this.opts.commits_path;
$('.js-commit-link').text(`#${id}`).attr('href', [commitsUrl, id].join('/'));
};
return MergeRequestWidget; return MergeRequestWidget;
})(); })();
})(window.gl || (window.gl = {})); })(window.gl || (window.gl = {}));
Loading
@@ -434,7 +434,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
Loading
@@ -434,7 +434,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
title: merge_request.title, title: merge_request.title,
sha: (merge_request.diff_head_commit.short_id if merge_request.diff_head_sha), sha: (merge_request.diff_head_commit.short_id if merge_request.diff_head_sha),
status: status, status: status,
coverage: coverage coverage: coverage,
pipeline: pipeline.try(:id)
} }
   
render json: response render json: response
Loading
Loading
Loading
@@ -10,7 +10,7 @@
Loading
@@ -10,7 +10,7 @@
= ci_label_for_status(status) = ci_label_for_status(status)
for for
= succeed "." do = succeed "." do
= link_to @pipeline.short_sha, namespace_project_commit_path(@merge_request.source_project.namespace, @merge_request.source_project, @pipeline.sha), class: "monospace" = link_to @pipeline.short_sha, namespace_project_commit_path(@merge_request.source_project.namespace, @merge_request.source_project, @pipeline.sha), class: "monospace js-commit-link"
%span.ci-coverage %span.ci-coverage
   
- elsif @merge_request.has_ci? - elsif @merge_request.has_ci?
Loading
Loading
Loading
@@ -24,6 +24,10 @@
Loading
@@ -24,6 +24,10 @@
preparing: "{{status}} build", preparing: "{{status}} build",
normal: "Build {{status}}" normal: "Build {{status}}"
}, },
ci_sha: "#{@merge_request.head_pipeline ? @merge_request.head_pipeline.short_sha : ''}",
ci_pipeline: #{@merge_request.head_pipeline.try(:id).to_json},
commits_path: "#{project_commits_path(@project)}",
pipeline_path: "#{project_pipelines_path(@project)}",
pipelines_path: "#{pipelines_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}" pipelines_path: "#{pipelines_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}"
}; };
   
Loading
Loading
---
title: Update pipeline and commit links when CI status is updated
merge_request: 8351
author:
/* eslint-disable space-before-function-paren, quotes, comma-dangle, dot-notation, quote-props, no-var, max-len */ /* eslint-disable space-before-function-paren, quotes, comma-dangle, dot-notation, quote-props, no-var, max-len */
   
/*= require merge_request_widget */ /*= require merge_request_widget */
/*= require smart_interval */
/*= require lib/utils/datetime_utility */ /*= require lib/utils/datetime_utility */
   
(function() { (function() {
Loading
@@ -21,7 +22,11 @@
Loading
@@ -21,7 +22,11 @@
normal: "Build {{status}}" normal: "Build {{status}}"
}, },
gitlab_icon: "gitlab_logo.png", gitlab_icon: "gitlab_logo.png",
builds_path: "http://sampledomain.local/sampleBuildsPath" ci_pipeline: 80,
ci_sha: "12a34bc5",
builds_path: "http://sampledomain.local/sampleBuildsPath",
commits_path: "http://sampledomain.local/commits",
pipeline_path: "http://sampledomain.local/pipelines"
}; };
this["class"] = new window.gl.MergeRequestWidget(this.opts); this["class"] = new window.gl.MergeRequestWidget(this.opts);
}); });
Loading
@@ -118,10 +123,11 @@
Loading
@@ -118,10 +123,11 @@
}); });
}); });
   
return describe('getCIStatus', function() { describe('getCIStatus', function() {
beforeEach(function() { beforeEach(function() {
this.ciStatusData = { this.ciStatusData = {
"title": "Sample MR title", "title": "Sample MR title",
"pipeline": 80,
"sha": "12a34bc5", "sha": "12a34bc5",
"status": "success", "status": "success",
"coverage": 98 "coverage": 98
Loading
@@ -165,6 +171,22 @@
Loading
@@ -165,6 +171,22 @@
this["class"].getCIStatus(true); this["class"].getCIStatus(true);
return expect(spy).not.toHaveBeenCalled(); return expect(spy).not.toHaveBeenCalled();
}); });
it('should update the pipeline URL when the pipeline changes', function() {
var spy;
spy = spyOn(this["class"], 'updatePipelineUrls').and.stub();
this["class"].getCIStatus(false);
this.ciStatusData.pipeline += 1;
this["class"].getCIStatus(false);
return expect(spy).toHaveBeenCalled();
});
it('should update the commit URL when the sha changes', function() {
var spy;
spy = spyOn(this["class"], 'updateCommitUrls').and.stub();
this["class"].getCIStatus(false);
this.ciStatusData.sha = "9b50b99a";
this["class"].getCIStatus(false);
return expect(spy).toHaveBeenCalled();
});
}); });
}); });
}).call(this); }).call(this);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment