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

60 lines
1.6 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]
2016-04-13 15:05:17 +00:00
before_action :commit, only: [:show]
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-05-12 18:08:18 +00:00
all_pipelines = project.ci_commits
@pipelines_count = all_pipelines.count
@running_or_pending_count = all_pipelines.running_or_pending.count
@pipelines = PipelinesFinder.new(project).execute(all_pipelines, @scope)
2016-05-09 23:26:13 +00:00
@pipelines = @pipelines.order(id: :desc).page(params[:page]).per(30)
2016-04-12 14:16:39 +00:00
end
def new
@pipeline = project.ci_commits.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
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
def retry
2016-05-09 23:26:13 +00:00
pipeline.retry_failed
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.ci_commits.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_data
end
2016-04-12 14:16:39 +00:00
end