#!/usr/bin/perl

use strict;
use warnings FATAL => 'all';
use Mail::Mailer;

my @to = ('thomas@glanzmann.de', 'mps@arvanta.net');

my @repos = qw(
/scratch/asahi/m1n1
/scratch/asahi/linux
/scratch/asahi/u-boot
/scratch/asahi/PKGBUILDs
);

my @output;

for my $repo (@repos) {
        chdir($repo);
        my @lines = `git pull 2>&1`;
        for (@lines) {
                if (/([0-9a-f]+\.\.[0-9a-f]+)\s+(\S+)/) {
                        push(@output, "# $repo\n");
                        push(@output, @lines);
                        my $refs = $1;
                        my $branch = $2;
                        push(@output, "\n");
                        push(@output, `git log -p $refs 2>&1`);
                }
        }
}

exit unless (@output);

my $mailer = Mail::Mailer->new("sendmail");
$mailer->open({ From => 'null@tg.st', To => \@to, Subject => "Asahi repository changes" });
print $mailer @output;
$mailer->close();
