Unify lib/api/job_artifacts.rb with EE
This commit is contained in:
parent
b8aa65d47c
commit
7de317d475
|
@ -2,20 +2,28 @@ module API
|
||||||
class JobArtifacts < Grape::API
|
class JobArtifacts < Grape::API
|
||||||
before { authenticate_non_get! }
|
before { authenticate_non_get! }
|
||||||
|
|
||||||
|
# EE::API::JobArtifacts would override the following helpers
|
||||||
|
helpers do
|
||||||
|
def authorize_download_artifacts!
|
||||||
|
authorize_read_builds!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
params do
|
params do
|
||||||
requires :id, type: String, desc: 'The ID of a project'
|
requires :id, type: String, desc: 'The ID of a project'
|
||||||
end
|
end
|
||||||
resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
|
resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
|
||||||
desc 'Download the artifacts file from a job' do
|
desc 'Download the artifacts archive from a job' do
|
||||||
detail 'This feature was introduced in GitLab 8.10'
|
detail 'This feature was introduced in GitLab 8.10'
|
||||||
end
|
end
|
||||||
params do
|
params do
|
||||||
requires :ref_name, type: String, desc: 'The ref from repository'
|
requires :ref_name, type: String, desc: 'The ref from repository'
|
||||||
requires :job, type: String, desc: 'The name for the job'
|
requires :job, type: String, desc: 'The name for the job'
|
||||||
end
|
end
|
||||||
|
route_setting :authentication, job_token_allowed: true
|
||||||
get ':id/jobs/artifacts/:ref_name/download',
|
get ':id/jobs/artifacts/:ref_name/download',
|
||||||
requirements: { ref_name: /.+/ } do
|
requirements: { ref_name: /.+/ } do
|
||||||
authorize_read_builds!
|
authorize_download_artifacts!
|
||||||
|
|
||||||
builds = user_project.latest_successful_builds_for(params[:ref_name])
|
builds = user_project.latest_successful_builds_for(params[:ref_name])
|
||||||
latest_build = builds.find_by!(name: params[:job])
|
latest_build = builds.find_by!(name: params[:job])
|
||||||
|
@ -23,14 +31,15 @@ module API
|
||||||
present_artifacts!(latest_build.artifacts_file)
|
present_artifacts!(latest_build.artifacts_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Download the artifacts file from a job' do
|
desc 'Download the artifacts archive from a job' do
|
||||||
detail 'This feature was introduced in GitLab 8.5'
|
detail 'This feature was introduced in GitLab 8.5'
|
||||||
end
|
end
|
||||||
params do
|
params do
|
||||||
requires :job_id, type: Integer, desc: 'The ID of a job'
|
requires :job_id, type: Integer, desc: 'The ID of a job'
|
||||||
end
|
end
|
||||||
|
route_setting :authentication, job_token_allowed: true
|
||||||
get ':id/jobs/:job_id/artifacts' do
|
get ':id/jobs/:job_id/artifacts' do
|
||||||
authorize_read_builds!
|
authorize_download_artifacts!
|
||||||
|
|
||||||
build = find_build!(params[:job_id])
|
build = find_build!(params[:job_id])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue