Commit ca936d2784773652530e7b02af40b925ca45a4d6
1 parent
c92726e6
Exists in
master
and in
4 other branches
Improve CI integration for merge requests
Showing
10 changed files
with
83 additions
and
12 deletions
Show diff stats
app/assets/javascripts/merge_requests.js
... | ... | @@ -26,6 +26,12 @@ var MergeRequest = { |
26 | 26 | self.showState(data.state); |
27 | 27 | }, "json"); |
28 | 28 | } |
29 | + | |
30 | + if(self.opts.ci_enable){ | |
31 | + $.get(self.opts.url_to_ci_check, function(data){ | |
32 | + self.showCiState(data.status); | |
33 | + }, "json"); | |
34 | + } | |
29 | 35 | }, |
30 | 36 | |
31 | 37 | initTabs: |
... | ... | @@ -79,6 +85,11 @@ var MergeRequest = { |
79 | 85 | $(".automerge_widget." + state).show(); |
80 | 86 | }, |
81 | 87 | |
88 | + showCiState: | |
89 | + function(state){ | |
90 | + $(".ci_widget").hide(); | |
91 | + $(".ci_widget.ci-" + state).show(); | |
92 | + }, | |
82 | 93 | |
83 | 94 | loadDiff: |
84 | 95 | function() { | ... | ... |
app/assets/stylesheets/sections/merge_requests.scss
app/controllers/merge_requests_controller.rb
1 | 1 | class MergeRequestsController < ProjectResourceController |
2 | 2 | before_filter :module_enabled |
3 | - before_filter :merge_request, only: [:edit, :update, :destroy, :show, :commits, :diffs, :automerge, :automerge_check] | |
3 | + before_filter :merge_request, only: [:edit, :update, :destroy, :show, :commits, :diffs, :automerge, :automerge_check, :ci_status] | |
4 | 4 | before_filter :validates_merge_request, only: [:show, :diffs] |
5 | 5 | before_filter :define_show_vars, only: [:show, :diffs] |
6 | 6 | |
... | ... | @@ -103,6 +103,13 @@ class MergeRequestsController < ProjectResourceController |
103 | 103 | @commit = CommitDecorator.decorate(@commit) |
104 | 104 | end |
105 | 105 | |
106 | + def ci_status | |
107 | + status = project.gitlab_ci_service.commit_status(merge_request.last_commit.sha) | |
108 | + response = { status: status } | |
109 | + | |
110 | + render json: response | |
111 | + end | |
112 | + | |
106 | 113 | protected |
107 | 114 | |
108 | 115 | def merge_request | ... | ... |
app/helpers/merge_requests_helper.rb
... | ... | @@ -39,7 +39,7 @@ module MergeRequestsHelper |
39 | 39 | classes |
40 | 40 | end |
41 | 41 | |
42 | - def ci_status_path | |
43 | - @project.gitlab_ci_service.commit_badge_path(@merge_request.last_commit.sha) | |
42 | + def ci_build_details_path merge_request | |
43 | + merge_request.project.gitlab_ci_service.build_page(merge_request.last_commit.sha) | |
44 | 44 | end |
45 | 45 | end | ... | ... |
app/models/gitlab_ci_service.rb
... | ... | @@ -36,4 +36,22 @@ class GitlabCiService < Service |
36 | 36 | def commit_badge_path sha |
37 | 37 | project_url + "/status?sha=#{sha}" |
38 | 38 | end |
39 | + | |
40 | + def commit_status_path sha | |
41 | + project_url + "/builds/#{sha}/status.json?token=#{token}" | |
42 | + end | |
43 | + | |
44 | + def commit_status sha | |
45 | + response = HTTParty.get(commit_status_path(sha)) | |
46 | + | |
47 | + if response.code == 200 and response["status"] | |
48 | + response["status"] | |
49 | + else | |
50 | + :error | |
51 | + end | |
52 | + end | |
53 | + | |
54 | + def build_page sha | |
55 | + project_url + "/builds/#{sha}" | |
56 | + end | |
39 | 57 | end | ... | ... |
app/models/merge_request.rb
... | ... | @@ -220,4 +220,8 @@ class MergeRequest < ActiveRecord::Base |
220 | 220 | def to_patch |
221 | 221 | project.repo.git.format_patch({timeout: 30, raise: true, stdout: true}, "#{target_branch}..#{source_branch}") |
222 | 222 | end |
223 | + | |
224 | + def last_commit_short_sha | |
225 | + @last_commit_short_sha ||= last_commit.sha[0..10] | |
226 | + end | |
223 | 227 | end | ... | ... |
app/views/merge_requests/_show.html.haml
... | ... | @@ -2,6 +2,8 @@ |
2 | 2 | = render "merge_requests/show/how_to_merge" |
3 | 3 | = render "merge_requests/show/mr_box" |
4 | 4 | = render "merge_requests/show/mr_accept" |
5 | +- if @project.gitlab_ci? | |
6 | + = render "merge_requests/show/mr_ci" | |
5 | 7 | = render "merge_requests/show/commits" |
6 | 8 | |
7 | 9 | - if @commits.present? |
... | ... | @@ -28,6 +30,8 @@ |
28 | 30 | MergeRequest.init({ |
29 | 31 | url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}", |
30 | 32 | check_enable: #{@merge_request.state == MergeRequest::UNCHECKED ? "true" : "false"}, |
33 | + url_to_ci_check: "#{ci_status_project_merge_request_path(@project, @merge_request)}", | |
34 | + ci_enable: #{@project.gitlab_ci? ? "true" : "false"}, | |
31 | 35 | current_state: "#{@merge_request.human_state}", |
32 | 36 | action: "#{controller.action_name}" |
33 | 37 | }); | ... | ... |
app/views/merge_requests/show/_mr_box.html.haml
... | ... | @@ -0,0 +1,35 @@ |
1 | +- if @merge_request.open? && @commits.any? | |
2 | + .ci_widget.ci-success{style: "display:none"} | |
3 | + .alert.alert-success | |
4 | + %i.icon-ok | |
5 | + %strong CI build passed | |
6 | + for #{@merge_request.last_commit_short_sha}. | |
7 | + = link_to "Build page", ci_build_details_path(@merge_request) | |
8 | + | |
9 | + | |
10 | + .ci_widget.ci-failed{style: "display:none"} | |
11 | + .alert.alert-error | |
12 | + %i.icon-remove | |
13 | + %strong CI build failed | |
14 | + for #{@merge_request.last_commit_short_sha}. | |
15 | + = link_to "Build page", ci_build_details_path(@merge_request) | |
16 | + | |
17 | + - [:running, :pending].each do |status| | |
18 | + .ci_widget{class: "ci-#{status}", style: "display:none"} | |
19 | + .alert | |
20 | + %i.icon-time | |
21 | + %strong CI build #{status} | |
22 | + for #{@merge_request.last_commit_short_sha}. | |
23 | + = link_to "Build page", ci_build_details_path(@merge_request) | |
24 | + | |
25 | + .ci_widget | |
26 | + .alert-message | |
27 | + %strong | |
28 | + %i.icon-refresh | |
29 | + Checking for CI status for #{@merge_request.last_commit_short_sha} | |
30 | + | |
31 | + .ci_widget.ci-error{style: "display:none"} | |
32 | + .alert.alert-error | |
33 | + %i.icon-remove | |
34 | + %strong Cannot connect to CI server. Please check your setting | |
35 | + | ... | ... |