cucumber-ci-environment 9.0.1 → 9.0.4

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: 8b113a16cc3df5fa4c163edac4bed8dc9cc479b03d7bc873d0e35e551b17e133
4
- data.tar.gz: b350572faa0a9f959d12dfbda6b3b323cf3d18e9a46635d813af29a808f6dd27
3
+ metadata.gz: c1cc542bd3cd0d027c8a6c7bcd3283540ad5422dffadef3e7dd45782ba1b210d
4
+ data.tar.gz: 76d7a0f4c685b44b0a4a4fcb63c9c372cb2e1675daa9459574cac6180d67418a
5
5
  SHA512:
6
- metadata.gz: b094712321f9251fab4120c75ed7fd261e187cced6aea4ed0e5fffaf8703b9dc679f5b0a7eb9979c6ff66fe7d40427fface9b156940d2f6c120b9d2785948475
7
- data.tar.gz: 71a3c6542c46d9064cc4f276378ca4c9296cbff2be31a7a6073bf78d36f74c88ef23affc4f941eedcd35ca25cc4bb1e155f27c83b87f86dd5e344010a9e8873c
6
+ metadata.gz: 3f4d2fa7fa571d1ea22a28e2104ad0c79bd638fa82bbfc7455d847aa7f6e55c9e72360166f5632d186babcbd6dca67c0fd983c4b9671abb37248f88876d55fa9
7
+ data.tar.gz: c8f5b94aec624580f1a1585139b8ca2bd4ff000498eea1e7f93445fb862ffa3ab1e5d1719b45edb734df3b3cfb660c05a2852be98606113bd884da72b84b92a1
@@ -80,7 +80,7 @@
80
80
  "git": {
81
81
  "remote": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git",
82
82
  "revision": "${GITHUB_SHA}",
83
- "branch": "${GITHUB_REF/refs\/heads\/(.*)/\\1}",
83
+ "branch": "${GITHUB_HEAD_REF}",
84
84
  "tag": "${GITHUB_REF/refs\/tags\/(.*)/\\1}"
85
85
  }
86
86
  },
@@ -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, file_reader = IO.method(:read))
11
- ci_environments = JSON.parse(file_reader.call(CI_ENVIRONMENTS_PATH))
10
+ def detect_ci_environment(env)
11
+ ci_environments = JSON.parse(IO.read(CI_ENVIRONMENTS_PATH))
12
12
  ci_environments.each do |ci_environment|
13
- detected = detect(ci_environment, env, file_reader)
13
+ detected = detect(ci_environment, env)
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, file_reader)
20
+ def detect(ci_environment, env)
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, file_reader)
30
+ detected_git = detect_git(ci_environment, env)
31
31
  result[:git] = detected_git if detected_git
32
32
  result
33
33
  end
34
34
 
35
- def detect_git(ci_environment, env, file_reader)
36
- revision = detect_revision(ci_environment, env, file_reader)
35
+ def detect_git(ci_environment, env)
36
+ revision = detect_revision(ci_environment, env)
37
37
  return nil if revision.nil?
38
38
 
39
39
  remote = evaluate(ci_environment['git']['remote'], env)
@@ -51,12 +51,13 @@ module Cucumber
51
51
  git_info
52
52
  end
53
53
 
54
- def detect_revision(ci_environment, env, file_reader)
54
+ def detect_revision(ci_environment, env)
55
55
  if env['GITHUB_EVENT_NAME'] == 'pull_request'
56
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('GITHUB_EVENT_PATH not set') unless event['before']
59
- return event['before']
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
60
61
  end
61
62
 
62
63
  return evaluate(ci_environment['git']['revision'], env)
@@ -8,12 +8,7 @@ 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
- def mock_reader(path)
12
- return '{"before": "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)) }
11
+ let(:ci_environment) { Cucumber::CiEnvironment.detect_ci_environment(env) }
17
12
  let(:env) { Hash[entries] }
18
13
  let(:entries) { env_data.split(/\n/).map { |line| line.split(/=/) } }
19
14
  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: 9.0.1
4
+ version: 9.0.4
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-03-04 00:00:00.000000000 Z
11
+ date: 2022-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -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-9.0.1
96
+ summary: cucumber-ci-environment-9.0.4
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