cucumber-ci-environment 10.0.1 → 11.0.0

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
  SHA256:
3
- metadata.gz: 5dcc9cd3de17a82ace1e2cebe193a2a0591dacf3c1332f61d15fae86fa68f638
4
- data.tar.gz: 6c356bef412b0c4c05e363fd144a0a3b96b58ac5ef9225165c0d98beed44ec8a
3
+ metadata.gz: baf6a11cd50dfb9ae5bdf63a33db62ef25473ccdf61b63b978a8259e3a051a3f
4
+ data.tar.gz: c2c84999d1a4b6c2699fcfdcb0d9c60ea4c4a4ce119cc02e4438482a4b6e28c9
5
5
  SHA512:
6
- metadata.gz: 882d1dc8afcc9eb0fe94c06fa43c82bd283afa9c6dfbf870e81079624915b41efd3d4ff366fca5e3a62914ff4ea3fa53f3de6b9fe17a052e9ce23f5b1ad2dd8a
7
- data.tar.gz: ed7ecd3c4677181fbe32963c006893adfca74437abf0d47fedf62a77cd92b71e9c54f995ec10a1a16137a82ddd5bb01ba73a4fd1e3c394b4816dde4fb05b73c3
6
+ metadata.gz: be572aab3b81f6dcfacfae5382daf2dcaf4341583f53a51a3c20216aaa696101b24ec80017d4881af0e47df2d1714fe0b9de581bdaa44870d853e92b3c348648
7
+ data.tar.gz: ad45b5d985598d9eb75e0074962274fbda1a034d352129abd59006eb39b878aac0ec9e065877e439b86432092af35c9d81ecfa1d617d9acffdef25ef77fce814
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) Cucumber Ltd
3
+ Copyright (c) 2020 Cucumber Ltd and contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,29 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cucumber
2
4
  module CiEnvironment
3
5
  module VariableExpression
4
6
  def evaluate(expression, env)
5
7
  return nil if expression.nil?
8
+
6
9
  begin
7
10
  expression.gsub(/\${(.*?)(?:(?<!\\)\/(.*)\/(.*))?}/) do
8
- variable = $1
9
- pattern = $2
10
- replacement = $3
11
+ variable = Regexp.last_match(1)
12
+ pattern = Regexp.last_match(2)
13
+ replacement = Regexp.last_match(3)
11
14
 
12
15
  value = get_value(variable, env)
13
16
  raise "Undefined variable #{variable}" if value.nil?
17
+
14
18
  if pattern.nil?
15
19
  value
16
20
  else
17
21
  regexp = Regexp.new(pattern.gsub('\/', '/'))
18
22
  match = value.match(regexp)
19
23
  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)
24
+
25
+ match[1..].each_with_index do |group, i|
26
+ replacement = replacement.gsub("\\#{i + 1}", group)
22
27
  end
23
28
  replacement
24
29
  end
25
30
  end
26
- rescue
31
+ rescue StandardError
27
32
  nil
28
33
  end
29
34
  end
@@ -31,7 +36,7 @@ module Cucumber
31
36
  def get_value(variable, env)
32
37
  if variable.index('*')
33
38
  env.each do |name, value|
34
- return value if Regexp.new(variable.gsub('*', '.*')) =~ name
39
+ return value if Regexp.new(variable.gsub('*', '.*')).match?(name)
35
40
  end
36
41
  end
37
42
  env[variable]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
  require 'json'
3
5
  require 'cucumber/ci_environment/variable_expression'
@@ -7,8 +9,10 @@ module Cucumber
7
9
  extend VariableExpression
8
10
  CI_ENVIRONMENTS_PATH = File.join(File.dirname(__FILE__), 'ci_environment/CiEnvironments.json')
9
11
 
12
+ module_function
13
+
10
14
  def detect_ci_environment(env)
11
- ci_environments = JSON.parse(IO.read(CI_ENVIRONMENTS_PATH))
15
+ ci_environments = JSON.parse(File.read(CI_ENVIRONMENTS_PATH))
12
16
  ci_environments.each do |ci_environment|
13
17
  detected = detect(ci_environment, env)
14
18
  return detected unless detected.nil?
@@ -24,7 +28,7 @@ module Cucumber
24
28
  result = {
25
29
  name: ci_environment['name'],
26
30
  url: url,
27
- buildNumber: evaluate(ci_environment['buildNumber'], env),
31
+ buildNumber: evaluate(ci_environment['buildNumber'], env)
28
32
  }
29
33
 
30
34
  detected_git = detect_git(ci_environment, env)
@@ -41,7 +45,7 @@ module Cucumber
41
45
 
42
46
  git_info = {
43
47
  remote: remove_userinfo_from_url(remote),
44
- revision: revision,
48
+ revision: revision
45
49
  }
46
50
 
47
51
  tag = evaluate(ci_environment['git']['tag'], env)
@@ -52,15 +56,14 @@ module Cucumber
52
56
  end
53
57
 
54
58
  def detect_revision(ci_environment, env)
55
- if env['GITHUB_EVENT_NAME'] == 'pull_request'
56
- raise StandardError('GITHUB_EVENT_PATH not set') unless env['GITHUB_EVENT_PATH']
57
- event = JSON.parse(IO.read(env['GITHUB_EVENT_PATH']))
58
- revision = event['pull_request']['head']['sha'] rescue nil
59
- raise StandardError("Could not find .pull_request.head.sha in #{env['GITHUB_EVENT_PATH']}:\n#{JSON.pretty_generate(event)}") if revision.nil?
60
- return revision
61
- end
59
+ return evaluate(ci_environment['git']['revision'], env) unless env['GITHUB_EVENT_NAME'] == 'pull_request'
62
60
 
63
- return evaluate(ci_environment['git']['revision'], env)
61
+ raise StandardError('GITHUB_EVENT_PATH not set') unless env['GITHUB_EVENT_PATH']
62
+
63
+ event = JSON.parse(File.read(env['GITHUB_EVENT_PATH']))
64
+ event.dig('pull_request', 'head', 'sha').tap do |revision|
65
+ raise StandardError("Could not find .pull_request.head.sha in GITHUB_EVENT_PATH:\n#{JSON.pretty_generate(event)}") if revision.nil?
66
+ end
64
67
  end
65
68
 
66
69
  def remove_userinfo_from_url(value)
@@ -74,7 +77,5 @@ module Cucumber
74
77
  value
75
78
  end
76
79
  end
77
-
78
- module_function :detect_ci_environment, :detect, :detect_git, :detect_revision, :remove_userinfo_from_url
79
80
  end
80
81
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-ci-environment
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.1
4
+ version: 11.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Prêtre
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-01-15 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -16,56 +15,56 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '13.1'
18
+ version: '13.3'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '13.1'
25
+ version: '13.3'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rspec
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '3.12'
32
+ version: '3.13'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '3.12'
39
+ version: '3.13'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: rubocop
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: 1.44.0
46
+ version: 1.81.0
48
47
  type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: 1.44.0
53
+ version: 1.81.0
55
54
  - !ruby/object:Gem::Dependency
56
55
  name: rubocop-performance
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: 1.16.0
60
+ version: 1.23.0
62
61
  type: :development
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - "~>"
67
66
  - !ruby/object:Gem::Version
68
- version: 1.16.0
67
+ version: 1.23.0
69
68
  - !ruby/object:Gem::Dependency
70
69
  name: rubocop-rake
71
70
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +85,14 @@ dependencies:
86
85
  requirements:
87
86
  - - "~>"
88
87
  - !ruby/object:Gem::Version
89
- version: 2.15.0
88
+ version: 3.7.0
90
89
  type: :development
91
90
  prerelease: false
92
91
  version_requirements: !ruby/object:Gem::Requirement
93
92
  requirements:
94
93
  - - "~>"
95
94
  - !ruby/object:Gem::Version
96
- version: 2.15.0
95
+ version: 3.7.0
97
96
  description: Detect CI Environment from environment variables
98
97
  email: cukes@googlegroups.com
99
98
  executables: []
@@ -104,19 +103,13 @@ files:
104
103
  - lib/cucumber/ci_environment.rb
105
104
  - lib/cucumber/ci_environment/CiEnvironments.json
106
105
  - lib/cucumber/ci_environment/variable_expression.rb
107
- - spec/cucumber/ci_environment/ci_environment_spec.rb
108
- - spec/cucumber/ci_environment/evaluate_variable_expression_spec.rb
109
- - spec/cucumber/ci_environment/github_pull_request_integration_spec.rb
110
- - spec/cucumber/ci_environment/remove_userinfo_from_url_spec.rb
111
106
  homepage: https://github.com/cucumber/ci-environment
112
107
  licenses:
113
108
  - MIT
114
109
  metadata:
115
110
  bug_tracker_uri: https://github.com/cucumber/ci-environment/issues
116
111
  changelog_uri: https://github.com/cucumber/ci-environment/blob/main/CHANGELOG.md
117
- documentation_uri: https://cucumber.io/docs/gherkin/
118
112
  source_code_uri: https://github.com/cucumber/ci-environment/tree/main/ruby
119
- post_install_message:
120
113
  rdoc_options:
121
114
  - "--charset=UTF-8"
122
115
  require_paths:
@@ -125,19 +118,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
118
  requirements:
126
119
  - - ">="
127
120
  - !ruby/object:Gem::Version
128
- version: '2.6'
121
+ version: '3.2'
129
122
  required_rubygems_version: !ruby/object:Gem::Requirement
130
123
  requirements:
131
124
  - - ">="
132
125
  - !ruby/object:Gem::Version
133
- version: 3.0.3
126
+ version: 3.2.8
134
127
  requirements: []
135
- rubygems_version: 3.4.10
136
- signing_key:
128
+ rubygems_version: 3.6.9
137
129
  specification_version: 4
138
- summary: cucumber-ci-environment-10.0.1
139
- test_files:
140
- - spec/cucumber/ci_environment/ci_environment_spec.rb
141
- - spec/cucumber/ci_environment/evaluate_variable_expression_spec.rb
142
- - spec/cucumber/ci_environment/github_pull_request_integration_spec.rb
143
- - spec/cucumber/ci_environment/remove_userinfo_from_url_spec.rb
130
+ summary: cucumber-ci-environment-11.0.0
131
+ test_files: []
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cucumber/ci_environment'
4
- require 'json'
5
-
6
- describe 'detect_ci_environment' do
7
- Dir.glob('../testdata/*.txt') do |test_data_file|
8
- context "with #{File.basename(test_data_file, '.txt')}" do
9
- subject { JSON.parse(ci_environment.to_json) }
10
-
11
- let(:ci_environment) { Cucumber::CiEnvironment.detect_ci_environment(env) }
12
- let(:env) { Hash[entries] }
13
- let(:entries) { env_data.split(/\n/).map { |line| line.split(/=/) } }
14
- let(:env_data) { IO.read(test_data_file) }
15
-
16
- let(:expected_json) { File.read("#{test_data_file}.json") }
17
-
18
- it { is_expected.to eq JSON.parse(expected_json) }
19
- end
20
- end
21
-
22
- context 'with no CI environment' do
23
- subject { JSON.parse(ci_environment.to_json) }
24
- let(:ci_environment) { Cucumber::CiEnvironment.detect_ci_environment(env) }
25
- let(:env) { {} }
26
-
27
- it { is_expected.to be_nil }
28
- end
29
- end
@@ -1,38 +0,0 @@
1
- require 'cucumber/ci_environment'
2
-
3
- describe 'Cucumber::CiEnvironment::VariableExpression.evaluate' do
4
- include Cucumber::CiEnvironment::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
@@ -1,10 +0,0 @@
1
- describe 'GitHub' do
2
- if (ENV['GITHUB_EVENT_NAME'] == 'pull_request')
3
- it 'detects the correct revision for pull requests' do
4
- ci_environment = Cucumber::CiEnvironment.detect_ci_environment(ENV)
5
- expect(ci_environment).to be_truthy
6
- puts ("Manually verify that the revision is correct");
7
- p ci_environment
8
- end
9
- end
10
- end
@@ -1,29 +0,0 @@
1
- require 'cucumber/ci_environment'
2
-
3
- describe 'remove_user_info_from_url' do
4
- it 'returns nil for nil' do
5
- expect(Cucumber::CiEnvironment.remove_userinfo_from_url(nil)).to be_nil
6
- end
7
-
8
- it 'returns empty string for empty string' do
9
- expect(Cucumber::CiEnvironment.remove_userinfo_from_url('')).to eq('')
10
- end
11
-
12
- it 'leaves the data intact when no sensitive information is detected' do
13
- expect(Cucumber::CiEnvironment.remove_userinfo_from_url('pretty safe')).to eq('pretty safe')
14
- end
15
-
16
- context 'with URLs' do
17
- it 'leaves intact when no password is found' do
18
- expect(Cucumber::CiEnvironment.remove_userinfo_from_url('https://example.com/git/repo.git')).to eq('https://example.com/git/repo.git')
19
- end
20
-
21
- it 'removes credentials when found' do
22
- expect(Cucumber::CiEnvironment.remove_userinfo_from_url('http://login@example.com/git/repo.git')).to eq('http://example.com/git/repo.git')
23
- end
24
-
25
- it 'removes credentials and passwords when found' do
26
- expect(Cucumber::CiEnvironment.remove_userinfo_from_url('ssh://login:password@example.com/git/repo.git')).to eq('ssh://example.com/git/repo.git')
27
- end
28
- end
29
- end