2015-10-24 18:46:33 +05:30
|
|
|
class Projects::BuildsController < Projects::ApplicationController
|
|
|
|
before_action :build, except: [:index, :cancel_all]
|
2016-08-24 12:49:21 +05:30
|
|
|
before_action :authorize_read_build!, except: [:cancel, :cancel_all, :retry, :play]
|
2016-06-02 11:05:42 +05:30
|
|
|
before_action :authorize_update_build!, except: [:index, :show, :status, :raw]
|
2016-04-02 18:10:28 +05:30
|
|
|
layout 'project'
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
def index
|
|
|
|
@scope = params[:scope]
|
2016-09-13 17:45:13 +05:30
|
|
|
@all_builds = project.builds.relevant
|
2015-11-26 14:37:03 +05:30
|
|
|
@builds = @all_builds.order('created_at DESC')
|
2015-10-24 18:46:33 +05:30
|
|
|
@builds =
|
|
|
|
case @scope
|
2016-08-24 12:49:21 +05:30
|
|
|
when 'pending'
|
|
|
|
@builds.pending.reverse_order
|
2016-01-14 18:37:52 +05:30
|
|
|
when 'running'
|
2016-08-24 12:49:21 +05:30
|
|
|
@builds.running.reverse_order
|
2015-10-24 18:46:33 +05:30
|
|
|
when 'finished'
|
2015-11-26 14:37:03 +05:30
|
|
|
@builds.finished
|
2015-10-24 18:46:33 +05:30
|
|
|
else
|
2016-01-14 18:37:52 +05:30
|
|
|
@builds
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
@builds = @builds.page(params[:page]).per(30)
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def cancel_all
|
2015-12-23 02:04:40 +05:30
|
|
|
@project.builds.running_or_pending.each(&:cancel)
|
2015-10-24 18:46:33 +05:30
|
|
|
redirect_to namespace_project_builds_path(project.namespace, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2016-06-16 23:09:34 +05:30
|
|
|
@builds = @project.pipelines.find_by_sha(@build.sha).builds.order('id DESC')
|
2015-11-26 14:37:03 +05:30
|
|
|
@builds = @builds.where("id not in (?)", @build.id)
|
2016-06-16 23:09:34 +05:30
|
|
|
@pipeline = @build.pipeline
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
2016-09-29 09:46:39 +05:30
|
|
|
render json: {
|
|
|
|
id: @build.id,
|
|
|
|
status: @build.status,
|
|
|
|
trace_html: @build.trace_html
|
|
|
|
}
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def trace
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2016-06-16 23:09:34 +05:30
|
|
|
render json: @build.trace_with_state(params[:state].presence).merge!(id: @build.id, status: @build.status)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
def retry
|
2016-08-24 12:49:21 +05:30
|
|
|
return render_404 unless @build.retryable?
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
build = Ci::Build.retry(@build, current_user)
|
2015-11-26 14:37:03 +05:30
|
|
|
redirect_to build_path(build)
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
def play
|
|
|
|
return render_404 unless @build.playable?
|
|
|
|
|
|
|
|
build = @build.play(current_user)
|
|
|
|
redirect_to build_path(build)
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def cancel
|
|
|
|
@build.cancel
|
|
|
|
redirect_to build_path(@build)
|
|
|
|
end
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
def status
|
|
|
|
render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha)
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def erase
|
|
|
|
@build.erase(erased_by: current_user)
|
|
|
|
redirect_to namespace_project_build_path(project.namespace, project, @build),
|
2016-09-29 09:46:39 +05:30
|
|
|
notice: "Build has been successfully erased!"
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def raw
|
2016-09-29 09:46:39 +05:30
|
|
|
if @build.has_trace_file?
|
|
|
|
send_file @build.trace_file_path, type: 'text/plain; charset=utf-8', disposition: 'inline'
|
2016-06-02 11:05:42 +05:30
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def build
|
2016-06-16 23:09:34 +05:30
|
|
|
@build ||= project.builds.find_by!(id: params[:id])
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def build_path(build)
|
2015-12-23 02:04:40 +05:30
|
|
|
namespace_project_build_path(build.project.namespace, build.project, build)
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|