Skip to content

Commit

Permalink
Add a flag to control which domains we send shame emails to
Browse files Browse the repository at this point in the history
  • Loading branch information
ixdy committed May 3, 2016
1 parent ae4626d commit f9cf860
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions hack/verify-flags/known-flags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
allowed-shame-domains
api-token
balance-algorithm
block-path-config
Expand Down
1 change: 1 addition & 0 deletions mungegithub/Dockerfile-shame-mailer
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
# -e SMTP_SERVER=smtp.example.com:1234 \
# -e SMTP_USER=smtp_example_user \
# -e SMTP_PASS=my_super_secret_smtp_password \
# -e ALLOWED_SHAME_DOMAINS=example.com,example.net \
# gcr.io/google_containers/shame-mailer:TAG

FROM google/debian:jessie
Expand Down
30 changes: 20 additions & 10 deletions mungegithub/reports/shame.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ import (

// ShameReport lists flaky tests and writes group+individual email to nag people to fix them.
type ShameReport struct {
Command string
From string
Cc string
ReplyTo string
Command string
From string
Cc string
ReplyTo string
AllowedShameDomains string
}

func init() {
Expand All @@ -53,6 +54,7 @@ func (s *ShameReport) AddFlags(cmd *cobra.Command, config *githubhelper.Config)
cmd.Flags().StringVar(&s.From, "shame-from", "", "From: header for shame report")
cmd.Flags().StringVar(&s.Cc, "shame-cc", "", "Cc: header for shame report")
cmd.Flags().StringVar(&s.ReplyTo, "shame-reply-to", "", "Reply-To: header for shame report")
cmd.Flags().StringVar(&s.AllowedShameDomains, "allowed-shame-domains", "", "comma-separated list of domains we can send shame emails to")
}

type reportData struct {
Expand Down Expand Up @@ -185,7 +187,7 @@ func (s *ShameReport) groupReport(r *reportData) (map[string]bool, error) {
// Exclude issues less than three days old if we can
// individually email the owner.
for _, data := range issues {
if data.age < 3*24*time.Hour && mayEmail(r.loginToEmail[assignee]) {
if data.age < 3*24*time.Hour && s.mayEmail(r.loginToEmail[assignee]) {
continue
}
strs = append(strs, data.String())
Expand All @@ -203,7 +205,7 @@ func (s *ShameReport) groupReport(r *reportData) (map[string]bool, error) {
to := []string{}
missingAddresses := []string{}
for u, e := range r.loginToEmail {
if mayEmail(e) {
if s.mayEmail(e) {
to = append(to, e)
} else {
missingAddresses = append(missingAddresses, u)
Expand Down Expand Up @@ -248,9 +250,10 @@ These users couldn't be added to the To: line, as we have no address for them:
Individuals with an accessible email and no assignments older than 3 days will
be left off the group email, so please make your email address public in github!
Note: non-google users are not emailed by this system.
Note: only users with public email addresses ending in %v
are emailed by this system.
`, strings.Join(missingAddresses, ", "))
`, strings.Join(missingAddresses, ", "), s.AllowedShameDomains)
}

return needsIndividualEmail, s.runCmd(dest)
Expand All @@ -268,7 +271,7 @@ func (s *ShameReport) individualReport(user string, r *reportData) error {

to := []string{}
email := r.loginToEmail[user]
if mayEmail(email) {
if s.mayEmail(email) {
to = append(to, email)
}
sort.Strings(to)
Expand Down Expand Up @@ -298,4 +301,11 @@ Full report:
return s.runCmd(dest)
}

func mayEmail(email string) bool { return strings.HasSuffix(email, "@google.com") }
func (s *ShameReport) mayEmail(email string) bool {
for _, domain := range strings.Split(s.AllowedShameDomains, ",") {
if strings.HasSuffix(email, "@"+domain) {
return true
}
}
return false
}
3 changes: 2 additions & 1 deletion mungegithub/shame_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
./mungegithub --token="${GITHUB_API_TOKEN}" --issue-reports=shame\
--shame-from="${SHAME_FROM}" --shame-reply-to="${SHAME_REPLY_TO}"\
--shame-cc="${SHAME_CC}"\
--shame-report-cmd="mailx -v -t -S smtp=${SMTP_SERVER} -S smtp-auth=login -S smtp-auth-user=${SMTP_USER} -S smtp-auth-password=${SMTP_PASS}"
--shame-report-cmd="mailx -v -t -S smtp=${SMTP_SERVER} -S smtp-auth=login -S smtp-auth-user=${SMTP_USER} -S smtp-auth-password=${SMTP_PASS}" \
--allowed-shame-domains="${ALLOWED_SHAME_DOMAINS}"

0 comments on commit f9cf860

Please sign in to comment.