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

126 lines
3.2 KiB
Ruby
Raw Normal View History

2016-04-12 13:57:22 -04:00
class Projects::PipelinesController < Projects::ApplicationController
before_action :pipeline, except: [:index, :new, :create, :charts]
before_action :commit, only: [:show, :builds]
2016-04-12 10:16:39 -04:00
before_action :authorize_read_pipeline!
before_action :authorize_create_pipeline!, only: [:new, :create]
before_action :authorize_update_pipeline!, only: [:retry, :cancel]
before_action :builds_enabled, only: :charts
2016-04-12 10:16:39 -04:00
def index
@scope = params[:scope]
@pipelines = PipelinesFinder
.new(project)
.execute(scope: @scope)
.page(params[:page])
.per(30)
2016-08-29 12:02:08 -04:00
@running_count = PipelinesFinder
.new(project).execute(scope: 'running').count
@pending_count = PipelinesFinder
.new(project).execute(scope: 'pending').count
@finished_count = PipelinesFinder
.new(project).execute(scope: 'finished').count
@pipelines_count = PipelinesFinder
.new(project).execute.count
respond_to do |format|
format.html
format.json do
2017-04-05 10:35:29 -04:00
Gitlab::PollingInterval.set_header(response, interval: 10_000)
render json: {
pipelines: PipelineSerializer
.new(project: @project, 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 10:16:39 -04:00
end
def new
@pipeline = project.pipelines.new(ref: @project.default_branch)
2016-04-12 10:16:39 -04:00
end
def create
@pipeline = Ci::CreatePipelineService
.new(project, current_user, create_params)
.execute(ignore_skip_ci: true, save_on_errors: false)
unless @pipeline.persisted?
2016-05-09 19:26:13 -04:00
render 'new'
return
2016-04-12 10:16:39 -04:00
end
redirect_to namespace_project_pipeline_path(project.namespace, project, @pipeline)
2016-04-12 10:16:39 -04:00
end
def show
end
2016-11-23 09:44:05 -05:00
def builds
respond_to do |format|
format.html do
render 'show'
end
end
2016-11-23 09:44:05 -05:00
end
def status
render json: PipelineSerializer
.new(project: @project, user: @current_user)
2017-03-10 12:44:41 -05:00
.represent_status(@pipeline)
end
def stage
2016-12-20 05:00:56 -05:00
@stage = pipeline.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 10:16:39 -04:00
def retry
pipeline.retry_failed(current_user)
2016-04-12 10:16:39 -04:00
redirect_back_or_default default: namespace_project_pipelines_path(project.namespace, project)
end
def cancel
2016-05-09 19:26:13 -04:00
pipeline.cancel_running
2016-04-12 10:16:39 -04:00
redirect_back_or_default default: namespace_project_pipelines_path(project.namespace, project)
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[:build_times] = Ci::Charts::BuildTime.new(project)
end
2016-04-12 10:16:39 -04:00
private
2016-05-09 19:26:13 -04:00
def create_params
params.require(:pipeline).permit(:ref)
2016-05-09 19:26:13 -04:00
end
2016-04-13 07:01:08 -04:00
def pipeline
@pipeline ||= project.pipelines.find_by!(id: params[:id]).present(current_user: current_user)
2016-04-12 10:16:39 -04:00
end
2016-04-13 11:05:17 -04:00
def commit
@commit ||= @pipeline.commit
2016-04-13 11:05:17 -04:00
end
2016-04-12 10:16:39 -04:00
end