This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
87 lines (73 loc) · 2 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
desc "Lint ruby"
task :lint do
sh "bundle exec rubocop --format clang"
end
task default: %i[lint spec]
require "http"
require "json"
require_relative "./lib/message_generator"
def currently_in_deploy_freeze?
Date.today >= Date.parse("2016-12-22") && Date.today <= Date.parse("2017-01-04")
end
def weekend?
Date.today.saturday? || Date.today.sunday?
end
def random_parrot
%w[
angel_parrot
aussieparrot
ceiling_parrot
coffeeparrot
congaparrot
darkbeerparrot
discoparrot
fasterparrot
fiesta_parrot
gentleman_parrot
ice_cream_parrot
jediparrot
jenkins_parrot
loveparrot
mardi_gras_parrot
oldtimeyparrot
parrot
ship_it_parrot
skiparrot
shuffleparrot
ultrafastparrot
].sample
end
desc "Run the deploy lag badger"
task :run do
JSON.parse(HTTP.get("https://docs.publishing.service.gov.uk/apps.json")).group_by { |app| app["team"] }.each do |team, applications|
messages = applications.map { |application|
github_owner_and_repo = application.dig("links", "repo_url").gsub("https://github.com/", "")
MessageGenerator.new(github_owner_and_repo).message
}.compact
message_payload = nil
if messages.any?
message_payload = {
username: "Badger",
icon_emoji: ":badger:",
text: "Hello :paw_prints:, this is your <https://github.com/alphagov/govuk-deploy-lag-badger|regular badgering to deploy>!\n\n#{messages.join("\n")}",
mrkdwn: true,
channel: team,
}
end
if weekend?
puts "Not posting anything, it's the weekend"
next
end
if currently_in_deploy_freeze?
puts "Not posting anything, we're in a deploy freeze period"
next
end
if ENV["REALLY_POST_TO_SLACK"] != "1"
puts "Not posting anything, this is a dry run"
next
end
HTTP.post(ENV.fetch("BADGER_SLACK_WEBHOOK_URL"), body: JSON.dump(message_payload)) unless message_payload.nil?
end
end