Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MuriloDalRi committed Apr 2, 2024
1 parent 9ee9146 commit 87c46ab
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 21 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/afternoon_seal_quotes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,4 @@ jobs:
- name: Afternoon Seal Quotes
id: afternoon_seal_quotes
run: |
teams=(
govuk-developers
govuk-platform-security-reliability
)
for team in ${teams[*]} ; do
./bin/seal_runner.rb $team quotes
done
./bin/seal_runner.rb afternoon_seal_quotes
2 changes: 1 addition & 1 deletion .github/workflows/morning_seal_quotes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ jobs:
)
for team in ${morning_quote_teams[*]}; do
./bin/seal_runner.rb $team quotes
./bin/seal_runner.rb $team morning_seal_quotes
done
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export SLACK_WEBHOOK="get_your_incoming_webhook_link_for_your_slack_group_channe
export SLACK_CHANNEL="#whatever-channel-you-prefer"
export GITHUB_USE_LABELS=true
export GITHUB_SECURITY_ALERTS=true
export MORNING_SEAL_QUOTES=true
export MORNING_SEAL_PRS=true
export AFTERNOON_SEAL_QUOTES=true
export DEPENDAPANDA=true
export CI_CHECKS=true
export GITHUB_EXCLUDE_LABELS="[DO NOT MERGE],Don't merge,DO NOT MERGE,Waiting on factcheck,wip"
export GITHUB_REPOS="myapp,anotherrepo" # Repos you want to be notified about
export COMPACT=true # Use a more compact version of the seal output
Expand Down
4 changes: 2 additions & 2 deletions bin/seal_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
require_relative '../lib/team_builder'

if !Date.today.saturday? && !Date.today.sunday?
teams = TeamBuilder.build(env: ENV, team_name: ARGV[0])
Seal.new(teams).bark(mode: ARGV[1])
teams = TeamBuilder.build(env: ENV)
Seal.new(teams).bark(mode: ARGV[0])
end
13 changes: 12 additions & 1 deletion config/alphagov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# To overwrite a specific section of common_properties, add the desired property with a new value after the '<<: *common_properties' line in the corresponding section

common_properties: &common_properties
security_alerts: true
security_alerts: false
morning_seal_quotes: false
morning_seal_prs: false
afternoon_seal_quotes: false
dependapanda: false
exclude_labels:
- WIP
- ignore
Expand All @@ -21,6 +25,13 @@ common_properties: &common_properties
- Thursday
- Friday

murilo-testing:
channel: "#murilo-testing"
morning_seal_quotes: true
afternoon_seal_quotes: true
quotes:
- Just testing some stuff.

data-infrastructure:
channel: '#data-infrastructure'
<<: *common_properties
Expand Down
20 changes: 13 additions & 7 deletions lib/seal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,27 @@ def bark(mode: nil)

def bark_at(team, mode: nil)
message = case mode
when "quotes"
Message.new(team.quotes.sample) if team.quotes_days.map(&:downcase).include?(Date.today.strftime("%A").downcase)
when "morning_seal_quotes", "afternoon_seal_quotes"
send_quotes_message(team, mode)
when "dependapanda"
MessageBuilder.new(team, :panda).build
MessageBuilder.new(team, :panda).build if team.dependapanda
when "ci"
MessageBuilder.new(team, :ci).build
MessageBuilder.new(team, :ci).build if team.ci_checks
else
MessageBuilder.new(team, :seal).build
MessageBuilder.new(team, :seal).build if team.morning_seal_prs
end

return if message.nil? || message.text.nil?

poster = SlackPoster.new(team.channel, message.mood)
poster.send_request(message.text)
rescue StandardError => e
puts "Error barking at team '#{team.name}': #{e.message}"
end

def send_quotes_message(team, mode)
if team.quotes_days.map(&:downcase).include?(Date.today.strftime("%A").downcase) && team.public_send("#{mode}")
Message.new(team.quotes.sample)
end
end
end
2 changes: 1 addition & 1 deletion lib/slack_poster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ def set_mood_from_team
end

def channel
@team_channel = "#bot-testing" if ENV["DEVELOPMENT"]
@team_channel = "#murilo-testing"
end
end
15 changes: 15 additions & 0 deletions lib/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ class Team
def initialize(
use_labels: nil,
security_alerts: nil,
morning_seal_quotes: nil,
morning_seal_prs: nil,
afternoon_seal_quotes: nil,
dependapanda: nil,
ci_checks: nil,
compact: nil,
exclude_labels: nil,
exclude_titles: nil,
Expand All @@ -12,6 +17,11 @@ def initialize(
)
@use_labels = (use_labels.nil? ? false : use_labels)
@security_alerts = (security_alerts.nil? ? false : security_alerts)
@morning_seal_quotes = (morning_seal_quotes.nil? ? false : morning_seal_quotes)
@morning_seal_prs = (morning_seal_prs.nil? ? false : morning_seal_prs)
@afternoon_seal_quotes = (afternoon_seal_quotes.nil? ? false : afternoon_seal_quotes)
@dependapanda = (dependapanda.nil? ? false : dependapanda)
@ci_checks = (ci_checks.nil? ? false : ci_checks)
@compact = (compact.nil? ? false : compact)
@quotes_days = quotes_days || []
@exclude_labels = exclude_labels || []
Expand All @@ -25,6 +35,11 @@ def initialize(
use_labels
quotes_days
security_alerts
morning_seal_quotes
morning_seal_prs
afternoon_seal_quotes
dependapanda
ci_checks
compact
exclude_labels
exclude_titles
Expand Down
13 changes: 12 additions & 1 deletion lib/team_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ def build_single_team(team_name)
end

def build_all_teams
static_config.map do |_, team_config|
static_config.map do |key, team_config|
if team_config["repos"].nil?
team_config["repos"] = govuk_team_repos(team_config["channel"])
puts key
team_config["ci_checks"] = is_govuk_team?(key)
end
Team.new(**apply_env(team_config))
end
Expand All @@ -60,6 +62,11 @@ def apply_env(config)
use_labels: env["GITHUB_USE_LABELS"] == "true" || config["use_labels"],
quotes_days: env["GITHUB_QUOTES_DAYS"]&.split(",") || config["quotes_days"],
security_alerts: env["GITHUB_SECURITY_ALERTS"] == "true" || config["security_alerts"],
morning_seal_quotes: env["MORNING_SEAL_QUOTES"] == "true" || config["morning_seal_quotes"],
morning_seal_prs: env["MORNING_SEAL_PRS"] == "true" || config["morning_seal_prs"],
afternoon_seal_quotes: env["AFTERNOON_SEAL_QUOTES"] == "true" || config["afternoon_seal_quotes"],
dependapanda: env["DEPENDAPANDA"] == "true" || config["dependapanda"],
ci_checks: env["CI_CHECKS"] == "true" || config["ci_checks"],
compact: env["COMPACT"] == "true" || config["compact"],
exclude_labels: env["GITHUB_EXCLUDE_LABELS"]&.split(",") || config["exclude_labels"],
exclude_titles: env["GITHUB_EXCLUDE_TITLES"]&.split(",") || config["exclude_titles"],
Expand Down Expand Up @@ -99,4 +106,8 @@ def govuk_team_repos(team_channel)
puts "Error fetching govuk team repos (#{team_channel}): #{e.message}"
[]
end

def is_govuk_team?(team)
@govuk_data.include? { |repos| repos["team"] == team }
end
end

0 comments on commit 87c46ab

Please sign in to comment.