Commit 8e33f946 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Show test coverage results in MR if available

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 71fce0b2
...@@ -40,6 +40,8 @@ class MergeRequest ...@@ -40,6 +40,8 @@ class MergeRequest
if @opts.ci_enable if @opts.ci_enable
$.get @opts.url_to_ci_check, (data) => $.get @opts.url_to_ci_check, (data) =>
this.showCiState data.status this.showCiState data.status
if data.coverage
this.showCiCoverage data.coverage
, 'json' , 'json'
bindEvents: -> bindEvents: ->
...@@ -102,7 +104,11 @@ class MergeRequest ...@@ -102,7 +104,11 @@ class MergeRequest
when "running", "pending" when "running", "pending"
$('.mr-state-widget').addClass("panel-warning") $('.mr-state-widget').addClass("panel-warning")
showCiCoverage: (coverage) ->
cov_html = $('<span>')
cov_html.addClass('ci-coverage')
cov_html.text('Coverage ' + coverage + '%')
$('.ci_widget:visible').append(cov_html)
loadDiff: (event) -> loadDiff: (event) ->
$.ajax $.ajax
......
...@@ -113,6 +113,10 @@ ...@@ -113,6 +113,10 @@
margin-bottom: 0; margin-bottom: 0;
} }
} }
.ci-coverage {
float: right;
}
} }
.merge-request-show-labels .label { .merge-request-show-labels .label {
......
...@@ -150,8 +150,17 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -150,8 +150,17 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def ci_status def ci_status
status = @merge_request.source_project.ci_service.commit_status(merge_request.last_commit.sha) ci_service = @merge_request.source_project.ci_service
response = {status: status} status = ci_service.commit_status(merge_request.last_commit.sha)
if ci_service.respond_to?(:commit_coverage)
coverage = ci_service.commit_coverage(merge_request.last_commit.sha)
end
response = {
status: status,
coverage: coverage
}
render json: response render json: response
end end
......
...@@ -31,8 +31,13 @@ class GitlabCiService < CiService ...@@ -31,8 +31,13 @@ class GitlabCiService < CiService
project_url + "/builds/#{sha}/status.json?token=#{token}" project_url + "/builds/#{sha}/status.json?token=#{token}"
end end
def commit_status sha def get_ci_build(sha)
response = HTTParty.get(commit_status_path(sha), verify: false) @ci_builds ||= {}
@ci_builds[sha] ||= HTTParty.get(commit_status_path(sha), verify: false)
end
def commit_status(sha)
response = get_ci_build(sha)
if response.code == 200 and response["status"] if response.code == 200 and response["status"]
response["status"] response["status"]
...@@ -41,6 +46,14 @@ class GitlabCiService < CiService ...@@ -41,6 +46,14 @@ class GitlabCiService < CiService
end end
end end
def commit_coverage(sha)
response = get_ci_build(sha)
if response.code == 200 and response["coverage"]
response["coverage"]
end
end
def build_page sha def build_page sha
project_url + "/builds/#{sha}" project_url + "/builds/#{sha}"
end end
......
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