summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Herry <WilliamHerryChina@Gmail.com>2014-09-09 22:56:42 +0800
committerWilliam Herry <WilliamHerryChina@Gmail.com>2014-09-10 05:46:32 +0800
commit2c03187fb6c3a89349faad781e90ebda476ad7ee (patch)
tree61c6d4db92cbf25a3ad33d6d11b4fb314ed4f632
parentc7b7cb7368c0165d88392bbfd951f3c4314470ae (diff)
downloadgitlab-ci-2c03187fb6c3a89349faad781e90ebda476ad7ee.tar.gz
make gitlab_ci able to skip refs from build
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/projects_controller.rb2
-rw-r--r--app/models/project.rb6
-rw-r--r--app/services/create_build_service.rb2
-rw-r--r--app/views/projects/_form.html.haml4
-rw-r--r--db/migrate/20140909142245_add_skip_refs_to_projects.rb5
-rw-r--r--db/schema.rb3
7 files changed, 20 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 541ea8b..aa56ebb 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,7 @@ v5.1
- Registration token and runner token are named differently
- Redirect to previous page after sign-in
- Dont show archived projects
+ - Add support for skip branches from build
v5.0.1
- Update rails to 4.0.5
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index e604571..7a6a8e0 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -75,7 +75,7 @@ class ProjectsController < ApplicationController
def build
@build = CreateBuildService.new.execute(@project, params.dup)
- if @build.persisted?
+ if @build && @build.persisted?
head 201
else
head 400
diff --git a/app/models/project.rb b/app/models/project.rb
index 5a8f052..fc70559 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -25,7 +25,7 @@
class Project < ActiveRecord::Base
attr_accessible :name, :path, :scripts, :timeout, :token, :timeout_in_minutes,
:default_ref, :gitlab_url, :always_build, :polling_interval,
- :public, :ssh_url_to_repo, :gitlab_id, :allow_git_fetch,
+ :public, :ssh_url_to_repo, :gitlab_id, :allow_git_fetch, :skip_refs,
:email_recipients, :email_add_committer, :email_only_broken_builds
has_many :builds, dependent: :destroy
@@ -175,4 +175,8 @@ ls -la
def timeout_in_minutes=(value)
self.timeout = value.to_i * 60
end
+
+ def skip_refs
+ read_attribute(:skip_refs).delete(" ").split(",")
+ end
end
diff --git a/app/services/create_build_service.rb b/app/services/create_build_service.rb
index a5b2484..a24a393 100644
--- a/app/services/create_build_service.rb
+++ b/app/services/create_build_service.rb
@@ -8,6 +8,8 @@ class CreateBuildService
ref = ref.scan(/heads\/(.*)$/).flatten[0]
end
+ return false if project.skip_refs.include?(ref)
+
data = {
ref: ref,
sha: sha,
diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml
index 14f48b8..5d8c05d 100644
--- a/app/views/projects/_form.html.haml
+++ b/app/views/projects/_form.html.haml
@@ -111,6 +111,10 @@
= f.label :token, "CI token", class: 'control-label'
.col-sm-10
= f.text_field :token, class: 'form-control', placeholder: 'xEeFCaDAB89'
+ .form-group
+ = f.label :skip_refs, "Skip refs", class: 'control-label'
+ .col-sm-10
+ = f.text_field :skip_refs, class: 'form-control', placeholder: 'branch1, branch2'
.form-actions
= f.submit 'Save changes', class: 'btn btn-save'
diff --git a/db/migrate/20140909142245_add_skip_refs_to_projects.rb b/db/migrate/20140909142245_add_skip_refs_to_projects.rb
new file mode 100644
index 0000000..2d7b1a2
--- /dev/null
+++ b/db/migrate/20140909142245_add_skip_refs_to_projects.rb
@@ -0,0 +1,5 @@
+class AddSkipRefsToProjects < ActiveRecord::Migration
+ def change
+ add_column :projects, :skip_refs, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index dcb3569..1a11e98 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20140506091853) do
+ActiveRecord::Schema.define(version: 20140909142245) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -53,6 +53,7 @@ ActiveRecord::Schema.define(version: 20140506091853) do
t.string "email_recipients", default: "", null: false
t.boolean "email_add_committer", default: true, null: false
t.boolean "email_only_broken_builds", default: true, null: false
+ t.string "skip_refs"
end
create_table "runner_projects", force: true do |t|