vx-service_connector 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be805b8dc0033600d9ca1308a978662265511fe9
4
- data.tar.gz: 20c8773267e79c9b8e67eca0db4d163bcd0297f0
3
+ metadata.gz: 52cbb6a0746f93f3d0a5cb115b40bea4ca1d3285
4
+ data.tar.gz: f26d4ff7f9c5b8a10d47d09128d18af8393a0ede
5
5
  SHA512:
6
- metadata.gz: 796ea1027648f0a5bd4e2d9d7068cf273a062a2b4b94cc3234ea745128366e3470f540a1f7856db619262fd25f0539b2ee5271df16bd9638c055f6b64d7bf0de
7
- data.tar.gz: 30b33ed4e562cba01b3b2fda3b61fbcf308a63122b5f312231326f1aba6f92c85c08a8908940ee12e77055524b15d3941d295aa2869dae1e6f4f115e7b0468b9
6
+ metadata.gz: fa0c48d29fe52fc515f4af58e35c669f035d4e1b9148f34a517dc0cdfafd6918a5c1a81ba5554e9025482d42026cd4bb805ff35bbec58ca6091f369938b20ec3
7
+ data.tar.gz: db8f3a59715a8fa358e2c179cdf2e68a4e94e7fd55e8b612f39d8f0638298daa1183c142fa2263e7426235cdcdb1a2198c379ed637f7cbc00316cc3f3704706a
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- class RequestError < StandardError ; end
3
+ class RequestError < RuntimeError ; end
4
4
  end
5
5
  end
@@ -7,18 +7,24 @@ module Vx
7
7
  Session = Struct.new(:endpoint, :private_token) do
8
8
 
9
9
  def get(url, options = {})
10
- res = agent.call :get, request_url(url), nil, query: options
11
- response! res
10
+ wrap do
11
+ res = agent.call :get, request_url(url), nil, query: options
12
+ response! res
13
+ end
12
14
  end
13
15
 
14
16
  def post(url, options = {})
15
- res = agent.call :post, request_url(url), options, nil
16
- response! res
17
+ wrap do
18
+ res = agent.call :post, request_url(url), options, nil
19
+ response! res
20
+ end
17
21
  end
18
22
 
19
23
  def delete(url, options = {})
20
- res = agent.call :delete, request_url(url), nil, query: options
21
- response! res
24
+ wrap do
25
+ res = agent.call :delete, request_url(url), nil, query: options
26
+ response! res
27
+ end
22
28
  end
23
29
 
24
30
  def uri
@@ -27,6 +33,14 @@ module Vx
27
33
 
28
34
  private
29
35
 
36
+ def wrap
37
+ begin
38
+ yield
39
+ rescue Errno::ETIMEDOUT => e
40
+ raise RequestError, e
41
+ end
42
+ end
43
+
30
44
  def response!(res)
31
45
  if (200..204).include?(res.status)
32
46
  res.data
@@ -2,7 +2,6 @@ require 'active_support/notifications'
2
2
  require 'faraday'
3
3
  require 'octokit/default'
4
4
 
5
-
6
5
  Octokit::Default::MIDDLEWARE.insert 0, Faraday::Request::Instrumentation
7
6
 
8
7
  builder = Faraday::RackBuilder.new
@@ -2,6 +2,8 @@ module Vx
2
2
  module ServiceConnector
3
3
  module Model
4
4
 
5
+ PAYLOAD_IGNORE_RE = Regexp.escape("[ci skip]")
6
+
5
7
  Repo = Struct.new(
6
8
  :id,
7
9
  :full_name,
@@ -12,7 +14,7 @@ module Vx
12
14
  )
13
15
 
14
16
  Payload = Struct.new(
15
- :ignore?,
17
+ :skip,
16
18
  :pull_request?,
17
19
  :pull_request_number,
18
20
  :branch,
@@ -25,6 +27,10 @@ module Vx
25
27
  ) do
26
28
  def to_hash ; to_h end
27
29
 
30
+ def ignore?
31
+ skip || message.to_s =~ /#{PAYLOAD_IGNORE_RE}/
32
+ end
33
+
28
34
  class << self
29
35
  def from_hash(params)
30
36
  payload = Payload.new
@@ -40,7 +46,7 @@ module Vx
40
46
 
41
47
  def test_payload_attributes(params = {})
42
48
  {
43
- ignore?: false,
49
+ skip: false,
44
50
  pull_request?: false,
45
51
  pull_request_number: nil,
46
52
  branch: 'master',
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -2,11 +2,27 @@ require 'spec_helper'
2
2
 
3
3
  describe "(models)" do
4
4
  context Vx::ServiceConnector::Model::Payload do
5
+ let(:params) { Vx::ServiceConnector::Model.test_payload_attributes }
5
6
 
6
- context ".from_hash" do
7
- let(:params) { Vx::ServiceConnector::Model.test_payload_attributes }
8
- subject { described_class.from_hash(params).to_hash }
9
- it { should eq params }
7
+ it "should build from hash" do
8
+ payload = described_class.from_hash(params).to_hash
9
+ expect(payload).to eq params
10
10
  end
11
+
12
+ it "should knowns [ci skip]" do
13
+ params[:skip] = false
14
+ payload = described_class.from_hash(params)
15
+ expect(payload).to_not be_ignore
16
+
17
+ params[:skip] = true
18
+ payload = described_class.from_hash(params)
19
+ expect(payload).to be_ignore
20
+
21
+ params[:skip] = false
22
+ params[:message] = 'message [ci skip]'
23
+ payload = described_class.from_hash(params)
24
+ expect(payload).to be_ignore
25
+ end
26
+
11
27
  end
12
28
  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.2.1
4
+ version: 0.2.2
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-06-27 00:00:00.000000000 Z
11
+ date: 2014-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit