Skip to content

Return 'N/A' if category is nil

Ash McKenzie requested to merge ashmckenzie/fix-when-category-is-nil into master

What does this MR do and why?

This MR updates the category name lookup logic to handle when the provided category is nil and instead of failing with a Ruby error, return N/A. This situation can happen when an MR has two changes with:

  • One change matching a category, e.g. :docs
  • Another change that doesn't match a category and so returns nil.

The list of categories is then [:docs, nil] which causes issues without this patch.

Closes gitlab-org/gitlab-development-kit#1663 (closed)

Without this change

From https://gitlab.com/gitlab-org/gitlab-development-kit/-/jobs/3584098444:

--snip--
bundler: failed to load command: danger (/builds/gitlab-org/gitlab-development-kit/vendor/bundle/ruby/3.0.0/bin/danger)
/builds/gitlab-org/gitlab-development-kit/vendor/bundle/ruby/3.0.0/gems/gitlab-dangerfiles-3.6.4/lib/danger/plugins/internal/helper.rb:241:in `label_for_category': \e[31m (Danger::DSLError)
[!] Invalid `Dangerfile` file: \e[31m
[!] Invalid `Dangerfile` file: undefined method `start_with?' for nil:NilClass\e[0m
 #  from /builds/gitlab-org/gitlab-development-kit/vendor/bundle/ruby/3.0.0/gems/gitlab-dangerfiles-3.6.4/lib/danger/rules/simple_roulette/Dangerfile:68
 #  -------------------------------------------
 #    row = +"| #{reviewer_note} | #{maintainer_note} |"
 >    row.prepend("| #{helper.label_for_category(category)} ") if has_categories
 #    row
 #  -------------------------------------------
\e[0m
 #  from /builds/gitlab-org/gitlab-development-kit/vendor/bundle/ruby/3.0.0/gems/gitlab-dangerfiles-3.6.4/lib/danger/rules/simple_roulette/Dangerfile:68
 #  -------------------------------------------
 #   >   #  
 #  -------------------------------------------
	from /builds/gitlab-org/gitlab-development-kit/vendor/bundle/ruby/3.0.0/gems/gitlab-dangerfiles-3.6.4/lib/danger/rules/simple_roulette/Dangerfile:68:in `markdown_row_for_spins'
--snip--

With this change

image

MR acceptance checklist

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

Edited by Ash McKenzie

Merge request reports