summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/builds_controller.rb7
-rw-r--r--app/helpers/projects_helper.rb2
-rw-r--r--app/models/build.rb9
-rw-r--r--app/views/builds/show.html.haml6
-rw-r--r--config/routes.rb6
-rw-r--r--lib/runner.rb4
6 files changed, 31 insertions, 3 deletions
diff --git a/app/controllers/builds_controller.rb b/app/controllers/builds_controller.rb
index b0cf548..a040916 100644
--- a/app/controllers/builds_controller.rb
+++ b/app/controllers/builds_controller.rb
@@ -15,6 +15,13 @@ class BuildsController < ApplicationController
@builds = @builds.paginate(:page => params[:page], :per_page => 20)
end
+ def cancel
+ @build = @project.builds.find(params[:id])
+ @build.cancel
+
+ redirect_to project_build_path(@project, @build)
+ end
+
protected
def project
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 76c2406..4a6266f 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -12,7 +12,7 @@ module ProjectsHelper
def build_status_alert_class build
if build.success?
'alert-success'
- elsif build.failed?
+ elsif build.failed? || build.canceled?
'alert-error'
else
''
diff --git a/app/models/build.rb b/app/models/build.rb
index 00d966a..ccf7fc8 100644
--- a/app/models/build.rb
+++ b/app/models/build.rb
@@ -23,6 +23,10 @@ class Build < ActiveRecord::Base
transition running: :success
end
+ event :cancel do
+ transition [:pending, :running] => :canceled
+ end
+
after_transition :pending => :running do |build, transition|
build.update_attributes started_at: Time.now
end
@@ -35,6 +39,7 @@ class Build < ActiveRecord::Base
state :running, value: 'running'
state :failed, value: 'failed'
state :success, value: 'success'
+ state :canceled, value: 'canceled'
end
def git_author_name
@@ -63,6 +68,10 @@ class Build < ActiveRecord::Base
def to_param
sha
end
+
+ def active?
+ running? || pending?
+ end
end
diff --git a/app/views/builds/show.html.haml b/app/views/builds/show.html.haml
index 0b8612f..cf0f416 100644
--- a/app/views/builds/show.html.haml
+++ b/app/views/builds/show.html.haml
@@ -20,6 +20,10 @@
%span= @build.updated_at.stamp('19:00 Aug 27')
= @build.status
+ - if @build.active?
+ .right
+ = link_to "Cancel", cancel_project_build_path(@project, @build.id), class: 'btn btn-small btn-danger'
+
- if @build.git_author_name
%p
%b Author:
@@ -58,7 +62,7 @@
Edit Project
-- if @build.running? || @build.pending?
+- if @build.active?
:javascript
$(function(){
getBuild('#{project_build_path(@project, @build)}', '#{@build.id}');
diff --git a/config/routes.rb b/config/routes.rb
index cf4940a..fc19253 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -9,7 +9,11 @@ GitlabCi::Application.routes.draw do
get :status
post :build
end
- resources :builds, only: [:show]
+ resources :builds, only: [:show] do
+ member do
+ get :cancel
+ end
+ end
end
devise_for :users
diff --git a/lib/runner.rb b/lib/runner.rb
index c0ec09c..924a1c7 100644
--- a/lib/runner.rb
+++ b/lib/runner.rb
@@ -24,6 +24,8 @@ class Runner
path = project.path
commands = project.scripts
+ return if build.canceled?
+
build.run!
prepare_project(path, build.ref)
@@ -33,6 +35,8 @@ class Runner
status = command(line, path)
build.write_trace(@output)
+ return if build.canceled?
+
unless status
build.drop!
return