This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathRakefile
97 lines (82 loc) · 2.53 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
88
89
90
91
92
93
94
95
96
97
require 'rubygems'
require 'bundler'
require 'time'
Bundler.require
require './lib/devdigest'
desc "Run the digest and print to stdout"
task :digest do
since = Time.now-24*60*60
puts Devdigest.new(since).run
end
desc "Run weekly ops and print to stdout"
task :ops_digest do
since = Time.now-7*24*60*60
puts Devdigest.new(since, :only => %w( pagerduty zendesk )).run
end
desc "Email daily digest"
task :daily_email do
case Time.now.wday
when 0, 6
puts "Skipping weekend"
next
when 1 # monday
since = Time.now-3*24*60*60
puts "Monday - fetching activity since #{since}"
else # regular weekday
since = Time.now-24*60*60
puts "Weekday - fetching activity since #{since}"
end
digest = Devdigest.new(since).run
markdown = RDiscount.new(digest)
team = ENV["ZENDESK_GROUP"] || "Team"
subject = "#{team} digest - #{Time.now.strftime("%A")}"
Pony.mail({
:to => ENV["EMAIL_TO"],
:from => ENV["EMAIL_FROM"],
:subject => subject,
:headers => { "Content-Type" => "text/html" },
:body => markdown.to_html,
:via => :smtp,
:via_options => {
:address => ENV["MAILGUN_SMTP_SERVER"],
:port => ENV["MAILGUN_SMTP_PORT"],
:user_name => ENV["MAILGUN_SMTP_LOGIN"],
:password => ENV["MAILGUN_SMTP_PASSWORD"],
:authentication => :plain,
:domain => "heroku.com"
}
})
puts "Emailed #{ENV["EMAIL_TO"]}."
end
desc "Email weekly operational digest"
task :weekly_ops_email do
if !ENV["WEEKLY_OPS_EMAIL_DAY"]
abort("set WEEKLY_OPS_EMAIL_DAY to the weekday you want it sent (sunday=0)")
end
if Time.now.wday != ENV["WEEKLY_OPS_EMAIL_DAY"].to_i
puts "Not doing the ops hand-off today, skipping"
exit 0
end
since = Time.now-7*24*60*60
puts "Fetching activity since #{since}"
digest = Devdigest.new(since, :only => %w( pagerduty zendesk )).run
markdown = RDiscount.new(digest)
subject = "Ops digest - #{Time.now.strftime("%A")}"
Pony.mail({
:to => ENV["EMAIL_TO"],
:from => ENV["EMAIL_FROM"],
:subject => subject,
:headers => { "Content-Type" => "text/html" },
:body => markdown.to_html,
:via => :smtp,
:via_options => {
:address => ENV["MAILGUN_SMTP_SERVER"],
:port => ENV["MAILGUN_SMTP_PORT"],
:user_name => ENV["MAILGUN_SMTP_LOGIN"],
:password => ENV["MAILGUN_SMTP_PASSWORD"],
:authentication => :plain,
:domain => "heroku.com"
}
})
puts "Emailed #{ENV["EMAIL_TO"]}."
end