#!/usr/bin/perl

my @choices = @ARGV ? @ARGV : qw(shanenka larryl rmoneill);
my %known = map { $_ => 1 } @choices;

my %already;
my ($first, undef, @lines) = qx{ gitc list };
$first =~ /reviewer\s*$/ or die "couldn't parse output of 'gitc list'\n";
for my $line (@lines) {
  my @F = split /\s+/, $line;
  die "can't parse line:\n\t$line" if @F > 7;
  my $reviewer = $F[2] eq "submitted" ? $F[6] :
                 $F[2] eq "reviewing" ? $F[5] : undef;
  next unless defined $reviewer;
  $already{$reviewer}++;
}

# Sort by who has fewest open reviews
@choices = sort { $already{$a} <=> $already{$b} } @choices;
# Throw away those with more than the minimal number
pop @choices until $already{$choices[0]} == $already{$choices[-1]};
print @choices[rand @choices], "\n";
