summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-10-07 15:24:32 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-10-07 15:24:32 +0200
commit1e06cabf4a8fa4d4c7acb9898682a5b4b41a9f58 (patch)
tree1dc00333ddcb0d926bf289312b05ff14a6f81949
parent3fa2cb93353720e1b70e01ec9e664ebf54d1fc29 (diff)
downloadgitlab-ce-cleanup-ci-pages.tar.gz
Remove Ci::Commit and Ci::Build controllerscleanup-ci-pages
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/controllers/ci/builds_controller.rb52
-rw-r--r--app/controllers/ci/commits_controller.rb32
-rw-r--r--app/controllers/projects/builds_controller.rb30
-rw-r--r--app/controllers/projects/commit_controller.rb8
-rw-r--r--app/views/projects/builds/_build.html.haml4
-rw-r--r--app/views/projects/builds/show.html.haml4
-rw-r--r--app/views/projects/commit/ci.html.haml2
-rw-r--r--config/routes.rb24
-rw-r--r--spec/features/builds_spec.rb21
-rw-r--r--spec/features/ci/builds_spec.rb31
10 files changed, 71 insertions, 137 deletions
diff --git a/app/controllers/ci/builds_controller.rb b/app/controllers/ci/builds_controller.rb
deleted file mode 100644
index b0b8b62fced..00000000000
--- a/app/controllers/ci/builds_controller.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-module Ci
- class BuildsController < Ci::ApplicationController
- before_action :authenticate_user!, except: [:status]
- before_action :project
- before_action :authorize_access_project!, except: [:status]
- before_action :authorize_manage_project!, except: [:status, :retry, :cancel]
- before_action :authorize_manage_builds!, only: [:retry, :cancel]
- before_action :build
-
- def retry
- if @build.commands.blank?
- return page_404
- end
-
- build = Ci::Build.retry(@build)
-
- if params[:return_to]
- redirect_to URI.parse(params[:return_to]).path
- else
- redirect_to build_path(build)
- end
- end
-
- def status
- render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha)
- end
-
- def cancel
- @build.cancel
-
- redirect_to build_path(@build)
- end
-
- protected
-
- def project
- @project = Ci::Project.find(params[:project_id])
- end
-
- def build
- @build ||= project.builds.unscoped.find_by!(id: params[:id])
- end
-
- def commit_by_sha
- @project.commits.find_by(sha: params[:id])
- end
-
- def build_path(build)
- namespace_project_build_path(build.gl_project.namespace, build.gl_project, build)
- end
- end
-end
diff --git a/app/controllers/ci/commits_controller.rb b/app/controllers/ci/commits_controller.rb
deleted file mode 100644
index 7e6705c9702..00000000000
--- a/app/controllers/ci/commits_controller.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-module Ci
- class CommitsController < Ci::ApplicationController
- before_action :authenticate_user!, except: [:status, :show]
- before_action :authenticate_public_page!, only: :show
- before_action :project
- before_action :authorize_access_project!, except: [:status, :show, :cancel]
- before_action :authorize_manage_builds!, only: [:cancel]
-
- def status
- commit = Ci::Project.find(params[:project_id]).commits.find_by_sha!(params[:id])
- render json: commit.to_json(only: [:id, :sha], methods: [:status, :coverage])
- rescue ActiveRecord::RecordNotFound
- render json: { status: "not_found" }
- end
-
- def cancel
- commit.builds.running_or_pending.each(&:cancel)
-
- redirect_to namespace_project_commit_path(commit.gl_project.namespace, commit.gl_project, commit.sha)
- end
-
- private
-
- def project
- @project ||= Ci::Project.find(params[:project_id])
- end
-
- def commit
- @commit ||= Ci::Project.find(params[:project_id]).commits.find_by_sha!(params[:id])
- end
- end
-end
diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb
index 76c7f31f61b..4e4ac6689d3 100644
--- a/app/controllers/projects/builds_controller.rb
+++ b/app/controllers/projects/builds_controller.rb
@@ -2,6 +2,8 @@ class Projects::BuildsController < Projects::ApplicationController
before_action :ci_project
before_action :build
+ before_action :authorize_admin_project!, except: [:show, :status]
+
layout "project"
def show
@@ -17,9 +19,37 @@ class Projects::BuildsController < Projects::ApplicationController
end
end
+ def retry
+ if @build.commands.blank?
+ return page_404
+ end
+
+ build = Ci::Build.retry(@build)
+
+ if params[:return_to]
+ redirect_to URI.parse(params[:return_to]).path
+ else
+ redirect_to build_path(build)
+ end
+ end
+
+ def status
+ render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha)
+ end
+
+ def cancel
+ @build.cancel
+
+ redirect_to build_path(@build)
+ end
+
private
def build
@build ||= ci_project.builds.unscoped.find_by!(id: params[:id])
end
+
+ def build_path(build)
+ namespace_project_build_path(build.gl_project.namespace, build.gl_project, build)
+ end
end
diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb
index 1938c63c10c..c08a90bddf0 100644
--- a/app/controllers/projects/commit_controller.rb
+++ b/app/controllers/projects/commit_controller.rb
@@ -38,6 +38,14 @@ class Projects::CommitController < Projects::ApplicationController
@ci_project = @project.gitlab_ci_project
end
+ def cancel_builds
+ @ci_commit = @project.ci_commit(@commit.sha)
+ @ci_commit.builds.running_or_pending.each(&:cancel)
+
+ redirect_to namespace_project_commit_path(project.namespace, project, commit.sha)
+ end
+
+
def branches
@branches = @project.repository.branch_names_contains(commit.id)
@tags = @project.repository.tag_names_contains(commit.id)
diff --git a/app/views/projects/builds/_build.html.haml b/app/views/projects/builds/_build.html.haml
index 21c543b38dd..65fd9413b60 100644
--- a/app/views/projects/builds/_build.html.haml
+++ b/app/views/projects/builds/_build.html.haml
@@ -43,8 +43,8 @@
- if defined?(controls) && current_user && can?(current_user, :manage_builds, gl_project)
.pull-right
- if build.active?
- = link_to cancel_ci_project_build_path(build.project, build, return_to: request.original_url), title: 'Cancel build' do
+ = link_to cancel_namespace_project_build_path(gl_project.namespace, gl_project, build, return_to: request.original_url), title: 'Cancel build' do
%i.fa.fa-remove.cred
- elsif build.commands.present?
- = link_to retry_ci_project_build_path(build.project, build, return_to: request.original_url), method: :post, title: 'Retry build' do
+ = link_to retry_namespace_project_build_path(gl_project.namespace, gl_project, build, return_to: request.original_url), method: :post, title: 'Retry build' do
%i.fa.fa-repeat
diff --git a/app/views/projects/builds/show.html.haml b/app/views/projects/builds/show.html.haml
index 93cd4dcfd93..b561078e8c7 100644
--- a/app/views/projects/builds/show.html.haml
+++ b/app/views/projects/builds/show.html.haml
@@ -72,9 +72,9 @@
- if current_user && can?(current_user, :manage_builds, @project)
.pull-right
- if @build.active?
- = link_to "Cancel", cancel_ci_project_build_path(@ci_project, @build), class: 'btn btn-sm btn-danger'
+ = link_to "Cancel", cancel_namespace_project_build_path(@project.namespace, @project, @build), class: 'btn btn-sm btn-danger'
- elsif @build.commands.present?
- = link_to "Retry", retry_ci_project_build_path(@ci_project, @build), class: 'btn btn-sm btn-primary', method: :post
+ = link_to "Retry", retry_namespace_project_build_path(@project.namespace, @project, @build), class: 'btn btn-sm btn-primary', method: :post
- if @build.duration
%p
diff --git a/app/views/projects/commit/ci.html.haml b/app/views/projects/commit/ci.html.haml
index f4382e88046..26ab38445c2 100644
--- a/app/views/projects/commit/ci.html.haml
+++ b/app/views/projects/commit/ci.html.haml
@@ -6,7 +6,7 @@
- if @ci_project && current_user && can?(current_user, :manage_builds, @project)
.pull-right
- if @ci_commit.builds.running_or_pending.any?
- = link_to "Cancel", cancel_ci_project_commits_path(@ci_project, @ci_commit), class: 'btn btn-sm btn-danger'
+ = link_to "Cancel", cancel_builds_namespace_project_commit_path(@project.namespace, @project, @commit.sha), class: 'btn btn-sm btn-danger'
- if @ci_commit.yaml_errors.present?
diff --git a/config/routes.rb b/config/routes.rb
index ccce40589e7..4fb779e297c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -28,21 +28,6 @@ Gitlab::Application.routes.draw do
end
end
- resources :commits, only: [] do
- member do
- get :status
- get :cancel
- end
- end
-
- resources :builds, only: [] do
- member do
- get :cancel
- get :status
- post :retry
- end
- end
-
resources :runner_projects, only: [:create, :destroy]
resources :events, only: [:index]
@@ -486,6 +471,7 @@ Gitlab::Application.routes.draw do
member do
get :branches
get :ci
+ post :cancel_builds
end
end
@@ -590,7 +576,13 @@ Gitlab::Application.routes.draw do
end
end
- resources :builds, only: [:show]
+ resources :builds, only: [:show] do
+ member do
+ get :cancel
+ get :status
+ post :retry
+ end
+ end
resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do
member do
diff --git a/spec/features/builds_spec.rb b/spec/features/builds_spec.rb
index d0d60491b65..924047a0d8f 100644
--- a/spec/features/builds_spec.rb
+++ b/spec/features/builds_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
describe "Builds" do
-
before do
login_as(:user)
@commit = FactoryGirl.create :ci_commit
@@ -19,4 +18,24 @@ describe "Builds" do
it { expect(page).to have_content @commit.git_commit_message }
it { expect(page).to have_content @commit.git_author_name }
end
+
+ describe "GET /:project/builds/:id/cancel" do
+ before do
+ @build.run!
+ visit cancel_namespace_project_build_path(@gl_project.namespace, @gl_project, @build)
+ end
+
+ it { expect(page).to have_content 'canceled' }
+ it { expect(page).to have_content 'Retry' }
+ end
+
+ describe "POST /:project/builds/:id/retry" do
+ before do
+ visit cancel_namespace_project_build_path(@gl_project.namespace, @gl_project, @build)
+ click_link 'Retry'
+ end
+
+ it { expect(page).to have_content 'pending' }
+ it { expect(page).to have_content 'Cancel' }
+ end
end
diff --git a/spec/features/ci/builds_spec.rb b/spec/features/ci/builds_spec.rb
deleted file mode 100644
index aa0df59c04d..00000000000
--- a/spec/features/ci/builds_spec.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-require 'spec_helper'
-
-describe "Builds" do
- before do
- login_as(:user)
- @commit = FactoryGirl.create :ci_commit
- @build = FactoryGirl.create :ci_build, commit: @commit
- @gl_project = @commit.project.gl_project
- @gl_project.team << [@user, :master]
- end
-
- describe "GET /:project/builds/:id/cancel" do
- before do
- @build.run!
- visit cancel_ci_project_build_path(@commit.project, @build)
- end
-
- it { expect(page).to have_content 'canceled' }
- it { expect(page).to have_content 'Retry' }
- end
-
- describe "POST /:project/builds/:id/retry" do
- before do
- visit cancel_ci_project_build_path(@commit.project, @build)
- click_link 'Retry'
- end
-
- it { expect(page).to have_content 'pending' }
- it { expect(page).to have_content 'Cancel' }
- end
-end