gitlab-org--gitlab-foss/app/controllers/projects/pipelines_controller.rb

168 lines
4.1 KiB
Ruby
Raw Normal View History

2016-04-12 17:57:22 +00:00
class Projects::PipelinesController < Projects::ApplicationController
before_action :pipeline, except: [:index, :new, :create, :charts]
before_action :commit, only: [:show, :builds, :failures]
2016-04-12 14:16:39 +00:00
before_action :authorize_read_pipeline!
before_action :authorize_create_pipeline!, only: [:new, :create]
before_action :authorize_update_pipeline!, only: [:retry, :cancel]
wrap_parameters Ci::Pipeline
2017-05-06 16:45:46 +00:00
POLLING_INTERVAL = 10_000
2016-04-12 14:16:39 +00:00
def index
@scope = params[:scope]
@pipelines = PipelinesFinder
.new(project, scope: @scope)
.execute
.page(params[:page])
.per(30)
2016-08-29 16:02:08 +00:00
@running_count = PipelinesFinder
.new(project, scope: 'running').execute.count
@pending_count = PipelinesFinder
.new(project, scope: 'pending').execute.count
@finished_count = PipelinesFinder
.new(project, scope: 'finished').execute.count
@pipelines_count = PipelinesFinder
.new(project).execute.count
respond_to do |format|
format.html
format.json do
2017-05-06 16:45:46 +00:00
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
2017-04-05 14:35:29 +00:00
render json: {
pipelines: PipelineSerializer
2017-05-09 04:15:34 +00:00
.new(project: @project, current_user: @current_user)
.with_pagination(request, response)
.represent(@pipelines),
count: {
all: @pipelines_count,
running: @running_count,
pending: @pending_count,
finished: @finished_count
}
}
end
end
2016-04-12 14:16:39 +00:00
end
def new
@pipeline = project.pipelines.new(ref: @project.default_branch)
2016-04-12 14:16:39 +00:00
end
def create
@pipeline = Ci::CreatePipelineService
.new(project, current_user, create_params)
2017-05-24 13:13:51 +00:00
.execute(:web, ignore_skip_ci: true, save_on_errors: false)
2017-05-06 16:45:46 +00:00
if @pipeline.persisted?
redirect_to namespace_project_pipeline_path(project.namespace, project, @pipeline)
else
2016-05-09 23:26:13 +00:00
render 'new'
2016-04-12 14:16:39 +00:00
end
end
def show
2017-05-06 16:45:46 +00:00
respond_to do |format|
format.html
format.json do
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
render json: PipelineSerializer
2017-05-09 04:15:34 +00:00
.new(project: @project, current_user: @current_user)
2017-05-06 16:45:46 +00:00
.represent(@pipeline, grouped: true)
end
end
2016-04-12 14:16:39 +00:00
end
2016-11-23 14:44:05 +00:00
def builds
render_show
end
def failures
if @pipeline.statuses.latest.failed.present?
render_show
else
redirect_to pipeline_path(@pipeline)
end
2016-11-23 14:44:05 +00:00
end
def status
render json: PipelineSerializer
2017-05-09 04:15:34 +00:00
.new(project: @project, current_user: @current_user)
2017-03-10 17:44:41 +00:00
.represent_status(@pipeline)
end
def stage
@stage = pipeline.legacy_stage(params[:stage])
return not_found unless @stage
respond_to do |format|
format.json { render json: { html: view_to_html_string('projects/pipelines/_stage') } }
end
end
2016-04-12 14:16:39 +00:00
def retry
pipeline.retry_failed(current_user)
2016-04-12 14:16:39 +00:00
respond_to do |format|
format.html do
redirect_back_or_default default: namespace_project_pipelines_path(project.namespace, project)
end
format.json { head :no_content }
end
2016-04-12 14:16:39 +00:00
end
def cancel
2016-05-09 23:26:13 +00:00
pipeline.cancel_running
2016-04-12 14:16:39 +00:00
respond_to do |format|
format.html do
redirect_back_or_default default: namespace_project_pipelines_path(project.namespace, project)
end
format.json { head :no_content }
end
2016-04-12 14:16:39 +00:00
end
def charts
@charts = {}
@charts[:week] = Ci::Charts::WeekChart.new(project)
@charts[:month] = Ci::Charts::MonthChart.new(project)
@charts[:year] = Ci::Charts::YearChart.new(project)
@charts[:pipeline_times] = Ci::Charts::PipelineTime.new(project)
@counts = {}
@counts[:total] = @project.pipelines.count(:all)
@counts[:success] = @project.pipelines.success.count(:all)
@counts[:failed] = @project.pipelines.failed.count(:all)
end
2016-04-12 14:16:39 +00:00
private
def render_show
respond_to do |format|
format.html do
render 'show'
end
end
end
2016-05-09 23:26:13 +00:00
def create_params
params.require(:pipeline).permit(:ref)
2016-05-09 23:26:13 +00:00
end
2016-04-13 11:01:08 +00:00
def pipeline
@pipeline ||= project.pipelines.find_by!(id: params[:id]).present(current_user: current_user)
2016-04-12 14:16:39 +00:00
end
2016-04-13 15:05:17 +00:00
def commit
@commit ||= @pipeline.commit
2016-04-13 15:05:17 +00:00
end
2016-04-12 14:16:39 +00:00
end