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 NosOignons::Mailman.add_members(list, uptodate_emails - current_emails)
30 NosOignons::Mailman.remove_members(list, current_emails - uptodate_emails)
33 def send_membership_reminders!
34 today = Time.now.to_date
35 NosOignons::Member.all.select(&:up_to_date?).each do |member|
36 NosOignons::Reminder.all.sort_by(&:days).reverse.each do |reminder|
37 anniversary = Time.new(today.year, member.joined_on.month,
38 member.joined_on.day).to_date
40 next if member.membership_fee_paid_on > anniversary
41 next if member.membership_fee_paid_on > today - reminder.days
42 next if anniversary > today - reminder.days
43 next if member.reminded_on && member.reminded_on >= today
45 member.remind(reminder)
52 if system('git rev-parse --quiet --verify HEAD >/dev/null')
55 # Initial commit: diff against an empty tree object
56 against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
59 IO.popen(['git', 'diff-index', '--cached', '--name-status', against]) do |io|
60 NosOignons::Git.handle_modified_files(io) do |file|
61 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
63 # Use empty ref to get the index
64 NosOignons::Member.read_from_git('', file)
66 $stderr.puts "Désolé : #{file} n'a pas le bon format !"
73 def pre_receive_hook!(stdin)
74 stdin.readlines.each do |ref_line|
75 old_value, new_value, ref_name = ref_line.rstrip.split(' ', 3)
76 IO.popen(['git', 'diff', '--name-status', "#{old_value}..#{new_value}"]) do |io|
77 NosOignons::Git.handle_modified_files(io) do |file|
78 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
80 NosOignons::Member.read_from_git(new_value, file)
82 $stderr.puts "Désolé : #{file} n'a pas le bon format !"