2016-04-12 13:57:22 -04:00
|
|
|
class Projects::PipelinesController < Projects::ApplicationController
|
2016-04-13 07:01:08 -04:00
|
|
|
before_action :pipeline, except: [:index, :new, :create]
|
2016-11-24 06:28:48 -05:00
|
|
|
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]
|
|
|
|
|
|
|
|
def index
|
|
|
|
@scope = params[:scope]
|
2016-08-29 12:02:08 -04:00
|
|
|
@pipelines = PipelinesFinder.new(project).execute(scope: @scope).page(params[:page]).per(30)
|
2016-12-19 07:20:17 -05:00
|
|
|
@pipelines = @pipelines.includes(project: :namespace)
|
2016-08-29 12:02:08 -04:00
|
|
|
|
|
|
|
@running_or_pending_count = PipelinesFinder.new(project).execute(scope: 'running').count
|
|
|
|
@pipelines_count = PipelinesFinder.new(project).execute.count
|
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)
|
|
|
|
.execute(ignore_skip_ci: true, save_on_errors: false)
|
2016-05-18 14:02:10 -04:00
|
|
|
unless @pipeline.persisted?
|
2016-05-09 19:26:13 -04:00
|
|
|
render 'new'
|
2016-05-18 14:02:10 -04:00
|
|
|
return
|
2016-04-12 10:16:39 -04:00
|
|
|
end
|
2016-05-18 14:02:10 -04:00
|
|
|
|
|
|
|
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
|
2016-11-24 06:28:48 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
end
|
2016-11-23 09:44:05 -05:00
|
|
|
end
|
|
|
|
|
2016-12-19 07:20:17 -05:00
|
|
|
def stage
|
2016-12-20 05:00:56 -05:00
|
|
|
@stage = pipeline.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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
private
|
|
|
|
|
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
|
2016-06-02 10:19:18 -04:00
|
|
|
@pipeline ||= project.pipelines.find_by!(id: params[:id])
|
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
|