summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValeriy Sizov <vsv2711@gmail.com>2015-04-07 13:16:32 +0300
committerValeriy Sizov <vsv2711@gmail.com>2015-04-07 13:16:32 +0300
commit5bb4db13ae3ec9315239917cb9aeaab8065c5062 (patch)
treed32983116b88c92ba2d530749e557b6b3256f8a3
parent1bb72f838cde2d7f3cfd3e55c2e189499ff0f1cb (diff)
parent8fd382d1d17fddc5c7aa3924552fab5af849db7d (diff)
downloadgitlab-ci-5bb4db13ae3ec9315239917cb9aeaab8065c5062.tar.gz
Merge pull request #573 from pixel-shock/deploy-jobs-with-regex
Jobs checking "run_for_ref" by glob pattern
-rw-r--r--app/models/job.rb14
-rw-r--r--app/views/jobs/_deploy_job_edit.html.haml6
-rw-r--r--spec/models/job_spec.rb9
3 files changed, 22 insertions, 7 deletions
diff --git a/app/models/job.rb b/app/models/job.rb
index 106e0d3..005a778 100644
--- a/app/models/job.rb
+++ b/app/models/job.rb
@@ -26,13 +26,21 @@ class Job < ActiveRecord::Base
scope :parallel, ->(){ where(job_type: "parallel") }
scope :deploy, ->(){ where(job_type: "deploy") }
- validate :refs, length: { maximum: 100 }
-
+ validate :refs, length: { maximum: 255 }
+
def deploy?
job_type == "deploy"
end
def run_for_ref?(ref)
- refs.blank? || refs.split(",").map{|ref| ref.strip}.include?(ref)
+ if !refs.blank?
+ refs.split(",").map(&:strip).each do |refs_val|
+ return true if File.fnmatch(refs_val, ref)
+ end
+
+ false
+ else
+ true
+ end
end
end
diff --git a/app/views/jobs/_deploy_job_edit.html.haml b/app/views/jobs/_deploy_job_edit.html.haml
index f04029a..4a39c17 100644
--- a/app/views/jobs/_deploy_job_edit.html.haml
+++ b/app/views/jobs/_deploy_job_edit.html.haml
@@ -27,10 +27,12 @@
.form-group
= label_tag :refs, class: 'control-label' do
Refs
- .col-sm-10
- = job_form.text_field :refs, class: 'form-control', placeholder: "master, staging"
+ .col-sm-10
+ = job_form.text_field :refs, class: 'form-control', placeholder: "master, staging, feature/*, tags/testing*"
.help-block
Run only when the above git refs strings match the branch or tag that was pushed.
+ %br
+ Accepts strings and glob pattern syntax
.form-group
= f.label :commands, 'Script', class: 'control-label'
diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb
index f80519d..96221d7 100644
--- a/spec/models/job_spec.rb
+++ b/spec/models/job_spec.rb
@@ -22,7 +22,7 @@ describe Job do
it { should belong_to(:project) }
it { should have_many(:builds) }
-
+
describe "run_for_ref?" do
it "allows run for any ref if refs params is empty" do
job = FactoryGirl.create :job, project: project
@@ -30,9 +30,14 @@ describe Job do
end
it "allows run for any ref in refs params" do
- job = FactoryGirl.create :job, project: project, refs: "master, staging"
+ job = FactoryGirl.create :job, project: project, refs: "master, staging, tags/testing*"
job.run_for_ref?("master").should be_true
job.run_for_ref?("staging").should be_true
+ job.run_for_ref?("testing").should be_false
+ job.run_for_ref?("tags/testing").should be_true
+ job.run_for_ref?("tags/testing-v0.1.0").should be_true
+ job.run_for_ref?("tags/unstable-v0.1.0").should be_false
+ job.run_for_ref?("feature/feature-one").should be_false
job.run_for_ref?("anything").should be_false
end
end