Skip to content

Make the block optional for delete_stopped_environments

David Dieulivol requested to merge 386711-no_block_given_fix into master

What does this MR do and why?

Closes #386711 (closed)

This call to delete_stopped_environments (https://gitlab.com/gitlab-org/gitlab/-/blob/99c0f9c15de5beac07382ddf44a4bdee8d29ceb0/scripts/review_apps/automated_cleanup.rb#L141) does not pass a block, and the method uses yield. It crashed recently in #386711 (closed).

The chosen fix is to make the block optional.

Sidenote: It means that we've never successfully cleaned up a GitLab docs environment for a little while.

How to set up and validate locally

Before

irb(main):001:1* def simpler_delete_stopped_environments
irb(main):002:1*   yield 'Hello'
irb(main):003:0> end
=> :simpler_delete_stopped_environments

irb(main):004:1* simpler_delete_stopped_environments do |environment|
irb(main):005:1*   puts environment
irb(main):006:0> end
Hello
=> nil

irb(main):007:0> simpler_delete_stopped_environments
Traceback (most recent call last):
	20: from /Users/gitlab/.asdf/installs/ruby/2.7.7/bin/irb:25:in `<main>'
	19: from /Users/gitlab/.asdf/installs/ruby/2.7.7/bin/irb:25:in `load'
	18: from /Users/gitlab/.asdf/installs/ruby/2.7.7/lib/ruby/gems/2.7.0/gems/irb-1.6.1/exe/irb:11:in `<top (required)>'
	 1: from (irb):7:in `<main>'
(irb):2:in `simpler_delete_stopped_environments': no block given (yield) (LocalJumpError)

After

irb(main):001:1* def simpler_delete_stopped_environments
irb(main):002:1*   yield 'Hello' if block_given?
irb(main):003:0> end
=> :simpler_delete_stopped_environments

irb(main):004:1* simpler_delete_stopped_environments do |environment|
irb(main):005:1*   puts environment
irb(main):006:0> end
Hello
=> nil

irb(main):007:0> simpler_delete_stopped_environments
=> nil

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports

Loading