From 8d3e80692cbeea06dd28a052554f0c262004e18d Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 16 Nov 2017 19:44:14 +0100 Subject: [PATCH] Add information about project --- doc/api/runners.md | 9 +++++++++ lib/api/entities.rb | 17 +++++++++++++---- lib/api/runners.rb | 6 ++++-- spec/requests/api/runners_spec.rb | 8 ++++---- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/doc/api/runners.md b/doc/api/runners.md index 171857ef49e..f9a9e2bee5a 100644 --- a/doc/api/runners.md +++ b/doc/api/runners.md @@ -261,6 +261,15 @@ Example response: "sha": "97de212e80737a608d939f648d959671fb0a0142", "ref": "master", "status": "pending" + }, + "project": { + "id": 1, + "description": null, + "name": "project1", + "name_with_namespace": "John Doe2 / project1", + "path": "project1", + "path_with_namespace": "namespace1/project1", + "created_at": "2017-11-16T18:38:46.620Z" } } ] diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 7d5d68c8f14..cea9e9a8028 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -80,16 +80,21 @@ module API expose :group_access, as: :group_access_level end - class BasicProjectDetails < Grape::Entity - expose :id, :description, :default_branch, :tag_list - expose :ssh_url_to_repo, :http_url_to_repo, :web_url + class ProjectIdentity < Grape::Entity + expose :id, :description expose :name, :name_with_namespace expose :path, :path_with_namespace + expose :created_at + end + + class BasicProjectDetails < ProjectIdentity + expose :default_branch, :tag_list + expose :ssh_url_to_repo, :http_url_to_repo, :web_url expose :avatar_url do |project, options| project.avatar_url(only_path: false) end expose :star_count, :forks_count - expose :created_at, :last_activity_at + expose :last_activity_at end class Project < BasicProjectDetails @@ -838,6 +843,10 @@ module API expose :pipeline, with: PipelineBasic end + class JobWithProject < Job + expose :project, with: ProjectIdentity + end + class Trigger < Grape::Entity expose :id expose :token, :description diff --git a/lib/api/runners.rb b/lib/api/runners.rb index 56b70681852..b92a2c36cf3 100644 --- a/lib/api/runners.rb +++ b/lib/api/runners.rb @@ -85,7 +85,9 @@ module API destroy_conditionally!(runner) end - desc 'List jobs running on a runner' + desc 'List jobs running on a runner' do + success Entities::JobWithProject + end params do requires :id, type: Integer, desc: 'The ID of the runner' use :pagination @@ -94,7 +96,7 @@ module API runner = get_runner(params[:id]) authenticate_list_runners_jobs!(runner) - present paginate(runner.builds.running), with: Entities::Job + present paginate(runner.builds.running), with: Entities::JobWithProject end end diff --git a/spec/requests/api/runners_spec.rb b/spec/requests/api/runners_spec.rb index 95e5dd91c12..d68fa13af1e 100644 --- a/spec/requests/api/runners_spec.rb +++ b/spec/requests/api/runners_spec.rb @@ -356,10 +356,10 @@ describe API::Runners do describe 'GET /runners/:id/jobs' do let!(:job_1) { create(:ci_build) } - let!(:job_2) { create(:ci_build, :running, runner: shared_runner) } - let!(:job_3) { create(:ci_build, :failed, runner: shared_runner) } - let!(:job_4) { create(:ci_build, :running, runner: specific_runner) } - let!(:job_5) { create(:ci_build, :failed, runner: specific_runner) } + let!(:job_2) { create(:ci_build, :running, runner: shared_runner, project: project) } + let!(:job_3) { create(:ci_build, :failed, runner: shared_runner, project: project) } + let!(:job_4) { create(:ci_build, :running, runner: specific_runner, project: project) } + let!(:job_5) { create(:ci_build, :failed, runner: specific_runner, project: project) } context 'admin user' do context 'when runner exists' do