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 MEMBER_MAILING_LIST = 'ag'
13 # The following class methods are all meant to be called as command-line scripts
16 NosOignons::Member.all.each do |member|
23 def update_ag_subscribers!
24 list = NosOignons::MEMBER_MAILING_LIST
26 current_emails = NosOignons::Mailman.list_members(list)
27 uptodate_emails = NosOignons::Member.all.select(&:up_to_date?).collect(&:email)
29 emails_to_add = uptodate_emails - current_emails
30 NosOignons::Mailman.add_members(list, emails_to_add) unless emails_to_add.empty?
31 emails_to_remove = current_emails - uptodate_emails
32 NosOignons::Mailman.remove_members(list, emails_to_remove) unless emails_to_remove.empty?
35 def send_membership_reminders!
36 today = Time.now.to_date
37 NosOignons::Member.all.select(&:up_to_date?).each do |member|
38 NosOignons::Reminder.all.sort_by(&:days).reverse.each do |reminder|
39 anniversary = Time.new(today.year, member.joined_on.month,
40 member.joined_on.day).to_date
42 next if member.membership_fee_paid_on > anniversary
43 next if member.membership_fee_paid_on > today - reminder.days
44 next if anniversary > today - reminder.days
45 next if member.reminded_on && member.reminded_on >= today
47 member.remind(reminder)
54 if system('git rev-parse --quiet --verify HEAD >/dev/null')
57 # Initial commit: diff against an empty tree object
58 against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
61 IO.popen(['git', 'diff-index', '--cached', '--name-status', against]) do |io|
62 NosOignons::Git.handle_modified_files(io) do |file|
63 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
65 # Use empty ref to get the index
66 NosOignons::Member.read_from_git('', file)
67 rescue ArgumentError, Psych::SyntaxError
68 $stderr.puts "Désolé : #{file} n'a pas le bon format !"
75 def pre_receive_hook!(stdin)
76 stdin.readlines.each do |ref_line|
77 old_value, new_value, ref_name = ref_line.rstrip.split(' ', 3)
78 IO.popen(['git', 'diff', '--name-status', "#{old_value}..#{new_value}"]) do |io|
79 NosOignons::Git.handle_modified_files(io) do |file|
80 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
82 NosOignons::Member.read_from_git(new_value, file)
83 rescue ArgumentError, Psych::SyntaxError
84 $stderr.puts "Désolé : #{file} n'a pas le bon format !"