knapsack_pro 3.10.0 → 3.11.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: 5a557f5e56b1700cf9391abc05a6ce45321dcc2a79812927d1c78dbecf00dd09
4
- data.tar.gz: 908a4ac991778a85e3168fb5db8f06d77573a79e182cfed1e48b719037bf68dd
3
+ metadata.gz: a43c73ef1e2535db96433d5a39659b4a02cf0ecb9baac50f5effef464c0638de
4
+ data.tar.gz: 49739064aea9230e17d9719bd3ee8bff27dead716bf388530eb4c9e5e079d6e1
5
5
  SHA512:
6
- metadata.gz: cbba79dc7e72bf2785654ab7cf82d39cfbd34ff44395dd378c24a77ad283c7c7e243f3daf84e99206f439a4535b539dd20cd183454682ba38719cd24e0da7a5b
7
- data.tar.gz: e326a929107db8167d023b12c133edada0b849808f0b848e6eb235d5156f588e5bd6a347637fd7e689e844620717f178ca7c7dd395de000e19bc225f423d6666
6
+ metadata.gz: d019adc9a5a78d7b795e380828a5be81eca28702aba936c1fb6759b7294bffe3e90dfcc7ab009c844863cfbe4ead8c9a1bf1159a89dee44305f9d50803d798b7
7
+ data.tar.gz: c92054f2b1cdc5c842e0130d89ee8f9ebc9a44985721718b9af48e3c9e6db9f3e391fe2a8ead8ad8ebf040f0526a3ce4600014b4bbf62d1f43952c4b5e24025f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ### 3.11.0
4
+
5
+ * Send distinguishable user seat info over to the API
6
+
7
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/192
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v3.10.0...v3.11.0
10
+
3
11
  ### 3.10.0
4
12
 
5
13
  * Remove Solano CI and Snap CI support because they do not exist anymore
@@ -15,6 +15,7 @@ module KnapsackPro
15
15
  :node_total => args.fetch(:node_total),
16
16
  :node_index => args.fetch(:node_index),
17
17
  :ci_build_id => KnapsackPro::Config::Env.ci_node_build_id,
18
+ :user_seat => KnapsackPro::Config::Env.user_seat_hash,
18
19
  }
19
20
 
20
21
  unless request_hash[:cache_read_attempt]
@@ -16,6 +16,7 @@ module KnapsackPro
16
16
  :node_total => args.fetch(:node_total),
17
17
  :node_index => args.fetch(:node_index),
18
18
  :node_build_id => KnapsackPro::Config::Env.ci_node_build_id,
19
+ :user_seat => KnapsackPro::Config::Env.user_seat_hash,
19
20
  }
20
21
 
21
22
  if request_hash[:can_initialize_queue] && !request_hash[:attempt_connect_to_queue]
@@ -22,6 +22,9 @@ module KnapsackPro
22
22
 
23
23
  def project_dir
24
24
  end
25
+
26
+ def user_seat
27
+ end
25
28
  end
26
29
  end
27
30
  end
@@ -29,6 +29,10 @@ module KnapsackPro
29
29
  def project_dir
30
30
  ENV['BUILDKITE_BUILD_CHECKOUT_PATH']
31
31
  end
32
+
33
+ def user_seat
34
+ ENV['BUILDKITE_BUILD_AUTHOR'] || ENV['BUILDKITE_BUILD_CREATOR']
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -25,6 +25,10 @@ module KnapsackPro
25
25
  def project_dir
26
26
  ENV['CIRCLE_WORKING_DIRECTORY']
27
27
  end
28
+
29
+ def user_seat
30
+ ENV['CIRCLE_USERNAME'] || ENV['CIRCLE_PR_USERNAME']
31
+ end
28
32
  end
29
33
  end
30
34
  end
@@ -29,6 +29,10 @@ module KnapsackPro
29
29
  def project_dir
30
30
  ENV['GITHUB_WORKSPACE']
31
31
  end
32
+
33
+ def user_seat
34
+ ENV['GITHUB_ACTOR']
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -16,7 +16,7 @@ module KnapsackPro
16
16
 
17
17
  def node_build_id
18
18
  ENV['CI_PIPELINE_ID'] || # Gitlab Release 9.0+
19
- ENV['CI_BUILD_ID'] # Gitlab Release 8.x
19
+ ENV['CI_BUILD_ID'] # Gitlab Release 8.x
20
20
  end
21
21
 
22
22
  def commit_hash
@@ -32,6 +32,11 @@ module KnapsackPro
32
32
  def project_dir
33
33
  ENV['CI_PROJECT_DIR']
34
34
  end
35
+
36
+ def user_seat
37
+ ENV['GITLAB_USER_NAME'] || # Gitlab Release 10.0
38
+ ENV['GITLAB_USER_EMAIL'] # Gitlab Release 8.12
39
+ end
35
40
  end
36
41
  end
37
42
  end
@@ -58,6 +58,16 @@ module KnapsackPro
58
58
  ci_env_for(:project_dir)
59
59
  end
60
60
 
61
+ def user_seat
62
+ ENV['KNAPSACK_PRO_USER_SEAT'] ||
63
+ ci_env_for(:user_seat)
64
+ end
65
+
66
+ def user_seat_hash
67
+ return unless user_seat
68
+ Digest::SHA2.hexdigest(user_seat)
69
+ end
70
+
61
71
  def test_file_pattern
62
72
  ENV['KNAPSACK_PRO_TEST_FILE_PATTERN']
63
73
  end
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '3.10.0'
2
+ VERSION = '3.11.0'
3
3
  end
@@ -6,6 +6,7 @@ describe KnapsackPro::Client::API::V1::BuildDistributions do
6
6
  let(:node_total) { double }
7
7
  let(:node_index) { double }
8
8
  let(:ci_build_id) { double }
9
+ let(:user_seat_hash) { double }
9
10
  let(:test_files) { double }
10
11
 
11
12
  subject do
@@ -22,6 +23,7 @@ describe KnapsackPro::Client::API::V1::BuildDistributions do
22
23
  before do
23
24
  expect(KnapsackPro::Config::Env).to receive(:fixed_test_suite_split).and_return(fixed_test_suite_split)
24
25
  expect(KnapsackPro::Config::Env).to receive(:ci_node_build_id).and_return(ci_build_id)
26
+ expect(KnapsackPro::Config::Env).to receive(:user_seat_hash).and_return(user_seat_hash)
25
27
  end
26
28
 
27
29
  context 'when cache_read_attempt=true' do
@@ -40,6 +42,7 @@ describe KnapsackPro::Client::API::V1::BuildDistributions do
40
42
  node_total: node_total,
41
43
  node_index: node_index,
42
44
  ci_build_id: ci_build_id,
45
+ user_seat: user_seat_hash,
43
46
  }
44
47
  }).and_return(action)
45
48
  expect(subject).to eq action
@@ -62,6 +65,7 @@ describe KnapsackPro::Client::API::V1::BuildDistributions do
62
65
  node_total: node_total,
63
66
  node_index: node_index,
64
67
  ci_build_id: ci_build_id,
68
+ user_seat: user_seat_hash,
65
69
  test_files: test_files
66
70
  }
67
71
  }).and_return(action)
@@ -7,6 +7,7 @@ describe KnapsackPro::Client::API::V1::Queues do
7
7
  let(:node_index) { double }
8
8
  let(:test_files) { double }
9
9
  let(:node_build_id) { double }
10
+ let(:user_seat_hash) { double }
10
11
 
11
12
  subject do
12
13
  described_class.queue(
@@ -23,6 +24,7 @@ describe KnapsackPro::Client::API::V1::Queues do
23
24
  before do
24
25
  expect(KnapsackPro::Config::Env).to receive(:fixed_queue_split).and_return(fixed_queue_split)
25
26
  expect(KnapsackPro::Config::Env).to receive(:ci_node_build_id).and_return(node_build_id)
27
+ expect(KnapsackPro::Config::Env).to receive(:user_seat_hash).and_return(user_seat_hash)
26
28
  end
27
29
 
28
30
  context 'when can_initialize_queue=true and attempt_connect_to_queue=true' do
@@ -43,6 +45,7 @@ describe KnapsackPro::Client::API::V1::Queues do
43
45
  node_total: node_total,
44
46
  node_index: node_index,
45
47
  node_build_id: node_build_id,
48
+ user_seat: user_seat_hash,
46
49
  }
47
50
  }).and_return(action)
48
51
  expect(subject).to eq action
@@ -67,6 +70,7 @@ describe KnapsackPro::Client::API::V1::Queues do
67
70
  node_total: node_total,
68
71
  node_index: node_index,
69
72
  node_build_id: node_build_id,
73
+ user_seat: user_seat_hash,
70
74
  test_files: test_files
71
75
  }
72
76
  }).and_return(action)
@@ -92,6 +96,7 @@ describe KnapsackPro::Client::API::V1::Queues do
92
96
  node_total: node_total,
93
97
  node_index: node_index,
94
98
  node_build_id: node_build_id,
99
+ user_seat: user_seat_hash,
95
100
  }
96
101
  }).and_return(action)
97
102
  expect(subject).to eq action
@@ -6,4 +6,5 @@ describe KnapsackPro::Config::CI::Base do
6
6
  its(:commit_hash) { should be nil }
7
7
  its(:branch) { should be nil }
8
8
  its(:project_dir) { should be nil }
9
+ its(:user_seat) { should be nil }
9
10
  end
@@ -76,8 +76,8 @@ describe KnapsackPro::Config::CI::Buildkite do
76
76
  subject { described_class.new.branch }
77
77
 
78
78
  context 'when environment exists' do
79
- let(:env) { { 'BUILDKITE_BRANCH' => 'master' } }
80
- it { should eql 'master' }
79
+ let(:env) { { 'BUILDKITE_BRANCH' => 'main' } }
80
+ it { should eql 'main' }
81
81
  end
82
82
 
83
83
  context "when environment doesn't exist" do
@@ -97,4 +97,39 @@ describe KnapsackPro::Config::CI::Buildkite do
97
97
  it { should be nil }
98
98
  end
99
99
  end
100
+
101
+ describe '#user_seat' do
102
+ subject { described_class.new.user_seat }
103
+
104
+ context 'when the BUILDKITE_BUILD_AUTHOR env var exists' do
105
+ let(:env) do
106
+ { 'BUILDKITE_BUILD_AUTHOR' => 'Jane Doe',
107
+ 'BUILDKITE_BUILD_CREATOR' => nil }
108
+ end
109
+
110
+ it { should eql 'Jane Doe' }
111
+ end
112
+
113
+ context 'when the BUILDKITE_BUILD_CREATOR env var exists' do
114
+ let(:env) do
115
+ { 'BUILDKITE_BUILD_AUTHOR' => nil,
116
+ 'BUILDKITE_BUILD_CREATOR' => 'John Doe' }
117
+ end
118
+
119
+ it { should eql 'John Doe' }
120
+ end
121
+
122
+ context 'when both BUILDKITE_BUILD_AUTHOR and BUILDKITE_BUILD_CREATOR env vars exist' do
123
+ let(:env) do
124
+ { 'BUILDKITE_BUILD_AUTHOR' => 'Jane Doe',
125
+ 'BUILDKITE_BUILD_CREATOR' => 'John Doe' }
126
+ end
127
+
128
+ it { should eql 'Jane Doe' }
129
+ end
130
+
131
+ context "when neither env var exists" do
132
+ it { should be nil }
133
+ end
134
+ end
100
135
  end
@@ -63,8 +63,8 @@ describe KnapsackPro::Config::CI::Circle do
63
63
  subject { described_class.new.branch }
64
64
 
65
65
  context 'when environment exists' do
66
- let(:env) { { 'CIRCLE_BRANCH' => 'master' } }
67
- it { should eql 'master' }
66
+ let(:env) { { 'CIRCLE_BRANCH' => 'main' } }
67
+ it { should eql 'main' }
68
68
  end
69
69
 
70
70
  context "when environment doesn't exist" do
@@ -84,4 +84,39 @@ describe KnapsackPro::Config::CI::Circle do
84
84
  it { should be nil }
85
85
  end
86
86
  end
87
+
88
+ describe '#user_seat' do
89
+ subject { described_class.new.user_seat }
90
+
91
+ context 'when the CIRCLE_USERNAME env var exists' do
92
+ let(:env) do
93
+ { 'CIRCLE_USERNAME' => 'Jane Doe',
94
+ 'CIRCLE_PR_USERNAME' => nil }
95
+ end
96
+
97
+ it { should eql 'Jane Doe' }
98
+ end
99
+
100
+ context 'when the CIRCLE_PR_USERNAME env var exists' do
101
+ let(:env) do
102
+ { 'CIRCLE_USERNAME' => nil,
103
+ 'CIRCLE_PR_USERNAME' => 'John Doe' }
104
+ end
105
+
106
+ it { should eql 'John Doe' }
107
+ end
108
+
109
+ context 'when both CIRCLE_USERNAME and CIRCLE_PR_USERNAME env vars exist' do
110
+ let(:env) do
111
+ { 'CIRCLE_USERNAME' => 'Jane Doe',
112
+ 'CIRCLE_PR_USERNAME' => 'John Doe' }
113
+ end
114
+
115
+ it { should eql 'Jane Doe' }
116
+ end
117
+
118
+ context "when neither env var exists" do
119
+ it { should be nil }
120
+ end
121
+ end
87
122
  end
@@ -52,12 +52,12 @@ describe KnapsackPro::Config::CI::GithubActions do
52
52
  context 'when GITHUB_REF has value' do
53
53
  let(:env) do
54
54
  {
55
- 'GITHUB_REF' => 'master',
55
+ 'GITHUB_REF' => 'main',
56
56
  'GITHUB_SHA' => '2e13512fc230d6f9ebf4923352718e4d',
57
57
  }
58
58
  end
59
59
 
60
- it { should eql 'master' }
60
+ it { should eql 'main' }
61
61
  end
62
62
 
63
63
  context 'when GITHUB_REF is not set' do
@@ -88,4 +88,18 @@ describe KnapsackPro::Config::CI::GithubActions do
88
88
  it { should be nil }
89
89
  end
90
90
  end
91
+
92
+ describe '#user_seat' do
93
+ subject { described_class.new.user_seat }
94
+
95
+ context 'when the GITHUB_ACTOR environment variable exists' do
96
+ let(:env) { { 'GITHUB_ACTOR' => 'jane_doe' } }
97
+
98
+ it { should eql 'jane_doe' }
99
+ end
100
+
101
+ context "when the GITHUB_ACTOR environment variable doesn't exist" do
102
+ it { should be nil }
103
+ end
104
+ end
91
105
  end
@@ -73,13 +73,13 @@ describe KnapsackPro::Config::CI::GitlabCI do
73
73
  subject { described_class.new.branch }
74
74
 
75
75
  context 'when Gitlab Release 9.0+ and environment exists' do
76
- let(:env) { { 'CI_COMMIT_REF_NAME' => 'master' } }
77
- it { should eql 'master' }
76
+ let(:env) { { 'CI_COMMIT_REF_NAME' => 'main' } }
77
+ it { should eql 'main' }
78
78
  end
79
79
 
80
80
  context 'when Gitlab Release 8.x and environment exists' do
81
- let(:env) { { 'CI_BUILD_REF_NAME' => 'master' } }
82
- it { should eql 'master' }
81
+ let(:env) { { 'CI_BUILD_REF_NAME' => 'main' } }
82
+ it { should eql 'main' }
83
83
  end
84
84
 
85
85
  context "when environment doesn't exist" do
@@ -99,4 +99,39 @@ describe KnapsackPro::Config::CI::GitlabCI do
99
99
  it { should be nil }
100
100
  end
101
101
  end
102
+
103
+ describe '#user_seat' do
104
+ subject { described_class.new.user_seat }
105
+
106
+ context 'when the GITLAB_USER_NAME env var exists' do
107
+ let(:env) do
108
+ { 'GITLAB_USER_NAME' => 'Jane Doe',
109
+ 'GITLAB_USER_EMAIL' => nil }
110
+ end
111
+
112
+ it { should eql 'Jane Doe' }
113
+ end
114
+
115
+ context 'when the GITLAB_USER_EMAIL env var exists' do
116
+ let(:env) do
117
+ { 'GITLAB_USER_NAME' => nil,
118
+ 'GITLAB_USER_EMAIL' => 'janed@example.com' }
119
+ end
120
+
121
+ it { should eql 'janed@example.com' }
122
+ end
123
+
124
+ context 'when both GITLAB_USER_NAME and GITLAB_USER_EMAIL env vars exist' do
125
+ let(:env) do
126
+ { 'GITLAB_USER_NAME' => 'Jane Doe',
127
+ 'GITLAB_USER_EMAIL' => 'janed@example.com' }
128
+ end
129
+
130
+ it { should eql 'Jane Doe' }
131
+ end
132
+
133
+ context "when neither env var exists" do
134
+ it { should be nil }
135
+ end
136
+ end
102
137
  end
@@ -182,6 +182,51 @@ describe KnapsackPro::Config::Env do
182
182
  end
183
183
  end
184
184
 
185
+ describe '.user_seat' do
186
+ subject { described_class.user_seat }
187
+
188
+ context 'when ENV exists' do
189
+ context 'when KNAPSACK_PRO_USER_SEAT has value' do
190
+ before { stub_const("ENV", { 'KNAPSACK_PRO_USER_SEAT' => 'John Doe' }) }
191
+ it { should eq 'John Doe' }
192
+ end
193
+
194
+ context 'when CI environment has value' do
195
+ before do
196
+ expect(described_class).to receive(:ci_env_for).with(:user_seat).and_return('Jane Doe')
197
+ end
198
+
199
+ it { should eq 'Jane Doe' }
200
+ end
201
+ end
202
+
203
+ context "when ENV doesn't exist" do
204
+ it { should be nil }
205
+ end
206
+ end
207
+
208
+ describe '.user_seat_hash' do
209
+ subject { described_class.user_seat_hash }
210
+
211
+ before do
212
+ expect(described_class).to receive(:user_seat).at_least(1).and_return(user_seat)
213
+ end
214
+
215
+ context 'when the user seat has a value' do
216
+ let(:user_seat) { 'John Doe' }
217
+
218
+ it 'returns a SHA256 hash for the user seat' do
219
+ expect(subject).to eq '6cea57c2fb6cbc2a40411135005760f241fffc3e5e67ab99882726431037f908'
220
+ end
221
+ end
222
+
223
+ context 'when the user seat has no value' do
224
+ let(:user_seat) { nil }
225
+
226
+ it { expect(subject).to be_nil }
227
+ end
228
+ end
229
+
185
230
  describe '.test_file_pattern' do
186
231
  subject { described_class.test_file_pattern }
187
232
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.0
4
+ version: 3.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-02 00:00:00.000000000 Z
11
+ date: 2023-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake