diff options
author | Steve Azzopardi <steveazz@outlook.com> | 2018-12-06 13:25:25 +0300 |
---|---|---|
committer | Steve Azzopardi <steveazz@outlook.com> | 2019-01-07 19:29:26 +0300 |
commit | 7ac32ae282fa2d35a3651de08f35aad1b85ffca0 (patch) | |
tree | a29770af7276aa89fcea3cdcb0e075046aee1b86 /app/controllers/projects/artifacts_controller.rb | |
parent | f2c7f3d0aa9dfe94fa5e1ab421f86c01350f4cc9 (diff) |
Refactor project.latest_successful_builds_for def
`project.latest_successful_builds_for(ref)` is being used to find a
single job all the time. This results into us having to call `find_by`
inside of the controller which violates our CodeReuse/ActiveRecord
rubocop rule.
Refactor `project.latest_successful_builds_for(ref)` to
`project.latest_successful_build_for(job_name, ref)` which will execute
the `find_by` inside of the model.
Also create `project.latest_successful_build_for!(job_name, ref)` which
raises an exception instead of returning nil.
Diffstat (limited to 'app/controllers/projects/artifacts_controller.rb')
-rw-r--r-- | app/controllers/projects/artifacts_controller.rb | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb index 1a91e07b97f..f4696bcb989 100644 --- a/app/controllers/projects/artifacts_controller.rb +++ b/app/controllers/projects/artifacts_controller.rb @@ -91,14 +91,11 @@ class Projects::ArtifactsController < Projects::ApplicationController end # rubocop: enable CodeReuse/ActiveRecord - # rubocop: disable CodeReuse/ActiveRecord def build_from_ref return unless @ref_name - builds = project.latest_successful_builds_for(@ref_name) - builds.find_by(name: params[:job]) + project.latest_successful_build_for(params[:job], @ref_name) end - # rubocop: enable CodeReuse/ActiveRecord def artifacts_file @artifacts_file ||= build&.artifacts_file_for_type(params[:file_type] || :archive) |