vx-service_connector 0.2.20 → 0.3.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: be3cec4a635997e6ec7fbfe8ad9c030b8206f7a4
4
- data.tar.gz: b8674641becff7494dcc92798e91acb0c1a21937
3
+ metadata.gz: ab0eff25caf5ee2ce030a75bdd20eccc1df4ef9f
4
+ data.tar.gz: 4f95803dbc9b67ca06e1a26f898a72ff342e4aea
5
5
  SHA512:
6
- metadata.gz: aafa13cf97ffd8e1f17c109d514104c7c4f9fce3cba43b3c55c4d1694e6c25770831b991c2b3908ed072c264e3b89ec157a84bd6af2071fe8351461049e960c6
7
- data.tar.gz: 29888d03c6b2a95b3b16d08932b429b1546a0498e3b41dfcc75afdab20934c3a49c929e7d3455d160fc84f189c9de8371cb15cd51e19c2431ce4715949143283
6
+ metadata.gz: 739a18f6ffd6516d9c4a4615f84c257b98adaf6fff86e64016abd8c0eb5c8df2cf314ee39127666b12c9d7f71fc4dc20e3abda5c928724ff5055e5035c3d3c02
7
+ data.tar.gz: 71e15770f7debb28f4582c55c025548a5ea8a478e9330d54fbe1cf3c88520e7509d1b32bf2fc00d0d4c041055188dfd02d41408d370745309307bae9ca458b25
@@ -17,7 +17,6 @@ module Vx
17
17
 
18
18
  def destroy(key_name)
19
19
  all.select do |key|
20
- puts [key_name, key['label']].inspect
21
20
  key['label'] == key_name
22
21
  end.map do |key|
23
22
  session.delete "api/1.0/repositories/#{repo.full_name}/deploy-keys/#{key['pk']}"
@@ -4,22 +4,29 @@ module Vx
4
4
  Payload = Struct.new(:session, :params) do
5
5
 
6
6
  def build
7
- ServiceConnector::Model::Payload.new(
8
- !!ignore?,
9
- pull_request?,
10
- pull_request_number,
11
- branch,
12
- branch_label,
13
- sha,
14
- message,
15
- author,
16
- author_email,
17
- web_url
7
+ ServiceConnector::Model::Payload.from_hash(
8
+ internal_pull_request?: (pull_request? && !foreign_pull_request?),
9
+ foreign_pull_request?: foreign_pull_request?,
10
+ pull_request_number: pull_request_number,
11
+ branch: branch,
12
+ branch_label: branch_label,
13
+ sha: sha,
14
+ message: message,
15
+ author: author,
16
+ author_email: author_email,
17
+ web_url: web_url,
18
+ tag: tag_name,
19
+ skip: ignore?,
18
20
  )
19
21
  end
20
22
 
21
23
  private
22
24
 
25
+ # TODO: implement
26
+ def tag_name
27
+ nil
28
+ end
29
+
23
30
  def pull_request?
24
31
  !(key? 'repository') && pull_request
25
32
  end
@@ -88,7 +95,7 @@ module Vx
88
95
  end
89
96
  end
90
97
 
91
- def close_pull_request?
98
+ def closed_pull_request?
92
99
  %w(DECLINED MERGED).include?(pull_request_state)
93
100
  end
94
101
 
@@ -105,12 +112,14 @@ module Vx
105
112
  end
106
113
 
107
114
  def foreign_pull_request?
108
- pull_request_head_repo_full_name != pull_request_base_repo_full_name
115
+ if pull_request?
116
+ pull_request_head_repo_full_name != pull_request_base_repo_full_name
117
+ end
109
118
  end
110
119
 
111
120
  def ignore?
112
121
  if pull_request?
113
- close_pull_request? || !foreign_pull_request?
122
+ closed_pull_request?
114
123
  else
115
124
  sha == '0000000000000000000000000000000000000000' || !commits?
116
125
  end
@@ -6,17 +6,19 @@ module Vx
6
6
  Payload = Struct.new(:session, :params) do
7
7
 
8
8
  def build
9
- ServiceConnector::Model::Payload.new(
10
- !!ignore?,
11
- !!pull_request,
12
- pull_request_number,
13
- branch,
14
- branch_label,
15
- sha,
16
- message,
17
- author,
18
- author_email,
19
- web_url
9
+ ServiceConnector::Model::Payload.from_hash(
10
+ internal_pull_request?: (pull_request? && !foreign_pull_request?),
11
+ foreign_pull_request?: foreign_pull_request?,
12
+ pull_request_number: pull_request_number,
13
+ branch: branch,
14
+ branch_label: branch_label,
15
+ sha: sha,
16
+ message: message,
17
+ author: author,
18
+ author_email: author_email,
19
+ web_url: web_url,
20
+ tag: tag_name,
21
+ skip: ignore?,
20
22
  )
21
23
  end
22
24
 
@@ -26,6 +28,10 @@ module Vx
26
28
  key? "pull_request"
27
29
  end
28
30
 
31
+ def tag_name
32
+ tag? and self['ref'].split("/tags/").last
33
+ end
34
+
29
35
  def tag?
30
36
  !pull_request? && self['ref'] =~ /^#{Regexp.escape 'refs/tags/'}/
31
37
  end
@@ -118,11 +124,11 @@ module Vx
118
124
 
119
125
  def ignore?
120
126
  if pull_request?
121
- closed_pull_request? || !foreign_pull_request?
127
+ closed_pull_request?
122
128
  elsif ping_request?
123
129
  true
124
130
  else
125
- sha == '0000000000000000000000000000000000000000' || tag?
131
+ sha == '0000000000000000000000000000000000000000'
126
132
  end
127
133
  end
128
134
 
@@ -17,6 +17,20 @@ module Vx
17
17
  author_email,
18
18
  web_url
19
19
  )
20
+ ServiceConnector::Model::Payload.from_hash(
21
+ internal_pull_request?: (pull_request? && !foreign_pull_request?),
22
+ foreign_pull_request?: foreign_pull_request?,
23
+ pull_request_number: pull_request_number,
24
+ branch: branch,
25
+ branch_label: branch_label,
26
+ sha: sha,
27
+ message: message,
28
+ author: author,
29
+ author_email: author_email,
30
+ web_url: web_url,
31
+ tag: tag_name,
32
+ skip: !valid?,
33
+ )
20
34
  end
21
35
 
22
36
  private
@@ -51,9 +65,9 @@ module Vx
51
65
 
52
66
  def ignore?
53
67
  if pull_request?
54
- closed_pull_request? || !foreign_pull_request?
68
+ closed_pull_request?
55
69
  else
56
- sha == '0000000000000000000000000000000000000000' || tag?
70
+ sha == '0000000000000000000000000000000000000000'
57
71
  end
58
72
  end
59
73
 
@@ -71,6 +85,10 @@ module Vx
71
85
  self["object_kind"] == "merge_request"
72
86
  end
73
87
 
88
+ def tag_name
89
+ tag? and self['ref'].split("/tags/").last
90
+ end
91
+
74
92
  def tag?
75
93
  !pull_request? && self["ref"].start_with?("refs/tags/")
76
94
  end
@@ -15,8 +15,8 @@ module Vx
15
15
  )
16
16
 
17
17
  Payload = Struct.new(
18
- :skip,
19
- :pull_request?,
18
+ :internal_pull_request?,
19
+ :foreign_pull_request?,
20
20
  :pull_request_number,
21
21
  :branch,
22
22
  :branch_label,
@@ -24,14 +24,41 @@ module Vx
24
24
  :message,
25
25
  :author,
26
26
  :author_email,
27
- :web_url
27
+ :web_url,
28
+ :skip,
29
+ :tag,
28
30
  ) do
29
- def to_hash ; to_h end
31
+ def to_hash
32
+ to_h
33
+ end
34
+
35
+ def master?
36
+ branch_label == "master"
37
+ end
38
+
39
+ def perform?(strategy = nil)
40
+ return false if ignore?
41
+
42
+ case strategy
43
+ when "master_or_pr"
44
+ master? or pull_request?
45
+ else # build all
46
+ not (internal_pull_request? or tag?)
47
+ end
48
+ end
30
49
 
31
50
  def ignore?
32
51
  !!(skip || message.to_s =~ /#{PAYLOAD_IGNORE_RE}/)
33
52
  end
34
53
 
54
+ def tag?
55
+ !!tag
56
+ end
57
+
58
+ def pull_request?
59
+ internal_pull_request? or foreign_pull_request?
60
+ end
61
+
35
62
  class << self
36
63
  def from_hash(params)
37
64
  payload = Payload.new
@@ -47,16 +74,18 @@ module Vx
47
74
 
48
75
  def test_payload_attributes(params = {})
49
76
  {
50
- skip: false,
51
- pull_request?: false,
52
- pull_request_number: nil,
53
- branch: 'master',
54
- branch_label: 'master:label',
55
- sha: "HEAD",
56
- message: 'test commit',
57
- author: 'User Name',
58
- author_email: 'me@example.com',
59
- web_url: 'http://example.com',
77
+ skip: false,
78
+ foreign_pull_request?: false,
79
+ internal_pull_request?: false,
80
+ pull_request_number: nil,
81
+ branch: 'master',
82
+ branch_label: 'master:label',
83
+ sha: "HEAD",
84
+ message: 'test commit',
85
+ author: 'User Name',
86
+ author_email: 'me@example.com',
87
+ web_url: 'http://example.com',
88
+ tag: nil
60
89
  }.merge(params)
61
90
  end
62
91
 
@@ -0,0 +1,48 @@
1
+ module Vx
2
+ module ServiceConnector
3
+ class PayloadFilter
4
+
5
+ attr_reader :payload, :options
6
+
7
+ def initialize(payload, options = {})
8
+ @payload = payload
9
+ @options = options
10
+ end
11
+
12
+ def perform?
13
+ return false if payload.ignore?
14
+
15
+ if options.empty?
16
+ not (
17
+ payload.internal_pull_request? ||
18
+ payload.tag?
19
+ )
20
+ end
21
+ end
22
+
23
+ def pull_request?
24
+ options[:pull_request] and payload.pull_request?
25
+ end
26
+
27
+ def tag?
28
+ options[:tag] and payload.tag?
29
+ end
30
+
31
+ def branch?
32
+ @branch ||= Array(options[:branch]).map do |branch_name|
33
+ branch_name = branch_name.to_s
34
+ if branch_name[0] == "/" && branch_name[-1] == "/"
35
+ begin
36
+ Regexp.new(branch_name).match?(payload.branch)
37
+ rescue RegexpError
38
+ false
39
+ end
40
+ else
41
+ branch_name == payload.branch
42
+ end
43
+ end.any?
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- VERSION = "0.2.20"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -36,7 +36,7 @@ describe Vx::ServiceConnector::Bitbucket::Payload do
36
36
  mock_get_commit '121111foobar/vx-promo', sha
37
37
  end
38
38
 
39
- its(:ignore?) { should be_true }
39
+ its(:ignore?) { should be_false }
40
40
  its(:pull_request?) { should be_true }
41
41
  its(:pull_request_number) { should eq 1 }
42
42
  its(:branch) { should eq 'test' }
@@ -65,7 +65,10 @@ describe Vx::ServiceConnector::Bitbucket::Payload do
65
65
  mock_get_commit 'other_login/api-test', 'b8aed32b8a30'
66
66
  end
67
67
 
68
- its(:ignore?) { should be_false }
68
+ it { should_not be_ignore }
69
+ it { should be_pull_request }
70
+ it { should be_foreign_pull_request }
71
+ it { should_not be_internal_pull_request }
69
72
  end
70
73
 
71
74
  context 'pull request with same repo' do
@@ -76,7 +79,7 @@ describe Vx::ServiceConnector::Bitbucket::Payload do
76
79
  mock_get_commit '121111foobar/vx-promo', 'b14806535f5e'
77
80
  end
78
81
 
79
- its(:ignore?) { should be_true }
82
+ its(:ignore?) { should be_false }
80
83
  end
81
84
 
82
85
  context 'push with empty commits' do
@@ -12,13 +12,14 @@ describe Vx::ServiceConnector::Github::Payload do
12
12
 
13
13
  context "ping" do
14
14
  let(:content) { read_json_fixture 'github/payload/ping' }
15
-
16
- its(:ignore?) { should be_true }
15
+ it { should be_ignore }
17
16
  end
18
17
 
19
18
  context "push" do
20
19
  let(:url) { "https://github.com/evrone/ci-worker-test-repo/commit/687753389908e70801dd4ff5448be908642055c6" }
21
20
 
21
+ it { should_not be_ignore }
22
+
22
23
  its(:pull_request?) { should be_false }
23
24
  its(:pull_request_number) { should be_nil }
24
25
  its(:sha) { should eq '84158c732ff1af3db9775a37a74ddc39f5c4078f' }
@@ -28,10 +29,10 @@ describe Vx::ServiceConnector::Github::Payload do
28
29
  its(:author) { should eq 'Dmitry Galinsky' }
29
30
  its(:author_email) { should eq 'dima.exe@gmail.com' }
30
31
  its(:web_url) { should eq url }
31
- its(:ignore?) { should be_false }
32
+ its(:tag) { should be_nil }
32
33
  end
33
34
 
34
- context "pull_request" do
35
+ context "internal pull_request" do
35
36
  let(:content) { read_json_fixture("github/payload/pull_request") }
36
37
  let(:url) { "https://github.com/evrone/cybergifts/pull/177" }
37
38
  let(:sha) { '84158c732ff1af3db9775a37a74ddc39f5c4078f' }
@@ -40,21 +41,26 @@ describe Vx::ServiceConnector::Github::Payload do
40
41
  mock_get_commit 'evrone/cybergifts', sha
41
42
  end
42
43
 
43
- its(:pull_request?) { should be_true }
44
- its(:pull_request_number) { should eq 177 }
45
- its(:sha) { should eq sha }
46
- its(:branch) { should eq 'test' }
47
- its(:branch_label) { should eq 'dima-exe:test' }
48
- its(:message) { should eq 'Fix all the bugs' }
49
- its(:author) { should eq 'Monalisa Octocat' }
50
- its(:author_email) { should eq 'support@github.com' }
51
- its(:web_url) { should eq url }
52
- its(:ignore?) { should be_true }
44
+ its(:pull_request?) { should be_true }
45
+ its(:foreign_pull_request?) { should be_false }
46
+ its(:internal_pull_request?){ should be_true }
47
+ its(:pull_request_number) { should eq 177 }
48
+ its(:sha) { should eq sha }
49
+ its(:branch) { should eq 'test' }
50
+ its(:branch_label) { should eq 'dima-exe:test' }
51
+ its(:message) { should eq 'Fix all the bugs' }
52
+ its(:author) { should eq 'Monalisa Octocat' }
53
+ its(:author_email) { should eq 'support@github.com' }
54
+ its(:web_url) { should eq url }
55
+ its(:ignore?) { should be_false }
53
56
  end
54
57
 
55
58
  context "push tag" do
56
59
  let(:content) { read_json_fixture("github/payload/push_tag") }
57
- its(:ignore?) { should be_true }
60
+ it { should_not be_pull_request }
61
+ it { should_not be_ignore }
62
+ it { should be_tag }
63
+ its(:tag) { should eq 'v0.0.1' }
58
64
  end
59
65
 
60
66
  context "closed pull request" do
@@ -63,7 +69,7 @@ describe Vx::ServiceConnector::Github::Payload do
63
69
  before do
64
70
  mock_get_commit 'evrone/cybergifts', '84158c732ff1af3db9775a37a74ddc39f5c4078f'
65
71
  end
66
-
72
+ it { should be_pull_request }
67
73
  its(:ignore?) { should be_true }
68
74
  end
69
75
 
@@ -74,18 +80,10 @@ describe Vx::ServiceConnector::Github::Payload do
74
80
  mock_get_commit 'evrone/serverist-email-provider', 'f57c385116139082811442ad48cb6127c29eb351'
75
81
  end
76
82
 
77
- its(:ignore?) { should be_false }
78
- end
79
-
80
- context "pull request with same repo" do
81
-
82
- let(:content) { read_json_fixture("github/payload/pull_request") }
83
-
84
- before do
85
- mock_get_commit 'evrone/cybergifts', '84158c732ff1af3db9775a37a74ddc39f5c4078f'
86
- end
87
-
88
- its(:ignore?) { should be_true }
83
+ it { should be_pull_request }
84
+ it { should_not be_internal_pull_request }
85
+ it { should be_foreign_pull_request }
86
+ it { should_not be_ignore }
89
87
  end
90
88
 
91
89
  end
@@ -10,7 +10,7 @@ describe Vx::ServiceConnector::GitlabV6::Payload do
10
10
  let(:payload) { gitlab.payload(repo, content) }
11
11
  subject { payload }
12
12
 
13
- context "pull_request" do
13
+ context "foreign pull request" do
14
14
  let(:content) { read_json_fixture("gitlab_v6/payload/merge_request") }
15
15
  let(:sha) { 'a7c31647c6449c3d98c4027d97e00b3048ac3bbf' }
16
16
 
@@ -20,7 +20,10 @@ describe Vx::ServiceConnector::GitlabV6::Payload do
20
20
  mock_project 1
21
21
  end
22
22
 
23
- its(:pull_request?) { should be_true }
23
+ it { should be_pull_request }
24
+ it { should be_foreign_pull_request }
25
+ it { should_not be_internal_pull_request }
26
+
24
27
  its(:pull_request_number) { should eq 5 }
25
28
  its(:sha) { should eq sha }
26
29
  its(:branch) { should eq 'some-branch-name' }
@@ -39,7 +42,9 @@ describe Vx::ServiceConnector::GitlabV6::Payload do
39
42
  end
40
43
 
41
44
  let(:content) { read_json_fixture("gitlab_v6/payload/push_tag") }
42
- its(:ignore?) { should be_true }
45
+ it { should_not be_ignore }
46
+ it { should be_tag }
47
+ its(:tag) { should eq 'v1' }
43
48
  end
44
49
 
45
50
  context "closed pull request" do
@@ -49,7 +54,8 @@ describe Vx::ServiceConnector::GitlabV6::Payload do
49
54
  mock_project 1
50
55
  end
51
56
 
52
- its(:ignore?) { should be_true }
57
+ it { should be_pull_request }
58
+ it { should be_ignore }
53
59
  end
54
60
 
55
61
  context "merged pull request" do
@@ -59,7 +65,8 @@ describe Vx::ServiceConnector::GitlabV6::Payload do
59
65
  mock_project 1
60
66
  end
61
67
 
62
- its(:ignore?) { should be_true }
68
+ it { should be_pull_request }
69
+ it { should be_ignore }
63
70
  end
64
71
 
65
72
  context "when identity is not authorized on push request" do
@@ -12,16 +12,16 @@ describe "(models)" do
12
12
  it "should knowns [ci skip]" do
13
13
  params[:skip] = false
14
14
  payload = described_class.from_hash(params)
15
- expect(payload).to_not be_ignore
15
+ expect(payload).to be_perform
16
16
 
17
17
  params[:skip] = true
18
18
  payload = described_class.from_hash(params)
19
- expect(payload).to be_ignore
19
+ expect(payload).to_not be_perform
20
20
 
21
21
  params[:skip] = false
22
22
  params[:message] = 'message [ci skip]'
23
23
  payload = described_class.from_hash(params)
24
- expect(payload).to be_ignore
24
+ expect(payload).to_not be_perform
25
25
  end
26
26
 
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-service_connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.20
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
@@ -167,6 +167,7 @@ files:
167
167
  - lib/vx/service_connector/gitlab_v6/session.rb
168
168
  - lib/vx/service_connector/instrumentation.rb
169
169
  - lib/vx/service_connector/model.rb
170
+ - lib/vx/service_connector/payload_filter.rb
170
171
  - lib/vx/service_connector/version.rb
171
172
  - spec/fixtures/bitbucket/add_deploy_key.json
172
173
  - spec/fixtures/bitbucket/changesets.json