#!/usr/bin/env perl

use v5.24.0;
use strict;
#use warnings;

use Data::Dumper;
use Storable;
use lib '../lib';
use Dist;
use Template;

my $data = retrieve '../everything.stor';

my %auths;

for my $mod ($data->{modules}->@*) {
  my ($tested, $status) = $data->{jobstatus}{$mod}->@{qw/tested status/};
  $tested = !!$tested ? "yes" : "no";
  $status //= "";

  my $log = "";
  if ($status && $status ne 'success') {
    my $failure = $status =~ /inc/ ? 'incfailure' : 'genfailure';
    $log = "<a href='/logs/${mod}_$failure.log'>here</a>"
  }

  my $author = Dist::get_author($mod) // '__UNKNOWN__';

  push $auths{$author}->@*, {
    name => $mod,
    author => $author,
    status => $status,
    tested => $tested,
    dist => $Dist::mod_to_dist{$mod} // $mod,
    log => $log
  };
}


my $tt = Template->new();
for my $auth (keys %auths) {
  my $vars = {
    modules => $auths{$auth},
  };

  $tt->process('template.tt.html', $vars, "files/$auth.html");
}
