Skip to content

Commit

Permalink
Revert "Critical alert callout"
Browse files Browse the repository at this point in the history
  • Loading branch information
MuriloDalRi authored Dec 3, 2024
1 parent 7a183bf commit 27b40da
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 88 deletions.
4 changes: 0 additions & 4 deletions lib/github_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions lib/security_alert_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 1 addition & 57 deletions spec/message_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down Expand Up @@ -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
22 changes: 1 addition & 21 deletions templates/dependapanda.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down

0 comments on commit 27b40da

Please sign in to comment.