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

94 lines
2.5 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]
layout 'project'
def index
@scope = params[:scope]
2016-04-13 11:01:08 +00:00
@all_pipelines = project.ci_commits
@pipelines = @all_pipelines.order(id: :desc)
@pipelines =
2016-04-12 14:16:39 +00:00
case @scope
when 'running'
2016-04-13 11:01:08 +00:00
@pipelines.running_or_pending
2016-04-12 14:16:39 +00:00
when 'branches'
2016-04-13 11:01:08 +00:00
@branches = project.repository.branches.map(&:name)
@branches_ids = @all_pipelines.where(ref: @branches).group(:ref).select('max(id)')
@pipelines.where(id: @branches_ids)
2016-04-12 14:16:39 +00:00
when 'tags'
2016-04-13 11:01:08 +00:00
@tags = project.repository.tags.map(&:name)
@tags_ids = @all_pipelines.where(ref: @tags).group(:ref).select('max(id)')
@pipelines.where(id: @tags_ids)
2016-04-12 14:16:39 +00:00
else
2016-04-13 11:01:08 +00:00
@pipelines
2016-04-12 14:16:39 +00:00
end
2016-04-13 11:01:08 +00:00
@pipelines = @pipelines.page(params[:page]).per(30)
2016-04-12 14:16:39 +00:00
end
def new
end
def create
ref_names = project.repository.ref_names
unless ref_names.include?(params[:ref])
@error = 'Reference not found'
render action: 'new'
return
end
commit = project.commit(params[:ref])
unless commit
@error = 'Commit not found'
render action: 'new'
return
end
2016-04-13 11:01:08 +00:00
pipeline = project.ci_commits.new(sha: commit.id, ref: params[:ref], before_sha: Gitlab::Git::BLANK_SHA)
2016-04-12 14:16:39 +00:00
# Skip creating ci_commit when no gitlab-ci.yml is found
2016-04-13 11:01:08 +00:00
unless pipeline.config_processor
@error = pipeline.yaml_errors || 'Missing .gitlab-ci.yml file'
2016-04-12 14:16:39 +00:00
render action: 'new'
return
end
Ci::Commit.transaction do
commit.save!
2016-04-13 11:01:08 +00:00
commit.create_builds(current_user)
2016-04-12 14:16:39 +00:00
end
redirect_to builds_namespace_project_commit_path(project.namespace, project, commit.id)
end
def show
respond_to do |format|
format.html
end
end
def retry
2016-04-13 11:01:08 +00:00
pipeline.builds.latest.failed.select(&:retryable?).each(&:retry)
2016-04-12 14:16:39 +00:00
redirect_back_or_default default: namespace_project_pipelines_path(project.namespace, project)
end
def cancel
2016-04-13 11:01:08 +00:00
pipeline.builds.running_or_pending.each(&:cancel)
2016-04-12 14:16:39 +00:00
redirect_back_or_default default: namespace_project_pipelines_path(project.namespace, project)
end
private
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