Skip to content

Add a link to Slack notification for silenced RuboCop offenses

Peter Leitzen requested to merge pl-rubocop-grace-period-slack-notification into master

What does this MR do and why?

This MR documents how to fix Slack notification message related to silenced RuboCop offenses.

It also refines the notification message to show the documentation link as a breadcrumb.

Screenshots or screen recordings

Slack notification
Screenshot_from_2022-09-28_11-35-23

How to set up and validate locally

rspec spec/rubocop/check_graceful_task_spec.rb`

Notification testing

  1. Export needed envvars:
export CI_JOB_NAME="update-static-analysis-cache"
export CI_JOB_URL=https://gitlab.com/gitlab-org/gitlab/-/jobs/3094949954
# See Settings > CI/CD > Variables
export CI_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/XXX/YYY/ZZZ
  1. Change Slack channel to avoid spam:
diff --git a/rubocop/check_graceful_task.rb b/rubocop/check_graceful_task.rb
index 724f7fa6963..88b9b12ce7d 100644
--- a/rubocop/check_graceful_task.rb
+++ b/rubocop/check_graceful_task.rb
@@ -65,7 +65,7 @@ def notify_slack
         return
       end
 
-      channel = 'f_rubocop'
+      channel = 'chat-ops-test'
       message = format(
         ':warning: `%{job_name}` passed :green: but contained <%{job_url}|silenced offenses>. ' \
         'See <%{docs_link}|docs>.',
  1. Trigger notification
ruby -r./rubocop/check_graceful_task -e 'RuboCop::CheckGracefulTask.new($stdout).send(:notify_slack)'
Notifying Slack #chat-ops-test.
  1. Verify the notification in #chat-opt-test (internal) (or see screenshot above)
  2. Cleanup
unset CI_JOB_NAME
unset CI_JOB_URL
unset CI_SLACK_WEBHOOK_URL

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 Peter Leitzen

Merge request reports