Remove Ci::Commit and Ci::Build controllers
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
3fa2cb9335
commit
1e06cabf4a
10 changed files with 71 additions and 137 deletions
|
@ -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
|
|
|
@ -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
|
|
|
@ -2,6 +2,8 @@ class Projects::BuildsController < Projects::ApplicationController
|
||||||
before_action :ci_project
|
before_action :ci_project
|
||||||
before_action :build
|
before_action :build
|
||||||
|
|
||||||
|
before_action :authorize_admin_project!, except: [:show, :status]
|
||||||
|
|
||||||
layout "project"
|
layout "project"
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@ -17,9 +19,37 @@ class Projects::BuildsController < Projects::ApplicationController
|
||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def build
|
def build
|
||||||
@build ||= ci_project.builds.unscoped.find_by!(id: params[:id])
|
@build ||= ci_project.builds.unscoped.find_by!(id: params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_path(build)
|
||||||
|
namespace_project_build_path(build.gl_project.namespace, build.gl_project, build)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,6 +38,14 @@ class Projects::CommitController < Projects::ApplicationController
|
||||||
@ci_project = @project.gitlab_ci_project
|
@ci_project = @project.gitlab_ci_project
|
||||||
end
|
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
|
def branches
|
||||||
@branches = @project.repository.branch_names_contains(commit.id)
|
@branches = @project.repository.branch_names_contains(commit.id)
|
||||||
@tags = @project.repository.tag_names_contains(commit.id)
|
@tags = @project.repository.tag_names_contains(commit.id)
|
||||||
|
|
|
@ -43,8 +43,8 @@
|
||||||
- if defined?(controls) && current_user && can?(current_user, :manage_builds, gl_project)
|
- if defined?(controls) && current_user && can?(current_user, :manage_builds, gl_project)
|
||||||
.pull-right
|
.pull-right
|
||||||
- if build.active?
|
- 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
|
%i.fa.fa-remove.cred
|
||||||
- elsif build.commands.present?
|
- 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
|
%i.fa.fa-repeat
|
||||||
|
|
|
@ -72,9 +72,9 @@
|
||||||
- if current_user && can?(current_user, :manage_builds, @project)
|
- if current_user && can?(current_user, :manage_builds, @project)
|
||||||
.pull-right
|
.pull-right
|
||||||
- if @build.active?
|
- 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?
|
- 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
|
- if @build.duration
|
||||||
%p
|
%p
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
- if @ci_project && current_user && can?(current_user, :manage_builds, @project)
|
- if @ci_project && current_user && can?(current_user, :manage_builds, @project)
|
||||||
.pull-right
|
.pull-right
|
||||||
- if @ci_commit.builds.running_or_pending.any?
|
- 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?
|
- if @ci_commit.yaml_errors.present?
|
||||||
|
|
|
@ -28,21 +28,6 @@ Gitlab::Application.routes.draw do
|
||||||
end
|
end
|
||||||
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 :runner_projects, only: [:create, :destroy]
|
||||||
|
|
||||||
resources :events, only: [:index]
|
resources :events, only: [:index]
|
||||||
|
@ -486,6 +471,7 @@ Gitlab::Application.routes.draw do
|
||||||
member do
|
member do
|
||||||
get :branches
|
get :branches
|
||||||
get :ci
|
get :ci
|
||||||
|
post :cancel_builds
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -590,7 +576,13 @@ Gitlab::Application.routes.draw do
|
||||||
end
|
end
|
||||||
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
|
resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do
|
||||||
member do
|
member do
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe "Builds" do
|
describe "Builds" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
login_as(:user)
|
login_as(:user)
|
||||||
@commit = FactoryGirl.create :ci_commit
|
@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_commit_message }
|
||||||
it { expect(page).to have_content @commit.git_author_name }
|
it { expect(page).to have_content @commit.git_author_name }
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -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
|
|
Loading…
Reference in a new issue