diff --git a/.github/workflows/afternoon_seal_quotes.yml b/.github/workflows/afternoon_seal_quotes.yml index 6309d5eb..87ffdee3 100644 --- a/.github/workflows/afternoon_seal_quotes.yml +++ b/.github/workflows/afternoon_seal_quotes.yml @@ -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" diff --git a/.github/workflows/morning_seal_quotes.yml b/.github/workflows/morning_seal_quotes.yml index d82855f1..105db675 100644 --- a/.github/workflows/morning_seal_quotes.yml +++ b/.github/workflows/morning_seal_quotes.yml @@ -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 diff --git a/README.md b/README.md index d2af2a1c..5618ccd1 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/seal_runner.rb b/bin/seal_runner.rb index 5a3eb98e..f579f27b 100755 --- a/bin/seal_runner.rb +++ b/bin/seal_runner.rb @@ -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 diff --git a/config/alphagov.yml b/config/alphagov.yml index 2e27e194..9c17c18d 100644 --- a/config/alphagov.yml +++ b/config/alphagov.yml @@ -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 @@ -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 diff --git a/lib/seal.rb b/lib/seal.rb index 853965b9..f9849796 100755 --- a/lib/seal.rb +++ b/lib/seal.rb @@ -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 diff --git a/lib/slack_poster.rb b/lib/slack_poster.rb index 9368498a..998c33fb 100644 --- a/lib/slack_poster.rb +++ b/lib/slack_poster.rb @@ -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 diff --git a/lib/team.rb b/lib/team.rb index 8c32be7c..daf4ca97 100644 --- a/lib/team.rb +++ b/lib/team.rb @@ -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, @@ -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 || [] @@ -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 diff --git a/lib/team_builder.rb b/lib/team_builder.rb index b1e8e248..0c64d63d 100644 --- a/lib/team_builder.rb +++ b/lib/team_builder.rb @@ -44,9 +44,10 @@ 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"]) + team_config["ci_checks"] = is_govuk_team?(key) end Team.new(**apply_env(team_config)) end @@ -60,6 +61,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"], @@ -99,4 +105,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