artifacts.rb 957 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
module API
  # Projects artifacts API
  class Artifacts < Grape::API
    before do
      authenticate!
      authorize!(:read_build, user_project)
    end

    resource :projects do
      # Download the artifacts file from ref_name and build_name
      #
      # Parameters:
      #   id (required) - The ID of a project
      #   ref_name (required) - The ref from repository
      #   build_name (required) - The name for the build
      # Example Request:
      #   GET /projects/:id/artifacts/:ref_name/:build_name
      get ':id/artifacts/:ref_name/:build_name',
          requirements: { ref_name: /.+/ } do
        builds = user_project.builds_for(
          params[:build_name], params[:ref_name])

        latest_build = builds.success.latest.first

        if latest_build
          redirect(
            "/projects/#{user_project.id}/builds/#{latest_build.id}/artifacts")
        else
          not_found!
        end
      end
    end
  end
end