cucumber-create-meta 4.0.0 → 5.0.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
  SHA256:
3
- metadata.gz: 9c0d4c7da171c38558ed7c0809aa059da8161aeeab9fc0f2a788f757712fc953
4
- data.tar.gz: 997e930fe502d8a6f58ab7e8489b4b677b077a8f123d4748c40971ac14a235a5
3
+ metadata.gz: 8f655f885d4b250da9d8923262231aca56d2c2aff33788fbfc55ed1c86318c58
4
+ data.tar.gz: 7cc5d5a2e4ac40b40652373ee8afd8a61a3db34be2e58780945b7361b82ce906
5
5
  SHA512:
6
- metadata.gz: 2a7eabe5cbfcae7db34f143aec073c0341f91e5e09266ad0b417e0419f10ef5daf9ddc1cedec8dabd12976d7f9b24adff217c5b6226511eac758e30aca880463
7
- data.tar.gz: 94c175d39941c886a7e8322a90f618747a5fffb148c06a3523034c0ff676a377efbd049f33fa7094270308690e9ec099c65c4aee180940262962ca5a92aa2b9c
6
+ metadata.gz: e743ddae1ad514729be26e52995f2ab9e5b82f4b29d0ca60c92d48df8a19befb0653476d29326a23c7dc1f1539629cb19f0dea57280d65c919451c1a577e8f72
7
+ data.tar.gz: 54ce5d5d9ed2a044f68749d0127c4f6e543982d53ecdd746e6c5347dee3f72ba245c1cfb0d10172c8057da259bd4d3c5188f3f03b6264f1a679e3dda4dd3b1b9
@@ -4,8 +4,8 @@
4
4
  "git": {
5
5
  "remote": "${BUILD_REPOSITORY_URI}",
6
6
  "revision": "${BUILD_SOURCEVERSION}",
7
- "branch": "${refbranch BUILD_SOURCEBRANCH}",
8
- "tag": "${reftag BUILD_SOURCEBRANCH}"
7
+ "branch": "${BUILD_SOURCEBRANCH/refs\/heads\/(.*)/\\1}",
8
+ "tag": "${BUILD_SOURCEBRANCH/refs\/tags\/(.*)/\\1}"
9
9
  }
10
10
  },
11
11
  "Bamboo": {
@@ -26,6 +26,15 @@
26
26
  "tag": "${BUDDY_EXECUTION_TAG}"
27
27
  }
28
28
  },
29
+ "Bitrise": {
30
+ "url": "${BITRISE_BUILD_URL}",
31
+ "git": {
32
+ "remote": "${GIT_REPOSITORY_URL}",
33
+ "revision": "${BITRISE_GIT_COMMIT}",
34
+ "branch": "${BITRISE_GIT_BRANCH}",
35
+ "tag": "${BITRISE_GIT_TAG}"
36
+ }
37
+ },
29
38
  "CircleCI": {
30
39
  "url": "${CIRCLE_BUILD_URL}",
31
40
  "git": {
@@ -35,7 +44,7 @@
35
44
  "tag": "${CIRCLE_TAG}"
36
45
  }
37
46
  },
38
- "CodeShip": {
47
+ "CodeFresh": {
39
48
  "url": "${CF_BUILD_URL}",
40
49
  "git": {
41
50
  "remote": "${CF_COMMIT_URL}",
@@ -44,13 +53,22 @@
44
53
  "tag": null
45
54
  }
46
55
  },
56
+ "CodeShip": {
57
+ "url": "${CI_BUILD_URL}",
58
+ "git": {
59
+ "remote": "${CI_PULL_REQUEST/(.*)\\/pull\\/\\d+/\\1.git}",
60
+ "revision": "${CI_COMMIT_ID}",
61
+ "branch": "${CI_BRANCH}",
62
+ "tag": null
63
+ }
64
+ },
47
65
  "GitHub Actions": {
48
66
  "url": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}",
49
67
  "git": {
50
68
  "remote": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git",
51
69
  "revision": "${GITHUB_SHA}",
52
- "branch": "${refbranch GITHUB_REF}",
53
- "tag": "${reftag GITHUB_REF}"
70
+ "branch": "${GITHUB_REF/refs\/heads\/(.*)/\\1}",
71
+ "tag": "${GITHUB_REF/refs\/tags\/(.*)/\\1}"
54
72
  }
55
73
  },
56
74
  "GitLab": {
@@ -63,16 +81,25 @@
63
81
  }
64
82
  },
65
83
  "GoCD": {
66
- "url": "${GO_SERVER_URL}/???",
84
+ "url": "${GO_SERVER_URL}/pipelines/${GO_PIPELINE_NAME}/${GO_PIPELINE_COUNTER}/${GO_STAGE_NAME}/${GO_STAGE_COUNTER}",
67
85
  "git": {
68
- "remote": null,
86
+ "remote": "${GO_SCM_*_PR_URL/(.*)\\/pull\\/\\d+/\\1.git}",
69
87
  "revision": "${GO_REVISION}",
70
- "branch": null,
88
+ "branch": "${GO_SCM_*_PR_BRANCH/.*:(.*)/\\1}",
89
+ "tag": null
90
+ }
91
+ },
92
+ "Jenkins": {
93
+ "url": "${BUILD_URL}",
94
+ "git": {
95
+ "remote": "${GIT_URL}",
96
+ "revision": "${GIT_COMMIT}",
97
+ "branch": "${GIT_LOCAL_BRANCH}",
71
98
  "tag": null
72
99
  }
73
100
  },
74
101
  "Semaphore": {
75
- "url": "${SEMAPHORE_ORGANIZATION_URL}/${}",
102
+ "url": "${SEMAPHORE_ORGANIZATION_URL}/jobs/${SEMAPHORE_JOB_ID}",
76
103
  "git": {
77
104
  "remote": "${SEMAPHORE_GIT_URL}",
78
105
  "revision": "${SEMAPHORE_GIT_SHA}",
@@ -1,32 +1,34 @@
1
1
  require 'uri'
2
- require 'cucumber/messages'
3
2
  require 'sys/uname'
4
3
  require 'json'
4
+ require 'cucumber/messages'
5
+ require 'cucumber/create_meta/variable_expression'
5
6
 
6
7
  module Cucumber
7
8
  module CreateMeta
9
+ extend Cucumber::CreateMeta::VariableExpression
8
10
  CI_DICT = JSON.parse(IO.read(File.join(File.dirname(__FILE__), "ciDict.json")))
9
11
 
10
12
  def create_meta(tool_name, tool_version, env = ENV)
11
- Cucumber::Messages::Meta.new(
13
+ {
12
14
  protocol_version: Cucumber::Messages::VERSION,
13
- implementation: Cucumber::Messages::Meta::Product.new(
15
+ implementation: {
14
16
  name: tool_name,
15
17
  version: tool_version
16
- ),
17
- runtime: Cucumber::Messages::Meta::Product.new(
18
+ },
19
+ runtime: {
18
20
  name: RUBY_ENGINE,
19
21
  version: RUBY_VERSION
20
- ),
21
- os: Cucumber::Messages::Meta::Product.new(
22
+ },
23
+ os: {
22
24
  name: RbConfig::CONFIG['target_os'],
23
25
  version: Sys::Uname.uname.version
24
- ),
25
- cpu: Cucumber::Messages::Meta::Product.new(
26
+ },
27
+ cpu: {
26
28
  name: RbConfig::CONFIG['target_cpu']
27
- ),
29
+ },
28
30
  ci: detect_ci(env)
29
- )
31
+ }
30
32
  end
31
33
 
32
34
  def detect_ci(env)
@@ -41,44 +43,16 @@ module Cucumber
41
43
  url = evaluate(ci_system['url'], env)
42
44
  return nil if url.nil?
43
45
 
44
- Cucumber::Messages::Meta::CI.new(
46
+ {
45
47
  url: url,
46
48
  name: ci_name,
47
- git: Cucumber::Messages::Meta::CI::Git.new(
49
+ git: {
48
50
  remote: remove_userinfo_from_url(evaluate(ci_system['git']['remote'], env)),
49
51
  revision: evaluate(ci_system['git']['revision'], env),
50
52
  branch: evaluate(ci_system['git']['branch'], env),
51
53
  tag: evaluate(ci_system['git']['tag'], env),
52
- )
53
- )
54
- end
55
-
56
- def evaluate(template, env)
57
- return nil if template.nil?
58
- begin
59
- template.gsub(/\${((refbranch|reftag)\s+)?([^\s}]+)(\s+\|\s+([^}]+))?}/) do
60
- func = $2
61
- variable = $3
62
- default_value = $5 == "" ? nil : $5
63
- value = env[variable] || default_value
64
-
65
- if func == 'refbranch'
66
- value = group1(value, /^refs\/heads\/(.*)/)
67
- elsif func == 'reftag'
68
- value = group1(value, /^refs\/tags\/(.*)/)
69
- end
70
- raise "Undefined variable: #{variable}" if value.nil?
71
- value
72
- end
73
- rescue
74
- nil
75
- end
76
- end
77
-
78
- def group1(value, regexp)
79
- m = value.match(regexp)
80
- raise "No match" if m.nil?
81
- m[1]
54
+ }.delete_if {|k,v| v.nil?}
55
+ }
82
56
  end
83
57
 
84
58
  def remove_userinfo_from_url(value)
@@ -92,6 +66,6 @@ module Cucumber
92
66
  end
93
67
  end
94
68
 
95
- module_function :create_meta, :detect_ci, :create_ci, :group1, :evaluate, :remove_userinfo_from_url
69
+ module_function :create_meta, :detect_ci, :create_ci, :remove_userinfo_from_url
96
70
  end
97
71
  end
@@ -0,0 +1,41 @@
1
+ module Cucumber
2
+ module CreateMeta
3
+ module VariableExpression
4
+ def evaluate(expression, env)
5
+ return nil if expression.nil?
6
+ begin
7
+ expression.gsub(/\${(.*?)(?:(?<!\\)\/(.*)\/(.*))?}/) do
8
+ variable = $1
9
+ pattern = $2
10
+ replacement = $3
11
+
12
+ value = get_value(variable, env)
13
+ raise "Undefined variable #{variable}" if value.nil?
14
+ if pattern.nil?
15
+ value
16
+ else
17
+ regexp = Regexp.new(pattern.gsub('\/', '/'))
18
+ match = value.match(regexp)
19
+ raise "No match for variable #{variable}" if match.nil?
20
+ match[1..-1].each_with_index do |group, i|
21
+ replacement = replacement.gsub("\\#{i+1}", group)
22
+ end
23
+ replacement
24
+ end
25
+ end
26
+ rescue
27
+ nil
28
+ end
29
+ end
30
+
31
+ def get_value(variable, env)
32
+ if variable.index('*')
33
+ env.each do |name, value|
34
+ return value if Regexp.new(variable.gsub('*', '.*')) =~ name
35
+ end
36
+ end
37
+ env[variable]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,16 +1,16 @@
1
1
  require 'cucumber/create_meta'
2
2
 
3
- describe 'createMeta' do
3
+ describe 'create_meta' do
4
4
  it 'generates a Meta message with platform information' do
5
5
  meta = Cucumber::CreateMeta.create_meta('cucumba-ruby', 'X.Y.Z')
6
6
 
7
- expect(meta.protocol_version).to match(/\d+\.\d+\.\d+/)
8
- expect(meta.implementation.name).to eq('cucumba-ruby')
9
- expect(meta.implementation.version).to eq('X.Y.Z')
10
- expect(meta.runtime.name).to match(/(jruby|ruby)/)
11
- expect(meta.runtime.version).to eq(RUBY_VERSION)
12
- expect(meta.os.name).to match(/.+/)
13
- expect(meta.os.version).to match(/.+/)
14
- expect(meta.cpu.name).to match(/.+/)
7
+ expect(meta[:protocol_version]).to match(/\d+\.\d+\.\d+/)
8
+ expect(meta[:implementation][:name]).to eq('cucumba-ruby')
9
+ expect(meta[:implementation][:version]).to eq('X.Y.Z')
10
+ expect(meta[:runtime][:name]).to match(/(jruby|ruby)/)
11
+ expect(meta[:runtime][:version]).to eq(RUBY_VERSION)
12
+ expect(meta[:os][:name]).to match(/.+/)
13
+ expect(meta[:os][:version]).to match(/.+/)
14
+ expect(meta[:cpu][:name]).to match(/.+/)
15
15
  end
16
16
  end
@@ -0,0 +1,38 @@
1
+ require 'cucumber/create_meta'
2
+
3
+ describe 'Cucumber::CreateMeta::VariableExpression.evaluate' do
4
+ include Cucumber::CreateMeta::VariableExpression
5
+
6
+ it 'returns nil when a variable is undefined' do
7
+ expression = "hello-${SOME_VAR}";
8
+ result = evaluate(expression, {});
9
+ expect(result).to eq(nil)
10
+ end
11
+
12
+ it 'gets a value without replacement' do
13
+ expression = "${SOME_VAR}";
14
+ result = evaluate(expression, {'SOME_VAR' => 'some_value'});
15
+ expect(result).to eq('some_value')
16
+ end
17
+
18
+ it 'captures a group' do
19
+ expression = "${SOME_REF/refs\/heads\/(.*)/\\1}";
20
+ result = evaluate(expression, {'SOME_REF' => 'refs/heads/main'});
21
+ expect(result).to eq('main')
22
+ end
23
+
24
+ it 'works with star wildcard in var' do
25
+ expression = "${GO_SCM_*_PR_BRANCH/.*:(.*)/\\1}";
26
+ result = evaluate(expression, {'GO_SCM_MY_MATERIAL_PR_BRANCH' => 'ashwankthkumar:feature-1'});
27
+ expect(result).to eq('feature-1')
28
+ end
29
+
30
+ it 'evaluates a complex expression' do
31
+ expression = "hello-${VAR1}-${VAR2/(.*) (.*)/\\2-\\1}-world";
32
+ result = evaluate(expression, {
33
+ 'VAR1' => 'amazing',
34
+ 'VAR2' => 'gorgeous beautiful'
35
+ })
36
+ expect(result).to eq('hello-amazing-beautiful-gorgeous-world')
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-create-meta
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Prêtre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-29 00:00:00.000000000 Z
11
+ date: 2021-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber-messages
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '15.0'
19
+ version: '16.0'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 15.0.0
22
+ version: 16.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '15.0'
29
+ version: '16.0'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 15.0.0
32
+ version: 16.0.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: sys-uname
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -99,8 +99,10 @@ files:
99
99
  - LICENSE
100
100
  - lib/cucumber/ciDict.json
101
101
  - lib/cucumber/create_meta.rb
102
+ - lib/cucumber/create_meta/variable_expression.rb
102
103
  - spec/capture_warnings.rb
103
104
  - spec/cucumber/create_meta_spec.rb
105
+ - spec/cucumber/evaluate_variable_expression_spec.rb
104
106
  - spec/cucumber/remove_userinfo_from_url_spec.rb
105
107
  homepage: https://github.com/cucumber/create-meta-ruby
106
108
  licenses:
@@ -130,8 +132,9 @@ requirements: []
130
132
  rubygems_version: 3.1.2
131
133
  signing_key:
132
134
  specification_version: 4
133
- summary: cucumber-create-meta-4.0.0
135
+ summary: cucumber-create-meta-5.0.0
134
136
  test_files:
135
137
  - spec/capture_warnings.rb
136
138
  - spec/cucumber/create_meta_spec.rb
139
+ - spec/cucumber/evaluate_variable_expression_spec.rb
137
140
  - spec/cucumber/remove_userinfo_from_url_spec.rb