2016-06-02 11:05:42 +05:30
|
|
|
class Projects::PipelinesController < Projects::ApplicationController
|
2018-03-17 18:26:18 +05:30
|
|
|
before_action :whitelist_query_limiting, only: [:create, :retry]
|
2017-08-17 22:00:37 +05:30
|
|
|
before_action :pipeline, except: [:index, :new, :create, :charts]
|
|
|
|
before_action :commit, only: [:show, :builds, :failures]
|
2016-06-02 11:05:42 +05:30
|
|
|
before_action :authorize_read_pipeline!
|
|
|
|
before_action :authorize_create_pipeline!, only: [:new, :create]
|
|
|
|
before_action :authorize_update_pipeline!, only: [:retry, :cancel]
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
wrap_parameters Ci::Pipeline
|
|
|
|
|
|
|
|
POLLING_INTERVAL = 10_000
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
def index
|
|
|
|
@scope = params[:scope]
|
2017-08-17 22:00:37 +05:30
|
|
|
@pipelines = PipelinesFinder
|
|
|
|
.new(project, scope: @scope)
|
|
|
|
.execute
|
|
|
|
.page(params[:page])
|
|
|
|
.per(30)
|
|
|
|
|
|
|
|
@running_count = PipelinesFinder
|
|
|
|
.new(project, scope: 'running').execute.count
|
|
|
|
|
|
|
|
@pending_count = PipelinesFinder
|
|
|
|
.new(project, scope: 'pending').execute.count
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
@finished_count = PipelinesFinder
|
|
|
|
.new(project, scope: 'finished').execute.count
|
|
|
|
|
|
|
|
@pipelines_count = PipelinesFinder
|
|
|
|
.new(project).execute.count
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
@pipelines.map(&:commit) # List commits for batch loading
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
pipelines: PipelineSerializer
|
|
|
|
.new(project: @project, current_user: @current_user)
|
|
|
|
.with_pagination(request, response)
|
|
|
|
.represent(@pipelines),
|
|
|
|
count: {
|
|
|
|
all: @pipelines_count,
|
|
|
|
running: @running_count,
|
|
|
|
pending: @pending_count,
|
2017-09-10 17:25:29 +05:30
|
|
|
finished: @finished_count
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2016-06-16 23:09:34 +05:30
|
|
|
@pipeline = project.pipelines.new(ref: @project.default_branch)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-08-17 22:00:37 +05:30
|
|
|
@pipeline = Ci::CreatePipelineService
|
|
|
|
.new(project, current_user, create_params)
|
2017-09-10 17:25:29 +05:30
|
|
|
.execute(:web, ignore_skip_ci: true, save_on_errors: false)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
if @pipeline.persisted?
|
2017-09-10 17:25:29 +05:30
|
|
|
redirect_to project_pipeline_path(project, @pipeline)
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
2016-06-02 11:05:42 +05:30
|
|
|
render 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2017-08-17 22:00:37 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL)
|
|
|
|
|
|
|
|
render json: PipelineSerializer
|
|
|
|
.new(project: @project, current_user: @current_user)
|
|
|
|
.represent(@pipeline, grouped: true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def builds
|
|
|
|
render_show
|
|
|
|
end
|
|
|
|
|
|
|
|
def failures
|
|
|
|
if @pipeline.statuses.latest.failed.present?
|
|
|
|
render_show
|
|
|
|
else
|
|
|
|
redirect_to pipeline_path(@pipeline)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def status
|
|
|
|
render json: PipelineSerializer
|
|
|
|
.new(project: @project, current_user: @current_user)
|
|
|
|
.represent_status(@pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
def stage
|
2017-09-10 17:25:29 +05:30
|
|
|
@stage = pipeline.legacy_stage(params[:stage])
|
2017-08-17 22:00:37 +05:30
|
|
|
return not_found unless @stage
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { render json: { html: view_to_html_string('projects/pipelines/_stage') } }
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def retry
|
2016-06-16 23:09:34 +05:30
|
|
|
pipeline.retry_failed(current_user)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2017-09-10 17:25:29 +05:30
|
|
|
redirect_back_or_default default: project_pipelines_path(project)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def cancel
|
|
|
|
pipeline.cancel_running
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2017-09-10 17:25:29 +05:30
|
|
|
redirect_back_or_default default: project_pipelines_path(project)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def charts
|
|
|
|
@charts = {}
|
2018-03-17 18:26:18 +05:30
|
|
|
@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-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
@counts = {}
|
|
|
|
@counts[:total] = @project.pipelines.count(:all)
|
|
|
|
@counts[:success] = @project.pipelines.success.count(:all)
|
|
|
|
@counts[:failed] = @project.pipelines.failed.count(:all)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def render_show
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def create_params
|
|
|
|
params.require(:pipeline).permit(:ref)
|
|
|
|
end
|
|
|
|
|
|
|
|
def pipeline
|
2017-08-17 22:00:37 +05:30
|
|
|
@pipeline ||= project.pipelines.find_by!(id: params[:id]).present(current_user: current_user)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def commit
|
2016-06-22 15:30:34 +05:30
|
|
|
@commit ||= @pipeline.commit
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def whitelist_query_limiting
|
|
|
|
# Also see https://gitlab.com/gitlab-org/gitlab-ce/issues/42343
|
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42339')
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|