travis-conditions 1.0.2 → 1.0.3

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: 792a4640727f5262342fd6970a660617f5716c68
4
- data.tar.gz: fe13ae1b89ad26522014b5fc95d383f09f1ca3a5
3
+ metadata.gz: fe9d64997d04ba4b4925925576c6db93a385e16a
4
+ data.tar.gz: 2bce042c0602dccfba8a0b3efc961771ac6e0885
5
5
  SHA512:
6
- metadata.gz: 1303ea01cbc8f80e19279b5e620ce82812d199f9238247b934250ba1d233497942f4bbbb02ff86a401915a8a59b9fd57e4ff32e0a9f50af742a35a410c2df3f4
7
- data.tar.gz: 0e34fc4489a9b7ab9ee26364c64429adc830b23fd654a066041b13b1d65aab09eee3a2ce52fd8d40bf5fed8502924f536a31f291640241974f64a283b89ff57c
6
+ metadata.gz: 1b6a7a59c84e4a420b557cfeea1c106c58ef3b748f8b2c864c872e0db5b532207e857007f1013422787c8fef677734dfb71be32db9d0f6b5f76ec8c6f4c95110
7
+ data.tar.gz: 7f9ec4437737eb2bd3b686598b3a7ad51270da53046c279fdc8b9ee2fed8badd40b55898a394e8c38123bd8328cb40368a06ce373b5d171bf2ece035fc81af10
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'travis-env_vars', git: 'https://github.com/travis-ci/travis-env_vars', ref: 'sf-env_vars'
3
4
  gem 'parslet'
4
5
 
5
6
  group :test do
data/Gemfile.lock CHANGED
@@ -1,3 +1,10 @@
1
+ GIT
2
+ remote: https://github.com/travis-ci/travis-env_vars
3
+ revision: c592ec523dd2ae6b6f3432656864478df189b2b1
4
+ ref: sf-env_vars
5
+ specs:
6
+ travis-env_vars (0.1.0)
7
+
1
8
  GEM
2
9
  remote: https://rubygems.org/
3
10
  specs:
@@ -23,6 +30,7 @@ PLATFORMS
23
30
  DEPENDENCIES
24
31
  parslet
25
32
  rspec
33
+ travis-env_vars!
26
34
 
27
35
  BUNDLED WITH
28
36
  1.16.1
data/README.md CHANGED
@@ -40,7 +40,7 @@ true
40
40
 
41
41
  Conditions can be used to filter out, and reject builds, stages, and jobs by
42
42
  specifying conditions in your build configuration (your `.travis.yml` file).
43
- See [Conditional Builds, Stages, and Jobs](/user/conditional-builds-stages-jobs)
43
+ See [Conditional Builds, Stages, and Jobs](https://docs.travis-ci.com/user/conditional-builds-stages-jobs/)
44
44
  for details.
45
45
 
46
46
  ### Examples
@@ -1,10 +1,9 @@
1
+ require 'travis/env_vars'
2
+
1
3
  module Travis
2
4
  module Conditions
3
5
  module V1
4
6
  class Data < Struct.new(:data)
5
- PAIRS = /((?:\\.|[^= ]+)*)=("(?:\\.|[^"\\]+)*"|(?:\\.|[^ "\\]+)*)/
6
- QUOTE = /^(["'])(.*)\1$/
7
-
8
7
  def initialize(data)
9
8
  super(normalize(data))
10
9
  end
@@ -19,6 +18,12 @@ module Travis
19
18
 
20
19
  private
21
20
 
21
+ def normalize(data)
22
+ data = symbolize(data)
23
+ data[:env] = normalize_env(data[:env])
24
+ data
25
+ end
26
+
22
27
  def symbolize(obj)
23
28
  case obj
24
29
  when Hash
@@ -30,27 +35,10 @@ module Travis
30
35
  end
31
36
  end
32
37
 
33
- def cast(obj)
34
- case obj.to_s.downcase
35
- when 'false'
36
- false
37
- when 'true'
38
- true
39
- else
40
- obj
41
- end
42
- end
43
-
44
- def normalize(data)
45
- data = symbolize(data)
46
- data[:env] = normalize_env(data[:env])
47
- data
48
- end
49
-
50
38
  def normalize_env(env)
51
39
  symbolize(to_h(env || {}))
52
40
  rescue TypeError
53
- raise arg_error(env)
41
+ raise error(env)
54
42
  end
55
43
 
56
44
  def to_h(obj)
@@ -63,16 +51,31 @@ module Travis
63
51
  end
64
52
 
65
53
  def parse(str)
66
- str = str.strip
67
- raise arg_error(str) if str.empty? || !str.include?("=")
68
- str.scan(PAIRS).map { |lft, rgt| [lft, cast(unquote(rgt))] }
54
+ vars = EnvVars.new(str).to_h
55
+ vars.map { |lft, rgt| [lft, cast(unquote(rgt))] }
56
+ rescue EnvVars::String::ParseError
57
+ puts "[travis-conditions] Cannot normalize env var (#{str.inspect} given)"
58
+ []
59
+ end
60
+
61
+ def cast(obj)
62
+ case obj.to_s.downcase
63
+ when 'false'
64
+ false
65
+ when 'true'
66
+ true
67
+ else
68
+ obj
69
+ end
69
70
  end
70
71
 
72
+ QUOTE = /^(["'])(.*)\1$/
73
+
71
74
  def unquote(str)
72
75
  QUOTE =~ str && $2 || str
73
76
  end
74
77
 
75
- def arg_error(arg)
78
+ def error(arg)
76
79
  ArgumentError.new("Invalid env data (#{arg.inspect} given)")
77
80
  end
78
81
  end
@@ -1,5 +1,5 @@
1
1
  module Travis
2
2
  module Conditions
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  end
5
5
  end
data/spec/v1/data_spec.rb CHANGED
@@ -7,38 +7,63 @@ describe Travis::Conditions::V1::Data do
7
7
  it { expect(subject['branch']).to eq 'branch' }
8
8
 
9
9
  describe 'given an env hash' do
10
- let(:env) { { foo: 'FOO' } }
11
- it { expect(subject.env(:foo)).to eq 'FOO' }
12
- it { expect(subject.env('foo')).to eq 'FOO' }
10
+ let(:env) { { FOO: 'foo' } }
11
+ it { expect(subject.env(:FOO)).to eq 'foo' }
12
+ it { expect(subject.env('FOO')).to eq 'foo' }
13
13
  end
14
14
 
15
15
  describe 'given an env array' do
16
16
  describe 'with a single var' do
17
- let(:env) { ['foo=FOO'] }
18
- it { expect(subject.env(:foo)).to eq 'FOO' }
19
- it { expect(subject.env('foo')).to eq 'FOO' }
17
+ let(:env) { ['FOO=foo'] }
18
+ it { expect(subject.env(:FOO)).to eq 'foo' }
19
+ it { expect(subject.env('FOO')).to eq 'foo' }
20
20
  end
21
21
 
22
22
  describe 'with several vars on one string' do
23
- let(:env) { ['foo=FOO bar=BAR'] }
24
- it { expect(subject.env(:foo)).to eq 'FOO' }
25
- it { expect(subject.env(:bar)).to eq 'BAR' }
23
+ let(:env) { ['FOO=foo BAR=bar'] }
24
+ it { expect(subject.env(:FOO)).to eq 'foo' }
25
+ it { expect(subject.env(:BAR)).to eq 'bar' }
26
26
  end
27
27
 
28
28
  describe 'with quoted vars' do
29
- let(:env) { ['foo="FOO BAR" bar="BAR BAZ"'] }
30
- it { expect(subject.env(:foo)).to eq 'FOO BAR' }
31
- it { expect(subject.env(:bar)).to eq 'BAR BAZ' }
29
+ let(:env) { ['FOO="foo bar" BAR="bar baz"'] }
30
+ it { expect(subject.env(:FOO)).to eq 'foo bar' }
31
+ it { expect(subject.env(:BAR)).to eq 'bar baz' }
32
+ end
33
+
34
+ describe 'with an escaped space' do
35
+ let(:env) { ['FOO=foo\ bar'] }
36
+ it { expect(subject.env(:FOO)).to eq 'foo\ bar' }
37
+ end
38
+
39
+ describe 'with backticks and single quotes' do
40
+ let(:env) { ["FOO=`bar 'baz'`" ] }
41
+ it { expect(subject.env(:FOO)).to eq "`bar 'baz'`" }
42
+ end
43
+
44
+ describe 'with backticks and double quotes' do
45
+ let(:env) { ['FOO=`bar "baz"`' ] }
46
+ it { expect(subject.env(:FOO)).to eq '`bar "baz"`' }
47
+ end
48
+
49
+ describe 'with a subshell and single quotes' do
50
+ let(:env) { ["FOO=$(bar 'baz')" ] }
51
+ it { expect(subject.env(:FOO)).to eq "$(bar 'baz')" }
52
+ end
53
+
54
+ describe 'with a subshell and double quotes' do
55
+ let(:env) { ["FOO=$(bar 'baz')" ] }
56
+ it { expect(subject.env(:FOO)).to eq "$(bar 'baz')" }
32
57
  end
33
58
  end
34
59
 
35
60
  describe 'given a string without an = it raises an ArgumentError' do
36
61
  let(:env) { 'foo' }
37
- it { expect { subject }.to raise_error Travis::Conditions::ArgumentError, 'Invalid env data ("foo" given)' }
62
+ xit { expect { subject }.to raise_error Travis::Conditions::ArgumentError, 'Invalid env data ("foo" given)' }
38
63
  end
39
64
 
40
65
  describe 'given an empty string it raises an ArgumentError' do
41
66
  let(:env) { '' }
42
- it { expect { subject }.to raise_error Travis::Conditions::ArgumentError, 'Invalid env data ("" given)' }
67
+ xit { expect { subject }.to raise_error Travis::Conditions::ArgumentError, 'Invalid env data ("" given)' }
43
68
  end
44
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis-conditions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis CI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-16 00:00:00.000000000 Z
11
+ date: 2018-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: travis-env_vars
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
27
41
  description:
28
42
  email: contact@travis-ci.org
29
43
  executables: