Skip to content

Commit be22c84

Browse files
authored
fix: exit with non-zero status when check conclusions are disallowed (#147)
1 parent 78dd4dd commit be22c84

3 files changed

Lines changed: 34 additions & 19 deletions

File tree

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ AllCops:
88
RSpec/ExampleLength:
99
Enabled: false
1010
Max: 10
11+
12+
RSpec/MultipleExpectations:
13+
Max: 2

app/services/github_checks_verifier.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def call
2929
wait_for_checks
3030
rescue CheckNeverRunError, CheckConclusionNotAllowedError, RequiredInputError => e
3131
puts e.message
32-
raise SystemExit
32+
exit 1
3333
end
3434

3535
private

spec/services/github_checks_verifier_spec.rb

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,39 @@
1010

1111
before do
1212
described_class.config.client = Octokit::Client.new
13+
described_class.config.client.access_token = '_'
14+
described_class.config.ref = '_'
1315
described_class.config.allowed_conclusions = %w[success skipped]
1416
end
1517

1618
describe '#inputs' do
19+
before { allow(service).to receive(:exit) }
20+
1721
it 'raises an error when the ref input is empty' do
1822
service.config.ref = ''
1923
expected_msg = 'The ref parameter is required but was not provided.'
20-
expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout
24+
expect { service.call }.to output(/#{expected_msg}/).to_stdout
25+
expect(service).to have_received(:exit).with(1)
2126
end
2227

2328
it 'raises an error when the repo-token input is empty' do
24-
service.config.ref = '_'
2529
service.config.client.access_token = ''
2630
expected_msg = 'The repo-token parameter is required but was not provided.'
27-
expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout
31+
expect { service.call }.to output(/#{expected_msg}/).to_stdout
32+
expect(service).to have_received(:exit).with(1)
2833
end
2934
end
3035

3136
describe '#call' do
32-
before { allow(service).to receive(:wait_for_checks).and_raise(CheckNeverRunError) }
37+
before do
38+
allow(service).to receive(:wait_for_checks).and_raise(CheckNeverRunError)
39+
allow(service).to receive(:exit)
40+
end
3341

3442
it 'exit with status false if wait_for_checks fails' do
35-
service.config.ref = '_'
36-
service.config.client.access_token = '_'
3743
expected_msg = 'The requested check was never run against this ref, exiting...'
38-
expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout
44+
expect { service.call }.to output(/#{expected_msg}/).to_stdout
45+
expect(service).to have_received(:exit).with(1)
3946
end
4047
end
4148

@@ -110,9 +117,11 @@
110117

111118
all_checks = []
112119
allow(service).to receive(:query_check_status).and_return all_checks
120+
allow(service).to receive(:exit)
113121

114122
expected_msg = 'The requested check was never run against this ref, exiting...'
115-
expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout
123+
expect { service.call }.to output(/#{expected_msg}/).to_stdout
124+
expect(service).to have_received(:exit).with(1)
116125
end
117126

118127
context 'when fail_on_no_checks is false' do
@@ -147,6 +156,8 @@
147156
end
148157

149158
context 'when fail_on_no_checks is true (default)' do
159+
before { allow(service).to receive(:exit) }
160+
150161
it 'raises an exception when check_regexp is set and no checks match' do
151162
service.config.check_regexp = 'non-matching-regexp'
152163
service.config.fail_on_no_checks = true
@@ -156,7 +167,8 @@
156167
allow(service).to receive(:query_check_status).and_return all_checks
157168

158169
expected_msg = 'The requested check was never run against this ref, exiting...'
159-
expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout
170+
expect { service.call }.to output(/#{expected_msg}/).to_stdout
171+
expect(service).to have_received(:exit).with(1)
160172
end
161173

162174
it 'raises an exception when check_name is set and no checks match' do
@@ -168,17 +180,13 @@
168180
allow(service).to receive(:query_check_status).and_return all_checks
169181

170182
expected_msg = 'The requested check was never run against this ref, exiting...'
171-
expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout
183+
expect { service.call }.to output(/#{expected_msg}/).to_stdout
184+
expect(service).to have_received(:exit).with(1)
172185
end
173186
end
174187
end
175188

176189
describe '#wait_for_check_discovery' do
177-
before do
178-
service.config.ref = '_'
179-
service.config.client.access_token = '_'
180-
end
181-
182190
it 'polls until checks are found within the timeout' do
183191
service.config.check_name = 'delayed-check'
184192
service.config.fail_on_no_checks = true
@@ -225,25 +233,29 @@
225233
service.wait = 0
226234

227235
allow(service).to receive(:query_check_status).and_return []
236+
allow(service).to receive(:exit)
228237

229238
expected_msg = 'The requested check was never run against this ref, exiting...'
230-
expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout
239+
expect { service.call }.to output(/#{expected_msg}/).to_stdout
240+
expect(service).to have_received(:exit).with(1)
231241
end
232242
end
233243

234244
describe '#fail_unless_all_conclusions_allowed' do
235-
it 'raises an exception if some check conclusion is not allowed' do
245+
it 'prints an error message when a check conclusion is not allowed' do
236246
all_checks = [
237247
Helpers::CheckRun.new(name: 'test', status: 'completed', conclusion: 'success'),
238248
Helpers::CheckRun.new(name: 'test', status: 'completed', conclusion: 'failure')
239249
]
240250

241251
allow(service).to receive(:query_check_status).and_return all_checks
252+
allow(service).to receive(:exit)
242253

243254
expected_msg = 'The conclusion of one or more checks were not allowed. Allowed conclusions are: ' \
244255
"success, skipped. This can be configured with the 'allowed-conclusions' param."
245256

246-
expect { service.call }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout
257+
expect { service.call }.to output(/#{expected_msg}/).to_stdout
258+
expect(service).to have_received(:exit).with(1)
247259
end
248260

249261
it 'does not raise an exception if all checks conclusions are allowed' do

0 commit comments

Comments
 (0)