2015-10-24 18:46:33 +05:30
|
|
|
class Projects::BuildsController < Projects::ApplicationController
|
|
|
|
before_action :build, except: [:index, :cancel_all]
|
2016-04-02 18:10:28 +05:30
|
|
|
before_action :authorize_read_build!, except: [:cancel, :cancel_all, :retry]
|
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]
|
2015-12-23 02:04:40 +05:30
|
|
|
@all_builds = project.builds
|
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-01-14 18:37:52 +05:30
|
|
|
when 'running'
|
|
|
|
@builds.running_or_pending.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
|
|
|
|
render json: @build.to_json(methods: :trace_html)
|
|
|
|
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
|
2015-11-26 14:37:03 +05:30
|
|
|
unless @build.retryable?
|
2016-01-19 16:12:03 +05:30
|
|
|
return render_404
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
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-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),
|
|
|
|
notice: "Build has been sucessfully erased!"
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def raw
|
|
|
|
if @build.has_trace?
|
|
|
|
send_file @build.path_to_trace, type: 'text/plain; charset=utf-8', disposition: 'inline'
|
|
|
|
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
|