Expose runners status information in job api

This commit is contained in:
Steve Azzopardi 2018-09-18 07:42:59 +00:00 committed by Kamil Trzciński
parent 953018e3d4
commit 673764319a
7 changed files with 88 additions and 7 deletions

View file

@ -123,11 +123,6 @@ module CiStatusHelper
render_status_with_link('pipeline', pipeline.status, path, tooltip_placement: tooltip_placement)
end
def no_runners_for_project?(project)
project.runners.blank? &&
Ci::Runner.instance_type.blank?
end
def render_status_with_link(type, status, path = nil, tooltip_placement: 'left', cssclass: '', container: 'body', icon_size: 16)
klass = "ci-status-link ci-status-icon-#{status.dasherize} #{cssclass}"
title = "#{type.titleize}: #{ci_label_for_status(status)}"

View file

@ -79,6 +79,20 @@ class BuildDetailsEntity < JobEntity
expose :trigger_variables, as: :variables, using: TriggerVariableEntity
end
expose :runners do
expose :online do |build|
build.any_runners_online?
end
expose :available do |build|
project.any_runners?
end
expose :settings_path, if: -> (*) { can_admin_build? } do |build|
project_runners_path(project)
end
end
private
def build_failed_issue_options
@ -97,4 +111,8 @@ class BuildDetailsEntity < JobEntity
def can_create_build_terminal?
can?(current_user, :create_build_terminal, build) && build.has_terminal?
end
def can_admin_build?
can?(request.current_user, :admin_build, project)
end
end

View file

@ -10,7 +10,7 @@
- unless @build.any_runners_online?
.bs-callout.bs-callout-warning.js-build-stuck
%p
- if no_runners_for_project?(@build.project)
- if @project.any_runners?
This job is stuck, because the project doesn't have any runners online assigned to it.
- elsif @build.tags.any?
This job is stuck, because you don't have any active runners online with any of these tags assigned to them:

View file

@ -0,0 +1,5 @@
---
title: Expose project runners in job API
merge_request: 21618
author:
type: other

View file

@ -288,6 +288,55 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
end
end
end
context 'when no runners are available' do
let(:runner) { create(:ci_runner, :instance, active: false) }
let(:job) { create(:ci_build, :pending, pipeline: pipeline, runner: runner) }
it 'exposes needed information' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['runners']['online']).to be false
expect(json_response['runners']['available']).to be false
end
end
context 'when no runner is online' do
let(:runner) { create(:ci_runner, :instance) }
let(:job) { create(:ci_build, :pending, pipeline: pipeline, runner: runner) }
it 'exposes needed information' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['runners']['online']).to be false
expect(json_response['runners']['available']).to be true
end
end
context 'settings_path' do
context 'when user is developer' do
it 'settings_path is not available' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['runners']).not_to have_key('settings_path')
end
end
context 'when user is maintainer' do
let(:user) { create(:user, :admin) }
before do
project.add_maintainer(user)
sign_in(user)
end
it 'settings_path is available' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['runners']['settings_path']).to match(/runners/)
end
end
end
end
context 'when requesting JSON job is triggered' do

View file

@ -8,6 +8,7 @@
"terminal_path": { "type": "string" },
"trigger": { "$ref": "trigger.json" },
"deployment_status": { "$ref": "deployment_status.json" },
"runner": { "$ref": "runner.json" }
"runner": { "$ref": "runner.json" },
"runners": { "type": "runners.json" }
}
}

View file

@ -0,0 +1,13 @@
{
"type": "object",
"required": [
"online",
"available"
],
"properties": {
"online": { "type": "boolean" },
"available": { "type": "boolean" },
"settings_path": { "type": "string" }
},
"additionalProperties": false
}