cucumber-ci-environment 8.1.0 → 9.0.2

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: 3d3ea98e767664065044ea095d2b3d12d3f8c8a63f02af5e2881f9fff82b64df
4
- data.tar.gz: 9f5da9baf7e74e81d6ec5f02dbaa0601457d8e22f81eeba355b07a4105ab4b26
3
+ metadata.gz: 1fa280ae7a64a91f8851d28e4419f2d391ba080e0e511ed045594175d58c8225
4
+ data.tar.gz: 9bbe09efed429d2bcad1852c934357d0706a663f6450c33a9dadc62e990e005f
5
5
  SHA512:
6
- metadata.gz: ab82395b61fcdfcb5c65f75fbc2aee237a4d699cb1aed9344e99f38ff90d40ecef5e8bec88b3ca787c5b3e8096e23fa05e786a2ed43efb83a2bdc87d236a089e
7
- data.tar.gz: ca131069f18511eb234ff5f91465119a1451a176440841d191041b4eccd6c0b4661afe239e7c0ba43843edea281c82e417d5520d3d83302bf02e72d96d68f889
6
+ metadata.gz: 7fde55b617bd13cfbdc6766dcf75d67cc6f4cfe0ac9e67d906194ff8b5f7ca1422227dce609435ee420a95fd24048a5d606861c5e4d5a1659f257c88a63439d5
7
+ data.tar.gz: 0c26bd5ec292118386175d6a2aa707fc025d2994cd516184cdced9aadcbd215d259c3c442181decdf7c781ac34dcbd10b1b8bf8f2a15c049e8f4411ae0437337
@@ -17,8 +17,7 @@
17
17
  "git": {
18
18
  "remote": "${bamboo_planRepository_repositoryUrl}",
19
19
  "revision": "${bamboo_planRepository_revision}",
20
- "branch": "${bamboo_planRepository_branch}",
21
- "tag": null
20
+ "branch": "${bamboo_planRepository_branch}"
22
21
  }
23
22
  },
24
23
  {
@@ -61,8 +60,7 @@
61
60
  "git": {
62
61
  "remote": "${CF_COMMIT_URL/(.*)\\/commit.+$/\\1}.git",
63
62
  "revision": "${CF_REVISION}",
64
- "branch": "${CF_BRANCH}",
65
- "tag": null
63
+ "branch": "${CF_BRANCH}"
66
64
  }
67
65
  },
68
66
  {
@@ -72,8 +70,7 @@
72
70
  "git": {
73
71
  "remote": "${CI_PULL_REQUEST/(.*)\\/pull\\/\\d+/\\1.git}",
74
72
  "revision": "${CI_COMMIT_ID}",
75
- "branch": "${CI_BRANCH}",
76
- "tag": null
73
+ "branch": "${CI_BRANCH}"
77
74
  }
78
75
  },
79
76
  {
@@ -83,7 +80,7 @@
83
80
  "git": {
84
81
  "remote": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git",
85
82
  "revision": "${GITHUB_SHA}",
86
- "branch": "${GITHUB_REF/refs\/heads\/(.*)/\\1}",
83
+ "branch": "${GITHUB_HEAD_REF}",
87
84
  "tag": "${GITHUB_REF/refs\/tags\/(.*)/\\1}"
88
85
  }
89
86
  },
@@ -105,8 +102,7 @@
105
102
  "git": {
106
103
  "remote": "${GO_SCM_*_PR_URL/(.*)\\/pull\\/\\d+/\\1.git}",
107
104
  "revision": "${GO_REVISION}",
108
- "branch": "${GO_SCM_*_PR_BRANCH/.*:(.*)/\\1}",
109
- "tag": null
105
+ "branch": "${GO_SCM_*_PR_BRANCH/.*:(.*)/\\1}"
110
106
  }
111
107
  },
112
108
  {
@@ -116,8 +112,7 @@
116
112
  "git": {
117
113
  "remote": "${GIT_URL}",
118
114
  "revision": "${GIT_COMMIT}",
119
- "branch": "${GIT_LOCAL_BRANCH}",
120
- "tag": null
115
+ "branch": "${GIT_LOCAL_BRANCH}"
121
116
  }
122
117
  },
123
118
  {
@@ -149,8 +144,7 @@
149
144
  "git": {
150
145
  "remote": "https://${WERCKER_GIT_DOMAIN}/${WERCKER_GIT_OWNER}/${WERCKER_GIT_REPOSITORY}.git",
151
146
  "revision": "${WERCKER_GIT_COMMIT}",
152
- "branch": "${WERCKER_GIT_BRANCH}",
153
- "tag": null
147
+ "branch": "${WERCKER_GIT_BRANCH}"
154
148
  }
155
149
  }
156
150
  ]
@@ -7,17 +7,17 @@ module Cucumber
7
7
  extend VariableExpression
8
8
  CI_ENVIRONMENTS_PATH = File.join(File.dirname(__FILE__), 'ci_environment/CiEnvironments.json')
9
9
 
10
- def detect_ci_environment(env)
11
- ci_environments = JSON.parse(IO.read(CI_ENVIRONMENTS_PATH))
10
+ def detect_ci_environment(env, file_reader = IO.method(:read))
11
+ ci_environments = JSON.parse(file_reader.call(CI_ENVIRONMENTS_PATH))
12
12
  ci_environments.each do |ci_environment|
13
- detected = detect(ci_environment, env)
13
+ detected = detect(ci_environment, env, file_reader)
14
14
  return detected unless detected.nil?
15
15
  end
16
16
 
17
17
  nil
18
18
  end
19
19
 
20
- def detect(ci_environment, env)
20
+ def detect(ci_environment, env, file_reader)
21
21
  url = evaluate(ci_environment['url'], env)
22
22
  return nil if url.nil?
23
23
 
@@ -27,13 +27,13 @@ module Cucumber
27
27
  buildNumber: evaluate(ci_environment['buildNumber'], env),
28
28
  }
29
29
 
30
- detected_git = detect_git(ci_environment, env)
30
+ detected_git = detect_git(ci_environment, env, file_reader)
31
31
  result[:git] = detected_git if detected_git
32
32
  result
33
33
  end
34
34
 
35
- def detect_git(ci_environment, env)
36
- revision = evaluate(ci_environment['git']['revision'], env)
35
+ def detect_git(ci_environment, env, file_reader)
36
+ revision = detect_revision(ci_environment, env, file_reader)
37
37
  return nil if revision.nil?
38
38
 
39
39
  remote = evaluate(ci_environment['git']['remote'], env)
@@ -51,6 +51,17 @@ module Cucumber
51
51
  git_info
52
52
  end
53
53
 
54
+ def detect_revision(ci_environment, env, file_reader)
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(file_reader.call(env['GITHUB_EVENT_PATH']))
58
+ raise StandardError("No after property in #{env['GITHUB_EVENT_PATH']}:\n#{JSON.pretty_generate(event)}") unless event['after']
59
+ return event['after']
60
+ end
61
+
62
+ return evaluate(ci_environment['git']['revision'], env)
63
+ end
64
+
54
65
  def remove_userinfo_from_url(value)
55
66
  return nil if value.nil?
56
67
 
@@ -63,6 +74,6 @@ module Cucumber
63
74
  end
64
75
  end
65
76
 
66
- module_function :detect_ci_environment, :detect, :detect_git, :remove_userinfo_from_url
77
+ module_function :detect_ci_environment, :detect, :detect_git, :detect_revision, :remove_userinfo_from_url
67
78
  end
68
79
  end
@@ -8,7 +8,12 @@ describe 'detect_ci_environment' do
8
8
  context "with #{File.basename(test_data_file, '.txt')}" do
9
9
  subject { JSON.parse(ci_environment.to_json) }
10
10
 
11
- let(:ci_environment) { Cucumber::CiEnvironment.detect_ci_environment(env) }
11
+ def mock_reader(path)
12
+ return '{"after": "2436f28fad432a895bfc595bce16e907144b0dc3"}' if path.end_with?('_github_workflow/event.json')
13
+ IO.read(path)
14
+ end
15
+
16
+ let(:ci_environment) { Cucumber::CiEnvironment.detect_ci_environment(env, method(:mock_reader)) }
12
17
  let(:env) { Hash[entries] }
13
18
  let(:entries) { env_data.split(/\n/).map { |line| line.split(/=/) } }
14
19
  let(:env_data) { IO.read(test_data_file) }
@@ -0,0 +1,10 @@
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-ci-environment
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.0
4
+ version: 9.0.2
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: 2022-01-02 00:00:00.000000000 Z
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -36,20 +36,20 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '3.10'
39
+ version: '3.11'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 3.10.0
42
+ version: 3.11.0
43
43
  type: :development
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '3.10'
49
+ version: '3.11'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 3.10.0
52
+ version: 3.11.0
53
53
  description: Detect CI Environment from environment variables
54
54
  email: cukes@googlegroups.com
55
55
  executables: []
@@ -63,6 +63,7 @@ files:
63
63
  - spec/capture_warnings.rb
64
64
  - spec/cucumber/ci_environment/ci_environment_spec.rb
65
65
  - spec/cucumber/ci_environment/evaluate_variable_expression_spec.rb
66
+ - spec/cucumber/ci_environment/github_pull_request_integration_spec.rb
66
67
  - spec/cucumber/ci_environment/remove_userinfo_from_url_spec.rb
67
68
  homepage: https://github.com/cucumber/ci-environment
68
69
  licenses:
@@ -92,9 +93,10 @@ requirements: []
92
93
  rubygems_version: 3.2.32
93
94
  signing_key:
94
95
  specification_version: 4
95
- summary: cucumber-ci-environment-8.1.0
96
+ summary: cucumber-ci-environment-9.0.2
96
97
  test_files:
97
98
  - spec/capture_warnings.rb
98
99
  - spec/cucumber/ci_environment/ci_environment_spec.rb
99
100
  - spec/cucumber/ci_environment/evaluate_variable_expression_spec.rb
101
+ - spec/cucumber/ci_environment/github_pull_request_integration_spec.rb
100
102
  - spec/cucumber/ci_environment/remove_userinfo_from_url_spec.rb