vx-service_connector 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa4fdc2f34f10b5e4c9dfff4b3a817edf3982e9c
4
- data.tar.gz: 1c5601478f3bd460168bff00671d8e567e96da6a
3
+ metadata.gz: b5fc671f16c38849ff4dff07c11ced37c0c6ef64
4
+ data.tar.gz: d74297ae8b5ebdeea4049bb06b660125f800873e
5
5
  SHA512:
6
- metadata.gz: 6fef92824d5a332769cbd641986c11b48a29726e31b8291a47868d1e0ae0d5fd4705117e9e3be7c11bc8a014b01dcf683fbdde79534bc4d303a9288336637bba
7
- data.tar.gz: 5fb73350161baf06087e4f1caeb93f4cc250b7c8d7aabf24765ffdb025e2992c643551ff6dadd75c498b922cc69c45ad281325a1f478d37b6aab4b58ce03eaae
6
+ metadata.gz: df104c9393213f487f5e5689c1a625827ad4f777b2ee14dac502fc9812ab4d7b31174b361dcb3f45a6a9ccf8301c8f35fe3e3caf4be497c1fc6ce140fe449c9b
7
+ data.tar.gz: 65c3cff69aa04dd2487a71506e1bdbec7b93d6b79af782c6352f8bebb03206a5a54b59639c86148594039d55d8731bff8145005322249e4b258d49ba3d2cea53
@@ -32,19 +32,36 @@ module Vx
32
32
  to_h
33
33
  end
34
34
 
35
- def master?
36
- branch_label == "master"
37
- end
35
+ def perform?(restriction = nil)
36
+ if ignore?
37
+ # skip build
38
+ return false
39
+ end
40
+
41
+ if restriction.nil?
42
+ # skip internal pr or tag
43
+ # allow all pushes and foreign pr
44
+ return !(internal_pull_request? or tag?)
45
+ end
46
+
47
+ if restriction.is_a?(Hash)
48
+ branch_re = restriction[:branch]
49
+ pr = restriction[:pull_request]
38
50
 
39
- def perform?(strategy = nil)
40
- return false if ignore?
51
+ if branch_re && Regexp.new(branch_re).match(branch)
52
+ return true
53
+ end
54
+
55
+ if pr && pull_request?
56
+ return true
57
+ end
41
58
 
42
- case strategy
43
- when "master_or_pr"
44
- master? or pull_request?
45
- else # build all
46
- not (internal_pull_request? or tag?)
59
+ return false
47
60
  end
61
+
62
+ # unknown restriction
63
+ # denied
64
+ return false
48
65
  end
49
66
 
50
67
  def ignore?
@@ -68,6 +85,7 @@ module Vx
68
85
  payload
69
86
  end
70
87
  end
88
+
71
89
  end
72
90
 
73
91
  extend self
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- VERSION = "0.3.2"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -24,5 +24,72 @@ describe "(models)" do
24
24
  expect(payload).to_not be_perform
25
25
  end
26
26
 
27
+ context "perform?" do
28
+
29
+ it "message contains [ci skip]" do
30
+ params.merge!(message: "me [ci skip]")
31
+
32
+ # always skip
33
+ instance(params).to_not be_perform(nil)
34
+ end
35
+
36
+ it "restriction is null" do
37
+ # pass, push to master
38
+ instance(params).to be_perform(nil)
39
+
40
+ # pass, foreign pr
41
+ instance(
42
+ params.merge(foreign_pull_request?: true)
43
+ ).to be_perform(nil)
44
+
45
+ # deny, internal pr
46
+ instance(
47
+ params.merge(internal_pull_request?: true)
48
+ ).to_not be_perform(nil)
49
+ end
50
+
51
+ it "restriction is hash" do
52
+ # pass, branch matched
53
+ instance(
54
+ params.merge(branch: "master")
55
+ ).to be_perform(branch: "(master)" )
56
+
57
+ # deny, branch not matched
58
+ instance(
59
+ params.merge(branch: "master")
60
+ ).to_not be_perform(branch: "(develop)" )
61
+
62
+ # pass, pr allowed
63
+ instance(
64
+ params.merge(foreign_pull_request?: true)
65
+ ).to be_perform(pull_request: true)
66
+
67
+ # pass, pr allowed
68
+ instance(
69
+ params.merge(internal_pull_request?: true)
70
+ ).to be_perform(pull_request: true)
71
+
72
+ # deny, pr not allowed
73
+ instance(
74
+ params.merge(foreign_pull_request?: true)
75
+ ).to_not be_perform(pull_request: false)
76
+
77
+ # deny, pr not allowed
78
+ instance(
79
+ params.merge(internal_pull_request?: true)
80
+ ).to_not be_perform(pull_request: false)
81
+ end
82
+
83
+ it "unknown restriction" do
84
+ # deny always
85
+ instance(params).to_not be_perform('string')
86
+ instance(params).to_not be_perform(['array'])
87
+ end
88
+
89
+ def instance(payload)
90
+ expect(described_class.from_hash(payload))
91
+ end
92
+
93
+ end
27
94
  end
28
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-service_connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-23 00:00:00.000000000 Z
11
+ date: 2014-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit