diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-01-25 14:23:47 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-01-25 14:23:47 +0100 |
commit | 31be74c74b72a1cd33e1630f9462ab5c43f2e319 (patch) | |
tree | 2a592db0bb0a39f98b9745043c37926fe511118e | |
parent | 3234741576ef8b0ad02dd4fcfbd294c41430f8d7 (diff) | |
download | gitlab-ce-31be74c74b72a1cd33e1630f9462ab5c43f2e319.tar.gz |
Return struct instead of multiple values
-rw-r--r-- | app/services/ci/register_build_service.rb | 6 | ||||
-rw-r--r-- | lib/ci/api/builds.rb | 10 | ||||
-rw-r--r-- | spec/services/ci/register_build_service_spec.rb | 2 |
3 files changed, 10 insertions, 8 deletions
diff --git a/app/services/ci/register_build_service.rb b/app/services/ci/register_build_service.rb index ade6042c8f7..6f03bf2be13 100644 --- a/app/services/ci/register_build_service.rb +++ b/app/services/ci/register_build_service.rb @@ -6,6 +6,8 @@ module Ci attr_reader :runner + Result = Struct.new(:build, :valid?) + def initialize(runner) @runner = runner end @@ -29,10 +31,10 @@ module Ci build.run! end - [build, true] + Result.new(build, true) rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError - [nil, false] + Result.new(build, false) end private diff --git a/lib/ci/api/builds.rb b/lib/ci/api/builds.rb index 7d566faf7ed..8b939663ffd 100644 --- a/lib/ci/api/builds.rb +++ b/lib/ci/api/builds.rb @@ -24,14 +24,14 @@ module Ci new_update = current_runner.ensure_runner_queue_value - build, valid = Ci::RegisterBuildService.new(current_runner).execute + result = Ci::RegisterBuildService.new(current_runner).execute - if valid - if build + if result.valid? + if result.build Gitlab::Metrics.add_event(:build_found, - project: build.project.path_with_namespace) + project: result.build.project.path_with_namespace) - present build, with: Entities::BuildDetails + present result.build, with: Entities::BuildDetails else Gitlab::Metrics.add_event(:build_not_found) diff --git a/spec/services/ci/register_build_service_spec.rb b/spec/services/ci/register_build_service_spec.rb index 635ddf70c8d..d9f774a1095 100644 --- a/spec/services/ci/register_build_service_spec.rb +++ b/spec/services/ci/register_build_service_spec.rb @@ -171,7 +171,7 @@ module Ci end def execute(runner) - described_class.new(runner).execute.first + described_class.new(runner).execute.build end end end |