You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sam Ruby <ru...@apache.org> on 2016/02/16 15:22:44 UTC

[whimsy.git] [1/1] Commit db10f15: rough in a reminder cronjob

Commit db10f153ddadc699d9c4950b96cccb4ef14b1ab8:
    rough in a reminder cronjob


Branch: refs/heads/master
Author: Sam Ruby <ru...@intertwingly.net>
Committer: Sam Ruby <ru...@intertwingly.net>
Pusher: rubys <ru...@apache.org>

------------------------------------------------------------
www/board/agenda/bin/remind-cronjob.rb                       | +++++++++++++++ 
www/board/agenda/views/actions/send-reminders.json.rb        | +++++++++++ ----
------------------------------------------------------------
58 changes: 51 additions, 7 deletions.
------------------------------------------------------------


diff --git a/www/board/agenda/bin/remind-cronjob.rb b/www/board/agenda/bin/remind-cronjob.rb
new file mode 100644
index 0000000..10382ff
--- /dev/null
+++ b/www/board/agenda/bin/remind-cronjob.rb
@@ -0,0 +1,29 @@
+#
+# This is a sketch of what it would take to send board agendas via a cronjob.
+# It currently sets @dryrun to true, preventing emails from being sent out.
+#
+
+Dir.chdir File.expand_path('../..', __FILE__)
+
+require 'whimsy/asf/agenda'
+require 'mail'
+require 'listen'
+
+FOUNDATION_BOARD = ASF::SVN['private/foundation/board']
+require './models/agenda'
+require './models/ipc'
+
+# draft reminder text
+@reminder = ARGV.first || 'reminder1'
+reminder = eval(File.read("views/actions/reminder-text.json.rb"))
+
+# send reminders
+@agenda = File.basename(Dir["#{FOUNDATION_BOARD}/board_agenda_*.txt"].sort.last)
+@from = "Whimsy <no...@apache.org>"
+@dryrun = true
+@subject = reminder[:subject]
+@message = reminder[:body]
+response = eval(File.read("views/actions/send-reminders.json.rb"))
+
+# dump results for debugging purposes
+puts JSON.pretty_generate(response)
diff --git a/www/board/agenda/views/actions/send-reminders.json.rb b/www/board/agenda/views/actions/send-reminders.json.rb
index b243a7e..3293a61 100644
--- a/www/board/agenda/views/actions/send-reminders.json.rb
+++ b/www/board/agenda/views/actions/send-reminders.json.rb
@@ -3,6 +3,7 @@
 #
 
 sent = {}
+unsent = []
 
 # utilize smtp without certificate verification
 Mail.defaults do
@@ -10,14 +11,27 @@
 end
 
 # extract values for common fields
-sender = ASF::Person.find(env.user)
-from = "#{sender.public_name} <#{...@apache.org>".untaint
 subject = @subject.untaint
+unless @from
+  sender = ASF::Person.find(env.user)
+  @from = "#{sender.public_name} <#{...@apache.org>".untaint
+end
 
 # iterate over the agenda
 Agenda.parse(@agenda, :full).each do |item|
-  next unless @pmcs.include? item['title']
-  next unless item['chair_email']
+  # decide whether or not to skip the report based on the setting of @pmcs
+  next if @pmcs and not @pmcs.include? item['title']
+  next if not @pmcs and not item['report'].to_s.empty?
+
+  # select exec officer, additional officer, and committee reports
+  next unless item[:attach] =~ /^(4[A-Z]|\d|[A-Z]+)$/
+
+  # bail if chair email can't be found
+  unless item['chair_email']
+    unsent << item['title']
+    next
+  end
+
 
   # substitute [whoTo] values
   if item['to'] == 'president'
@@ -34,7 +48,7 @@
 
   # construct email
   mail = Mail.new do
-    from from
+    from @from
     to "#{item['owner']} <#{item['chair_email']}>".untaint
     subject subject
 
@@ -50,9 +64,10 @@
   end
 
   # deliver mail
-  mail.deliver! unless @dryrun
+# mail.deliver! unless @dryrun
   sent[item['title']] = mail.to_s
 end
 
 # provide a response to the request
-{count: sent.length, unsent: @pmcs - sent.keys, sent: sent, dryrun: @dryrun}
+unsent += @pmcs - sent.keys if @pmcs
+{count: sent.length, unsent: unsent, sent: sent, dryrun: @dryrun}