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

86 lines
2.1 KiB
Ruby
Raw Normal View History

2016-04-12 17:57:22 +00:00
class Projects::PipelinesController < Projects::ApplicationController
2016-04-13 11:01:08 +00:00
before_action :pipeline, except: [:index, :new, :create]
before_action :commit, only: [:show, :builds]
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]
def index
@scope = params[:scope]
2016-08-29 16:02:08 +00:00
@pipelines = PipelinesFinder.new(project).execute(scope: @scope).page(params[:page]).per(30)
@running_or_pending_count = PipelinesFinder.new(project).execute(scope: 'running').count
@pipelines_count = PipelinesFinder.new(project).execute.count
respond_to do |format|
format.html
format.json do
render json: {
2016-11-10 20:16:54 +00:00
pipelines: PipelineSerializer
2016-11-10 20:16:54 +00:00
.new(project: @project, user: @current_user)
.with_pagination(request, response)
.represent(@pipelines),
updated_at: Time.now.utc,
count: {
all: @pipelines_count,
running_or_pending: @running_or_pending_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)
.execute(ignore_skip_ci: true, save_on_errors: false)
unless @pipeline.persisted?
2016-05-09 23:26:13 +00:00
render 'new'
return
2016-04-12 14:16:39 +00:00
end
redirect_to namespace_project_pipeline_path(project.namespace, project, @pipeline)
2016-04-12 14:16:39 +00:00
end
def show
end
2016-11-23 14:44:05 +00:00
def builds
respond_to do |format|
format.html do
render 'show'
end
end
2016-11-23 14:44:05 +00:00
end
2016-04-12 14:16:39 +00:00
def retry
pipeline.retry_failed(current_user)
2016-04-12 14:16:39 +00:00
redirect_back_or_default default: namespace_project_pipelines_path(project.namespace, project)
end
def cancel
2016-05-09 23:26:13 +00:00
pipeline.cancel_running
2016-04-12 14:16:39 +00:00
redirect_back_or_default default: namespace_project_pipelines_path(project.namespace, project)
end
private
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])
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