From 27b40dab57d05d07bcbf7267cedad3d4781d6336 Mon Sep 17 00:00:00 2001 From: Murilo Date: Tue, 3 Dec 2024 09:25:11 +0000 Subject: [PATCH] Revert "Critical alert callout" --- lib/github_fetcher.rb | 4 --- lib/message_builder.rb | 2 -- lib/security_alert_handler.rb | 4 --- spec/message_builder_spec.rb | 58 +-------------------------------- templates/dependapanda.text.erb | 22 +------------ 5 files changed, 2 insertions(+), 88 deletions(-) diff --git a/lib/github_fetcher.rb b/lib/github_fetcher.rb index 94c1ac02..36a0cb19 100644 --- a/lib/github_fetcher.rb +++ b/lib/github_fetcher.rb @@ -46,10 +46,6 @@ def security_alerts_count @security_alert_handler&.security_alerts_count end - def critical_security_alerts_count - @security_alert_handler&.critical_security_alerts_count - end - def github_api_errors @security_alert_handler&.github_api_errors || 0 end diff --git a/lib/message_builder.rb b/lib/message_builder.rb index 13cecba2..6d0fbbdd 100644 --- a/lib/message_builder.rb +++ b/lib/message_builder.rb @@ -160,8 +160,6 @@ def dependapanda_message if @team.security_alerts @all_alerts_count = github_fetcher.security_alerts_count - @critical_alerts_count = github_fetcher.critical_security_alerts_count - @all_alerts_link = "https://github.com/orgs/alphagov/security/alerts/dependabot?q=is:open+repo:#{@team.repos.join(',')}" @github_api_errors = github_fetcher.github_api_errors diff --git a/lib/security_alert_handler.rb b/lib/security_alert_handler.rb index 1903f970..d02f8267 100644 --- a/lib/security_alert_handler.rb +++ b/lib/security_alert_handler.rb @@ -13,10 +13,6 @@ def security_alerts_count @global_security_alerts.length end - def critical_security_alerts_count - @global_security_alerts.select { |alert| alert[:severity] == 4 }.length - end - def filter_security_alerts(repo) @global_security_alerts.select { |alert| alert[:repo] == repo } end diff --git a/spec/message_builder_spec.rb b/spec/message_builder_spec.rb index 3c640ef7..5fd836f9 100644 --- a/spec/message_builder_spec.rb +++ b/spec/message_builder_spec.rb @@ -4,13 +4,12 @@ RSpec.describe MessageBuilder do let(:security_alerts) { false } let(:security_alerts_count) { 0 } - let(:critical_security_alerts_count) { 0 } let(:github_api_errors) { 0 } let(:repos) { %w[repo1 repo2] } let(:team) { double(:team, security_alerts:, compact: false, dependabot_prs_only:, repos:) } let(:pull_requests) { [] } let(:dependabot_prs_only) { false } - let(:github_fetcher) { double(:github_fetcher, list_pull_requests: pull_requests, security_alerts_count:, critical_security_alerts_count:, github_api_errors:) } + let(:github_fetcher) { double(:github_fetcher, list_pull_requests: pull_requests, security_alerts_count:, github_api_errors:) } let(:animal) { :seal } subject(:message_builder) { MessageBuilder.new(team, animal) } @@ -320,60 +319,5 @@ expect(message_builder.build.text).to include("1 security alert") end end - - context "security_alerts=True, critical_security_alerts_count=0, dependabot PRs present" do - let(:security_alerts) { true } - let(:security_alerts_count) { 1 } - let(:critical_security_alerts_count) { 0 } - let(:pull_requests) { dependabot_pull_requests } - - it "posts a message with security info" do - expect(message_builder.build.text).to include("It is not critical.") - end - end - - context "security_alerts=True, critical_security_alerts_count=1, dependabot PRs present" do - let(:security_alerts) { true } - let(:security_alerts_count) { 1 } - let(:critical_security_alerts_count) { 1 } - let(:pull_requests) { dependabot_pull_requests } - - it "posts a message with security info" do - expect(message_builder.build.text).to include("It is critical.") - end - end - - context "security_alerts=True, critical_security_alerts_count=0, dependabot PRs present" do - let(:security_alerts) { true } - let(:security_alerts_count) { 2 } - let(:critical_security_alerts_count) { 0 } - let(:pull_requests) { dependabot_pull_requests } - - it "posts a message with security info" do - expect(message_builder.build.text).to include("None of them are critical.") - end - end - - context "security_alerts=True, critical_security_alerts_count=1, dependabot PRs present" do - let(:security_alerts) { true } - let(:security_alerts_count) { 2 } - let(:critical_security_alerts_count) { 1 } - let(:pull_requests) { dependabot_pull_requests } - - it "posts a message with security info" do - expect(message_builder.build.text).to include("One of them is critical.") - end - end - - context "security_alerts=True, critical_security_alerts_count=2, dependabot PRs present" do - let(:security_alerts) { true } - let(:security_alerts_count) { 2 } - let(:critical_security_alerts_count) { 2 } - let(:pull_requests) { dependabot_pull_requests } - - it "posts a message with security info" do - expect(message_builder.build.text).to include("2 of them are critical.") - end - end end end diff --git a/templates/dependapanda.text.erb b/templates/dependapanda.text.erb index ace33266..5b0453c8 100644 --- a/templates/dependapanda.text.erb +++ b/templates/dependapanda.text.erb @@ -5,27 +5,7 @@ <% end -%> <% if @team.security_alerts %> -<%= ":#{@all_alerts_count.zero? ? 'tada' : 'alert'}: There #{@all_alerts_count == 1 ? 'is' : 'are'} a total of <#{@all_alerts_link}|#{@all_alerts_count == 1 ? '1 security alert' : "#{@all_alerts_count} security alerts"}> across all of your repos." %> - -<% if @all_alerts_count == 1 && @critical_alerts_count == 0 %> -<%= "It is not critical." %> - -<% elsif @all_alerts_count == 1 && @critical_alerts_count == 1 %> -<%= "It is critical." %> - -<% elsif @all_alerts_count > 1 && @critical_alerts_count == 0 %> -<%= "None of them are critical." %> - -<% elsif @all_alerts_count > 1 && @critical_alerts_count == 1 %> -<%= "One of them is critical." %> - -<% elsif @all_alerts_count > 1 && @critical_alerts_count > 1 %> -<%= "#{@critical_alerts_count} of them are critical." %> - -<% end %> - -<%= "#{' :tada:' if @all_alerts_count.zero?}" -%> - +<%= ":#{@all_alerts_count.zero? ? 'tada' : 'alert'}: There #{@all_alerts_count == 1 ? 'is' : 'are'} a total of <#{@all_alerts_link}|#{@all_alerts_count == 1 ? '1 security alert' : "#{@all_alerts_count} security alerts"}> across all of your repos.#{' :tada:' if @all_alerts_count.zero?}" -%> <% if @github_api_errors.positive? %> <%= ":warning: #{@github_api_errors} errors fetching security alerts. Check that you have the <#{'https://docs.publishing.service.gov.uk/manual/configure-github-repo.html#when-you-create-a-new-repo'}|right permissions> on all <#{'https://docs.publishing.service.gov.uk/repos.html#repos-by-team'}|your repos>." %> <% end %>