summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2017-02-16 01:05:44 +0100
committerTomasz Maczukin <tomasz@maczukin.pl>2017-03-02 17:45:45 +0100
commit3eafffcef0f8932bab4e06b465f9b63327e87942 (patch)
treecdb64b4be94007d4b8d0ce380862f21a027267fa /lib/api
parent3d26a8d0b62f70e02917f7601bc2032fb3aed7e6 (diff)
downloadgitlab-ce-3eafffcef0f8932bab4e06b465f9b63327e87942.tar.gz
Refactor JobRequest response structure
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/entities.rb94
-rw-r--r--lib/api/runner.rb6
2 files changed, 70 insertions, 30 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index cb3b409b8d0..7e07154600a 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -698,42 +698,82 @@ module API
expose :active?, as: :active
end
- class ArtifactFile < Grape::Entity
- expose :filename, :size
- end
+ module JobRequest
+ class JobInfo < Grape::Entity
+ expose :name, :stage
+ expose :project_id, :project_name
+ end
+
+ class GitInfo < Grape::Entity
+ expose :repo_url, :ref, :sha, :before_sha
+ expose :ref_type do |model|
+ if model.tag
+ 'tag'
+ else
+ 'branch'
+ end
+ end
+ end
- class JobCredentials < Grape::Entity
- expose :type, :url, :username, :password
- end
+ class RunnerInfo < Grape::Entity
+ expose :timeout
+ end
- class JobResponse < Grape::Entity
- expose :id, :ref, :tag, :sha, :status
- expose :name, :token, :stage
- expose :project_id
- expose :project_name
- expose :artifacts_file, using: ArtifactFile, if: ->(build, _) { build.artifacts? }
- end
+ class Step < Grape::Entity
+ expose :name, :script, :timeout, :condition, :result
+ end
- class RequestJobResponse < JobResponse
- expose :commands
- expose :repo_url
- expose :before_sha
- expose :allow_git_fetch
- expose :token
- expose :artifacts_expire_at, if: ->(build, _) { build.artifacts? }
+ class Image < Grape::Entity
+ expose :name
+ end
- expose :options do |model|
- model.options
+ class Artifacts < Grape::Entity
+ expose :name, :untracked, :paths, :when, :expire_in
end
- expose :timeout do |model|
- model.timeout
+ class Cache < Grape::Entity
+ expose :key, :untracked, :paths
end
- expose :variables
- expose :depends_on_builds, using: JobResponse
+ class Credentials < Grape::Entity
+ expose :type, :url, :username, :password
+ end
- expose :credentials, using: JobCredentials
+ class ArtifactFile < Grape::Entity
+ expose :filename, :size
+ end
+
+ class Dependency < Grape::Entity
+ expose :id, :name
+ expose :artifacts_file, using: ArtifactFile, if: ->(job, _) { job.artifacts? }
+ end
+
+ class Response < Grape::Entity
+ expose :id
+ expose :token
+ expose :allow_git_fetch
+
+ expose :job_info, using: JobInfo do |model|
+ model
+ end
+
+ expose :git_info, using: GitInfo do |model|
+ model
+ end
+
+ expose :runner_info, using: RunnerInfo do |model|
+ model
+ end
+
+ expose :variables
+ expose :steps, using: Step
+ expose :image, using: Image
+ expose :services, using: Image
+ expose :artifacts, using: Artifacts
+ expose :cache, using: Cache
+ expose :credentials, using: Credentials
+ expose :depends_on_builds, as: :dependencies, using: Dependency
+ end
end
end
end
diff --git a/lib/api/runner.rb b/lib/api/runner.rb
index 2e7b96e5169..8372b794739 100644
--- a/lib/api/runner.rb
+++ b/lib/api/runner.rb
@@ -51,7 +51,7 @@ module API
resource :jobs do
desc 'Request a job' do
- success Entities::RequestJobResponse
+ success Entities::JobRequest::Response
end
params do
requires :token, type: String, desc: %q(Runner's authentication token)
@@ -68,13 +68,13 @@ module API
end
new_update = current_runner.ensure_runner_queue_value
- result = ::Ci::RegisterBuildService.new(current_runner).execute
+ result = ::Ci::RegisterJobService.new(current_runner).execute
if result.valid?
if result.build
Gitlab::Metrics.add_event(:build_found,
project: result.build.project.path_with_namespace)
- present result.build, with: Entities::RequestJobResponse
+ present result.build, with: Entities::JobRequest::Response
else
Gitlab::Metrics.add_event(:build_not_found)
header 'X-GitLab-Last-Update', new_update