3 require 'nos_oignons/git'
4 require 'nos_oignons/mailman'
5 require 'nos_oignons/member'
6 require 'nos_oignons/reminder'
7 require 'nos_oignons/reminder_db'
10 BOARD_EMAIL = 'ca@nos-oignons.net'
11 ADVISORS_EMAIL = 'deontologie@nos-oignons.net'
12 MEMBER_MAILING_LIST = 'ag'
14 # The following class methods are all meant to be called as command-line scripts
17 NosOignons::Member.all.each do |member|
24 def update_ag_subscribers!
25 list = NosOignons::MEMBER_MAILING_LIST
27 current_emails = NosOignons::Mailman.list_members(list)
28 uptodate_emails = NosOignons::Member.all.select(&:up_to_date?).collect(&:email)
30 emails_to_add = uptodate_emails - current_emails
31 NosOignons::Mailman.add_members(list, emails_to_add) unless emails_to_add.empty?
32 emails_to_remove = current_emails - uptodate_emails
33 NosOignons::Mailman.remove_members(list, emails_to_remove) unless emails_to_remove.empty?
36 def send_membership_reminders!
37 today = Time.now.to_date
38 NosOignons::Member.all.select(&:up_to_date?).each do |member|
39 anniversary = Time.new(today.year, member.joined_on.month,
40 member.joined_on.day).to_date
41 next if member.membership_fee_paid_on >= anniversary
42 next if member.reminded_on && member.reminded_on >= today
43 NosOignons::Reminder.all.sort_by(&:days).reverse.each do |reminder|
44 next if anniversary < today + reminder.days
46 member.remind(reminder)
52 def send_member_emails_to_advisors!
53 uptodate_emails = NosOignons::Member.all.select(&:up_to_date?).collect(&:email)
54 subject = 'Adresses emails des members à jour de cotisation'
55 body = <<-END_OF_BODY.gsub(/^ /, '')
56 Cher comité de déontologie de Nos oignons,
58 Comme le prévoit les statuts l'article 12 des statuts de l'association,
59 vous devez être en mesure de pouvoir convoquer une assemblée générale
60 extraordinaire. Pour ce faire, voici donc la liste des emails à jour
61 de cotisation à la date d'aujourd'hui :
63 #{uptodate_emails.join("\n")}
65 Et merci encore de votre engagement auprès de Nos oignons !
68 Le robot du conseil d'administration
70 mail = Mail.new :charset => 'utf-8',
71 :from => NosOignons::BOARD_EMAIL,
72 :to => NosOignons::ADVISORS_EMAIL,
79 if system('git rev-parse --quiet --verify HEAD >/dev/null')
82 # Initial commit: diff against an empty tree object
83 against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
86 IO.popen(['git', 'diff-index', '--cached', '--name-status', against]) do |io|
87 NosOignons::Git.handle_modified_files(io) do |file|
88 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
90 # Use empty ref to get the index
91 NosOignons::Member.read_from_git('', file)
92 rescue ArgumentError, Psych::SyntaxError
93 $stderr.puts "Désolé : #{file} n'a pas le bon format !"
100 def pre_receive_hook!(stdin)
101 stdin.readlines.each do |ref_line|
102 old_value, new_value, ref_name = ref_line.rstrip.split(' ', 3)
103 IO.popen(['git', 'diff', '--name-status', "#{old_value}..#{new_value}"]) do |io|
104 NosOignons::Git.handle_modified_files(io) do |file|
105 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
107 NosOignons::Member.read_from_git(new_value, file)
108 rescue ArgumentError, Psych::SyntaxError
109 $stderr.puts "Désolé : #{file} n'a pas le bon format !"