summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTino Wehe <tino.wehe@brandrockers.com>2015-04-01 13:58:27 +0200
committerTino Wehe <tino.wehe@brandrockers.com>2015-04-01 13:58:27 +0200
commit6b4148c8ca04ff3332be6452b8d6cfc6870bc780 (patch)
tree77fe628396989f63035e2bcffee57caa16ad6cda
parent7564d38f6fe3aad1291750e17d815017a646032d (diff)
downloadgitlab-ci-6b4148c8ca04ff3332be6452b8d6cfc6870bc780.tar.gz
Changed RegExp to glob pattern like in project settings
-rw-r--r--app/models/job.rb21
-rw-r--r--app/views/jobs/_deploy_job_edit.html.haml6
-rw-r--r--spec/models/job_spec.rb13
3 files changed, 14 insertions, 26 deletions
diff --git a/app/models/job.rb b/app/models/job.rb
index 3a358c1..756f1eb 100644
--- a/app/models/job.rb
+++ b/app/models/job.rb
@@ -33,23 +33,14 @@ class Job < ActiveRecord::Base
end
def run_for_ref?(ref)
- refs.blank? || refs_include_ref?(ref)
- end
-
- def refs_include_ref?(ref)
- includes = false
- # extract the refs - split by ","
- # is tricky because they can be in a regex too
- refs.scan(/\w+|\/+.*?\/+/).map(&:strip).each do |re|
- # is regexp or not
- if re.start_with?("/") && re.end_with?("/")
- includes = !ref.match(/#{re.delete("/")}/i).nil?
- else
- includes = ref == re
+ if !refs.blank?
+ refs.split(",").map(&:strip).each do |refsVal|
+ return true if File.fnmatch(refsVal, ref)
end
- break if includes == true
+ false
+ else
+ true
end
- includes
end
end
diff --git a/app/views/jobs/_deploy_job_edit.html.haml b/app/views/jobs/_deploy_job_edit.html.haml
index 3b802d4..4a39c17 100644
--- a/app/views/jobs/_deploy_job_edit.html.haml
+++ b/app/views/jobs/_deploy_job_edit.html.haml
@@ -28,13 +28,11 @@
= label_tag :refs, class: 'control-label' do
Refs
.col-sm-10
- = job_form.text_field :refs, class: 'form-control', placeholder: "master, staging, /testing-v.*/"
+ = 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
- You can use RegExp like "/stable-v.*/" to match a ref like "stable-v0.1.0". The RegExp is always case insensitive.
- %br
- NOTE: It's important to surround you regex with "/"!
+ 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 643a23c..96221d7 100644
--- a/spec/models/job_spec.rb
+++ b/spec/models/job_spec.rb
@@ -30,15 +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, /testing.*/, /^unstable$/, /unstable-v[0-9]{1,}.[0-9]{1,}.[0-9]{1,}/"
+ 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?("staging-v0.1.0").should be_false
- job.run_for_ref?("testing").should be_true
- job.run_for_ref?("testing-v0.1.0").should be_true
- job.run_for_ref?("unstable").should be_true
- job.run_for_ref?("unstable-v0.1.0").should be_true
- job.run_for_ref?("unstable-0.1.0").should be_false
+ 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