2016-04-12 13:57:22 -04:00
|
|
|
class Projects::PipelinesController < Projects::ApplicationController
|
2017-03-02 12:57:01 -05:00
|
|
|
before_action :pipeline, except: [:index, :new, :create, :charts]
|
2017-04-15 21:33:01 -04:00
|
|
|
before_action :commit, only: [:show, :builds, :failures]
|
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]
|
|
|
|
|
2017-04-24 10:34:53 -04:00
|
|
|
wrap_parameters Ci::Pipeline
|
|
|
|
|
2017-05-06 12:45:46 -04:00
|
|
|
POLLING_INTERVAL = 10_000
|
|
|
|
|
2016-04-12 10:16:39 -04:00
|
|
|
def index
|
|
|
|
@scope = params[:scope]
|
2016-12-15 07:41:46 -05:00
|
|
|
@pipelines = PipelinesFinder
|
2017-02-21 03:20:50 -05:00
|
|
|
.new(project, scope: @scope)
|
|
|
|
.execute
|
2016-12-15 07:41:46 -05:00
|
|
|
.page(params[:page])
|
|
|
|
.per(30)
|
2016-08-29 12:02:08 -04:00
|
|
|
|
2017-02-15 09:06:00 -05:00
|
|
|
@running_count = PipelinesFinder
|
2017-02-21 03:20:50 -05:00
|
|
|
.new(project, scope: 'running').execute.count
|
2016-12-15 07:41:46 -05:00
|
|
|
|
2017-02-15 09:06:00 -05:00
|
|
|
@pending_count = PipelinesFinder
|
2017-02-21 03:20:50 -05:00
|
|
|
.new(project, scope: 'pending').execute.count
|
2017-02-15 09:06:00 -05:00
|
|
|
|
|
|
|
@finished_count = PipelinesFinder
|
2017-02-21 03:20:50 -05:00
|
|
|
.new(project, scope: 'finished').execute.count
|
2017-02-15 09:06:00 -05:00
|
|
|
|
2016-12-15 07:41:46 -05:00
|
|
|
@pipelines_count = PipelinesFinder
|
|
|
|
.new(project).execute.count
|
2016-11-10 09:32:23 -05:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
2017-05-06 12:45:46 -04:00
|
|
|
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
|
2017-04-05 10:35:29 -04:00
|
|
|
|
2016-12-15 07:41:46 -05:00
|
|
|
render json: {
|
|
|
|
pipelines: PipelineSerializer
|
2017-05-09 00:15:34 -04:00
|
|
|
.new(project: @project, current_user: @current_user)
|
2016-12-15 07:41:46 -05:00
|
|
|
.with_pagination(request, response)
|
|
|
|
.represent(@pipelines),
|
|
|
|
count: {
|
|
|
|
all: @pipelines_count,
|
2017-02-15 09:06:00 -05:00
|
|
|
running: @running_count,
|
|
|
|
pending: @pending_count,
|
2017-05-03 07:22:03 -04:00
|
|
|
finished: @finished_count
|
2016-12-15 07:41:46 -05:00
|
|
|
}
|
|
|
|
}
|
2016-11-10 09:32:23 -05:00
|
|
|
end
|
|
|
|
end
|
2016-04-12 10:16:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2016-06-02 10:19:18 -04:00
|
|
|
@pipeline = project.pipelines.new(ref: @project.default_branch)
|
2016-04-12 10:16:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2016-11-07 07:33:04 -05:00
|
|
|
@pipeline = Ci::CreatePipelineService
|
|
|
|
.new(project, current_user, create_params)
|
2017-05-24 09:13:51 -04:00
|
|
|
.execute(:web, ignore_skip_ci: true, save_on_errors: false)
|
2017-05-06 12:45:46 -04:00
|
|
|
|
|
|
|
if @pipeline.persisted?
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_pipeline_path(project, @pipeline)
|
2017-05-06 12:45:46 -04:00
|
|
|
else
|
2016-05-09 19:26:13 -04:00
|
|
|
render 'new'
|
2016-04-12 10:16:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2017-05-06 12:45:46 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
|
|
|
|
|
|
|
|
render json: PipelineSerializer
|
2017-05-09 00:15:34 -04:00
|
|
|
.new(project: @project, current_user: @current_user)
|
2017-05-06 12:45:46 -04:00
|
|
|
.represent(@pipeline, grouped: true)
|
|
|
|
end
|
|
|
|
end
|
2016-04-12 10:16:39 -04:00
|
|
|
end
|
|
|
|
|
2016-11-23 09:44:05 -05:00
|
|
|
def builds
|
2017-04-15 21:33:01 -04:00
|
|
|
render_show
|
|
|
|
end
|
|
|
|
|
|
|
|
def failures
|
2017-05-04 12:50:09 -04:00
|
|
|
if @pipeline.statuses.latest.failed.present?
|
|
|
|
render_show
|
|
|
|
else
|
|
|
|
redirect_to pipeline_path(@pipeline)
|
2016-11-24 06:28:48 -05:00
|
|
|
end
|
2016-11-23 09:44:05 -05:00
|
|
|
end
|
|
|
|
|
2017-03-03 01:59:25 -05:00
|
|
|
def status
|
2017-02-27 14:17:21 -05:00
|
|
|
render json: PipelineSerializer
|
2017-05-09 00:15:34 -04:00
|
|
|
.new(project: @project, current_user: @current_user)
|
2017-03-10 12:44:41 -05:00
|
|
|
.represent_status(@pipeline)
|
2017-02-27 14:17:21 -05:00
|
|
|
end
|
|
|
|
|
2016-12-19 07:20:17 -05:00
|
|
|
def stage
|
2017-06-01 05:55:18 -04:00
|
|
|
@stage = pipeline.legacy_stage(params[:stage])
|
2016-12-19 07:20:17 -05:00
|
|
|
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
|
2016-06-14 07:04:10 -04:00
|
|
|
pipeline.retry_failed(current_user)
|
2016-04-12 10:16:39 -04:00
|
|
|
|
2017-04-10 06:30:06 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_back_or_default default: project_pipelines_path(project)
|
2017-04-10 06:30:06 -04:00
|
|
|
end
|
|
|
|
|
2017-04-12 03:44:16 -04:00
|
|
|
format.json { head :no_content }
|
2017-04-10 06:30:06 -04:00
|
|
|
end
|
2016-04-12 10:16:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def cancel
|
2016-05-09 19:26:13 -04:00
|
|
|
pipeline.cancel_running
|
2016-04-12 10:16:39 -04:00
|
|
|
|
2017-04-10 06:30:06 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_back_or_default default: project_pipelines_path(project)
|
2017-04-10 06:30:06 -04:00
|
|
|
end
|
|
|
|
|
2017-04-12 03:44:16 -04:00
|
|
|
format.json { head :no_content }
|
2017-04-10 06:30:06 -04:00
|
|
|
end
|
2016-04-12 10:16:39 -04:00
|
|
|
end
|
|
|
|
|
2017-03-02 12:57:01 -05:00
|
|
|
def charts
|
|
|
|
@charts = {}
|
2017-09-06 07:11:00 -04:00
|
|
|
@charts[:week] = Gitlab::Ci::Charts::WeekChart.new(project)
|
|
|
|
@charts[:month] = Gitlab::Ci::Charts::MonthChart.new(project)
|
|
|
|
@charts[:year] = Gitlab::Ci::Charts::YearChart.new(project)
|
|
|
|
@charts[:pipeline_times] = Gitlab::Ci::Charts::PipelineTime.new(project)
|
2017-06-22 08:37:59 -04:00
|
|
|
|
|
|
|
@counts = {}
|
|
|
|
@counts[:total] = @project.pipelines.count(:all)
|
|
|
|
@counts[:success] = @project.pipelines.success.count(:all)
|
|
|
|
@counts[:failed] = @project.pipelines.failed.count(:all)
|
2017-03-02 12:57:01 -05:00
|
|
|
end
|
|
|
|
|
2016-04-12 10:16:39 -04:00
|
|
|
private
|
|
|
|
|
2017-04-15 21:33:01 -04:00
|
|
|
def render_show
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-09 19:26:13 -04:00
|
|
|
def create_params
|
2016-05-18 18:01:42 -04:00
|
|
|
params.require(:pipeline).permit(:ref)
|
2016-05-09 19:26:13 -04:00
|
|
|
end
|
|
|
|
|
2016-04-13 07:01:08 -04:00
|
|
|
def pipeline
|
2017-04-04 15:21:12 -04:00
|
|
|
@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
|
2016-06-21 08:43:37 -04:00
|
|
|
@commit ||= @pipeline.commit
|
2016-04-13 11:05:17 -04:00
|
|
|
end
|
2016-04-12 10:16:39 -04:00
|
|
|
end
|