#!/usr/bin/perl -w

use strict;
use Test::Repocop::Options;
use Test::Repocop::TestDB;
use Test::Repocop::Metadata;

$Repocop::arg::reportlevel='skip';
my $branch;
&Test::Repocop::Options::get_common_options(
    'b|branch=s' => \$branch,
);
&Test::Repocop::Options::die_if_nothing_to_report();

my $baseurl=$branch eq 't6' ? "http://autoports.altlinux.org/pub/repocop" :
    "http://repocop.altlinux.org/pub/repocop";
my $branch_id=1;
$branch_id=4 if $branch eq 't6';
my $sqlprefix='INSERT INTO repocop_patches (name, version, release, url) VALUES (';
$sqlprefix='INSERT INTO repocop_patches (branch_id, name, version, release, url) VALUES ('."'$branch_id'," if $branch;

my %patch;


my $metadata=Test::Repocop::Metadata->new();
my $testdb=Test::Repocop::TestDB->new();
my $cache=$testdb->get_pkg_test_status_iterator();
while (my ($rpm,$test,$status)=$cache->iterate3_filtered()) {
    my $srpm=$metadata->sourceid($rpm);
    if ($srpm eq $rpm) {
	my $patchid=$srpm;
	$patchid=~s/\.src$//;
	my $suffix='/reports/diff/by-srpm/'.$patchid.'.diff';
	if (-e $repocop_cachedir.$suffix) {
	    my $name=$metadata->name($rpm);
	    my $version=$metadata->version($rpm);
	    my $release=$metadata->release($rpm);
	    my $arch=$metadata->arch($rpm);
	    my $url=$baseurl.$suffix;
	    #my $sql=$sqlprefix."'$name','$version','$release','$url');\n";
	    print $sqlprefix,"'$name','$version','$release','$url');\n";
	    #$patch{$srpm}=$sql;
	#} else {
	    #print STDERR "skipped $rpm $repocop_cachedir$suffix\n";
	}
    }
}

#foreach (keys (%patch)) {
#    print $patch{$_};
#}

#print STDERR "done.\n" if $verbose;

=head1	NAME

repocop-report-heroku - a tool that creates repocop reports for sisyphus.heroku.com.

=head1	SYNOPSIS

see repocop-report-txt

=head1	DESCRIPTION

B<repocop-report-heroku> processes results of repocop unit tests, created with 
repocop-run command, stored in <cachedir> and creates results in txt form.
Presize subset of tests can be selected using B<--include>
and B<--exclude> options.

=head1	OPTIONS

see repocop-report-txt

=head1	AUTHOR

Written by Igor Vlasenko <viy@altlinux.org>.

=head1	ACKNOWLEGEMENTS

To Alexey Torbin <at@altlinux.org>, whose qa-robot package
had a strong influence on repocop. 

=head1	COPYING

Copyright (c) 2008 Igor Vlasenko, ALT Linux Team.

This is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

=cut

