diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-04-01 10:10:39 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-04-01 10:10:39 +0200 |
commit | feec3a45eb517607d96f5553f36e7d35c97520ba (patch) | |
tree | db037849302326f1ecdd2916687fadd00330cdba /app/controllers | |
parent | 95b010fb73832b1bcfba884b9bcfd87d2954e44c (diff) | |
download | gitlab-ce-ci-changes-refactor.tar.gz |
Show pipelinesci-changes-refactor
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/projects/builds_controller.rb | 28 | ||||
-rw-r--r-- | app/controllers/projects/ci_commits_controller.rb | 63 | ||||
-rw-r--r-- | app/controllers/projects/commit_controller.rb | 5 |
3 files changed, 94 insertions, 2 deletions
diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb index f159e169f6d..269c0d3c21f 100644 --- a/app/controllers/projects/builds_controller.rb +++ b/app/controllers/projects/builds_controller.rb @@ -20,6 +20,30 @@ class Projects::BuildsController < Projects::ApplicationController @builds = @builds.page(params[:page]).per(30) end + def commits + @scope = params[:scope] + @all_commits = project.ci_commits + @commits = @all_commits.order(id: :desc) + @commits = + case @scope + when 'latest' + @commits + when 'branches' + refs = project.repository.branches.map(&:name) + ids = @all_commits.where(ref: refs).group(:ref).select('max(id)') + @commits.where(id: ids) + when 'tags' + refs = project.repository.tags.map(&:name) + ids = @all_commits.where(ref: refs).group(:ref).select('max(id)') + @commits.where(id: ids) + else + @commits + end + @commits = @commits.page(params[:page]).per(30) + end + + private + def cancel_all @project.builds.running_or_pending.each(&:cancel) redirect_to namespace_project_builds_path(project.namespace, project) @@ -68,6 +92,10 @@ class Projects::BuildsController < Projects::ApplicationController @build ||= project.builds.unscoped.find_by!(id: params[:id]) end + def ci_commit + @ci_commit ||= project.ci_commits.find_by!(id: params[:id]) + end + def build_path(build) namespace_project_build_path(build.project.namespace, build.project, build) end diff --git a/app/controllers/projects/ci_commits_controller.rb b/app/controllers/projects/ci_commits_controller.rb index e4797833b06..a36e3085e8a 100644 --- a/app/controllers/projects/ci_commits_controller.rb +++ b/app/controllers/projects/ci_commits_controller.rb @@ -1,6 +1,8 @@ class Projects::CiCommitsController < Projects::ApplicationController - before_action :ci_commit, except: [:index] - before_action :authorize_read_build! + before_action :ci_commit, except: [:index, :new, :create] + 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 @@ -11,6 +13,8 @@ class Projects::CiCommitsController < Projects::ApplicationController case @scope when 'latest' @commits + when 'running' + @commits.running_or_pending when 'branches' refs = project.repository.branches.map(&:name) ids = @all_commits.where(ref: refs).group(:ref).select('max(id)') @@ -25,6 +29,47 @@ class Projects::CiCommitsController < Projects::ApplicationController @commits = @commits.page(params[:page]).per(30) 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 + + ci_commit = project.ci_commit(commit.id, params[:ref]) + if ci_commit + @error = 'Pipeline already created' + render action: 'new' + return + end + + # Skip creating ci_commit when no gitlab-ci.yml is found + commit = project.ci_commits.new(sha: commit.id, ref: params[:ref], before_sha: Gitlab::Git::BLANK_SHA) + unless commit.config_processor + @error = commit.yaml_errors || 'Missing .gitlab-ci.yml file' + render action: 'new' + return + end + + Ci::Commit.transaction do + commit.save! + commit.create_builds(params[:ref], false, current_user) + end + + redirect_to builds_namespace_project_commit_path(project.namespace, project, commit.id) + end + def show @commit = @ci_commit.commit @builds = @ci_commit.builds @@ -35,6 +80,20 @@ class Projects::CiCommitsController < Projects::ApplicationController end end + def retry + ci_commit.builds.latest.failed.select(&:retryable?).each(&:retry) + + redirect_back_or_default default: namespace_project_ci_commits_path(project.namespace, project) + end + + def cancel + ci_commit.builds.running_or_pending.each(&:cancel) + + redirect_back_or_default default: namespace_project_ci_commits_path(project.namespace, project) + end + + def retry_builds + end private def ci_commit diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index ef20281e82f..623856f282f 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -96,6 +96,11 @@ class Projects::CommitController < Projects::ApplicationController def ci_commits @ci_commits ||= project.ci_commits.where(sha: commit.sha) + if params[:commit_id] + @ci_commits.where(id: params[:commit_id].to_i) + else + @ci_commits + end end def define_show_vars |