CPAN-Digger

 view release on metacpan or  search on metacpan

lib/CPAN/Digger.pm  view on Meta::CPAN

        $logger->debug("Is CI '$ci'?");
        if ($data->{$ci}) {
            $logger->debug("CI '$ci' found!");
            $data->{has_ci} = 1;
        }
    }
}

sub analyze_gitlab {
    my ($data, $repo) = @_;

    $data->{gitlab_pipeline} = -e "$repo/.gitlab-ci.yml";
}

sub analyze_github {
    my ($data, $repo) = @_;

    $data->{travis} = -e "$repo/.travis.yml";
    my @ga = glob("$repo/.github/workflows/*");
    $data->{github_actions} = (scalar(@ga) ? 1 : 0);
    $data->{circleci} = -e "$repo/.circleci";
    $data->{appveyor} = (-e "$repo/.appveyor.yml") || (-e "$repo/appveyor.yml");
    $data->{azure_pipeline} = -e "$repo/azure-pipelines.yml";
}

sub html {
    my ($self) = @_;

    return if not $self->{html};
    if (not -d $self->{html}) {
        mkdir $self->{html};
    }

    $self->read_dashboards;

    my @distros = @{ $self->{db}->db_get_every_distro() };
    my %stats = (
        total => scalar @distros,
        has_vcs => 0,
        vcs => {},
        has_ci => 0,
        ci => {},
    );
    for my $ci (@ci_names) {
        $stats{ci}{$ci} = 0;
    }
    for my $dist (@distros) {
        $dist->{dashboard} = $self->{dashboards}{ $dist->{author} };
        if ($dist->{vcs_name}) {
            $stats{has_vcs}++;
            $stats{vcs}{ $dist->{vcs_name} }++;
        }
        if ($dist->{has_ci}) {
            $stats{has_ci}++;
            for my $ci (@ci_names) {
                $stats{ci}{$ci}++ if $dist->{$ci};
            }
        }
    }
    if ($stats{total}) {
        $stats{has_vcs_percentage} = int(100 * $stats{has_vcs} / $stats{total});
        $stats{has_ci_percentage} = int(100 * $stats{has_ci} / $stats{total});
    }


    my $tt = Template->new({
        INCLUDE_PATH => './templates',
        INTERPOLATE  => 1,
        WRAPPER      => 'wrapper.tt',
    }) or die "$Template::ERROR\n";

    my $report;
    $tt->process('main.tt', {
        distros => \@distros,
        version => $VERSION,
        timestamp => DateTime->now,
        stats => \%stats,
    }, \$report) or die $tt->error(), "\n";
    my $html_file = File::Spec->catfile($self->{html}, 'index.html');
    open(my $fh, '>', $html_file) or die "Could not open '$html_file'";
    print $fh $report;
    close $fh;
}


sub report {
    my ($self) = @_;

    return if not $self->{report};

    print "Report\n";
    print "------------\n";
    my @distros = @{ $self->{db}->db_get_every_distro() };
    if ($self->{limit} and @distros > $self->{limit}) {
        @distros = @distros[0 .. $self->{limit}-1];
    }
    for my $distro (@distros) {
        #die Dumper $distro;
        printf "%s %-40s %-7s", $distro->{date}, $distro->{distribution}, ($distro->{vcs_url} ? '' : 'NO VCS');
        if ($self->{check_vcs}) {
            printf "%-7s", ($distro->{has_ci} ? '' : 'NO CI');
        }
        print "\n";
    }

    if ($self->{days}) {
        my $distros = $self->{db}->get_distro_count($self->{start_date}, $self->{end_date});
        my $authors = $self->{db}->get_author_count($self->{start_date}, $self->{end_date});
        my $vcs_count = $self->{db}->get_vcs_count($self->{start_date}, $self->{end_date});
        my $ci_count = $self->{db}->get_ci_count($self->{start_date}, $self->{end_date});
        printf
            "Last week there were a total of %s uploads to CPAN of %s distinct distributions by %s different authors. Number of distributions with link to VCS: %s. Number of distros with CI: %s.\n",
            $self->{total}, $distros, $authors, $vcs_count,
            $ci_count;
    }
}

sub collect {
    my ($self) = @_;

    my @all_the_distributions;



( run in 1.804 second using v1.01-cache-2.11-cpan-98e64b0badf )