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 /lib | |
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 'lib')
-rw-r--r-- | lib/api/job_artifacts.rb | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/lib/api/job_artifacts.rb b/lib/api/job_artifacts.rb index a4068a200b3..933bd067e26 100644 --- a/lib/api/job_artifacts.rb +++ b/lib/api/job_artifacts.rb @@ -23,17 +23,14 @@ module API requires :job, type: String, desc: 'The name for the job' end route_setting :authentication, job_token_allowed: true - # rubocop: disable CodeReuse/ActiveRecord get ':id/jobs/artifacts/:ref_name/download', requirements: { ref_name: /.+/ } do authorize_download_artifacts! - builds = user_project.latest_successful_builds_for(params[:ref_name]) - latest_build = builds.find_by!(name: params[:job]) + latest_build = user_project.latest_successful_build_for!(params[:job], params[:ref_name]) present_carrierwave_file!(latest_build.artifacts_file) end - # rubocop: enable CodeReuse/ActiveRecord desc 'Download a specific file from artifacts archive from a ref' do detail 'This feature was introduced in GitLab 11.5' @@ -48,7 +45,7 @@ module API requirements: { ref_name: /.+/ } do authorize_download_artifacts! - build = user_project.latest_successful_build_for(params[:job], params[:ref_name]) + build = user_project.latest_successful_build_for!(params[:job], params[:ref_name]) path = Gitlab::Ci::Build::Artifacts::Path .new(params[:artifact_path]) |