Remove Ci::Commit and Ci::Build controllers

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2015-10-07 15:24:32 +02:00
parent 3fa2cb9335
commit 1e06cabf4a
No known key found for this signature in database
GPG key ID: 161B5D6A44D3D88A
10 changed files with 71 additions and 137 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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?

View file

@ -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

View file

@ -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

View file

@ -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