require 'whimsy/asf/agenda'
require 'date'

ASF::Committee.load_committee_info
agendas = Dir["#{ASF::SVN['private/foundation/board']}/board_agenda_*.txt"]
parsed = ASF::Board::Agenda.parse(IO.read(agendas.sort.last), true)
missing = parsed.select {|item| item['missing']}.
  map {|item| item['title'].downcase}

month = Date.today.strftime('%B')

ASF::Committee.list.sort_by(&:name).each do |committee|
  # skip committees in the process of heading to the attic
  next unless committee.report

  # determine current status
  if missing.include?(committee.name)
    if committee.report.start_with? 'Next month'
      if committee.report =~ /missing in \w+(, \w+)*$/
        # missing again
        committee.report += ", #{month}"
      else
        # missing after a problem (e.g., not accepted)
        committee.report += ", missing in #{month}"
      end
    else
      # first time missing
      committee.report = "Next month: missing in #{month}"
    end
  elsif committee.report =~ /Next month: new/
    if committee.report.include? "monthly through #{month}"
      # expired
      committee.report = ''
    end
  else
    # previously missing or rejected, now present
    committee.report = ''
  end

  # output 'Next month' lines, complete with comment
  if committee.report.start_with? 'Next month:'
    comment = committee.report.sub('Next month: ', '')
    puts "    #{committee.name.ljust(22)} # #{comment}"
  end
end
