Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script/tickets: cleanup #563

Merged
merged 1 commit into from
Nov 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 22 additions & 27 deletions lib/MetaCPAN/Script/Tickets.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use Parse::CSV;
use Pithub;
use URI::Escape qw(uri_escape);
use MetaCPAN::Types qw( ArrayRef Str );
use Ref::Util qw( is_ref is_hashref);

with 'MetaCPAN::Role::Script', 'MooseX::Getopt';

Expand All @@ -39,13 +40,6 @@ has github_token => (
builder => '_build_github_token',
);

has source => (
is => 'ro',
required => 1,
isa => ArrayRef [Str],
default => sub { [qw(rt github)] },
);

has pithub => (
is => 'ro',
isa => 'Pithub',
Expand Down Expand Up @@ -87,20 +81,8 @@ sub run {
my $self = shift;

$self->check_all_distributions;

# Hash keys are distribution names.
# rt issues are counted for all dists (the download tsv contains everything).
# gh issues are counted for any dist with a github url in `resources.bugtracker.web`.
foreach my $source ( @{ $self->source } ) {
if ( $source eq 'github' ) {
log_debug {'Fetching GitHub issues'};
$self->index_github_bugs;
}
elsif ( $source eq 'rt' ) {
log_debug {'Fetching RT bugs'};
$self->index_rt_bugs;
}
}
$self->index_rt_bugs;
$self->index_github_bugs;

return 1;
}
Expand Down Expand Up @@ -133,14 +115,18 @@ sub check_all_distributions {
$self->_bulk_update($dists);
}

# gh issues are counted for any dist with a github url in `resources.bugtracker.web`.
sub index_github_bugs {
my $self = shift;
my %summary;

log_debug {'Fetching GitHub issues'};

my $scroll
= $self->index->type('release')->find_github_based->scroll('5m');
log_debug { sprintf( "Found %s repos", $scroll->total ) };

my %summary;

while ( my $release = $scroll->next ) {
my $resources = $release->resources;
my ( $user, $repo, $source )
Expand Down Expand Up @@ -176,23 +162,32 @@ sub index_github_bugs {
sub github_user_repo_from_resources {
my ( $self, $resources ) = @_;
my ( $user, $repo, $source );
while ( my ( $k, $v ) = each %$resources ) {
if ( !ref $v

for my $k ( keys %{$resources} ) {
my $v = $resources->{$k};

if ( !is_ref($v)
&& $v
=~ /^(https?|git):\/\/github\.com\/([^\/]+)\/([^\/]+?)(\.git)?\/?$/
)
{
return ( $2, $3, $v );
}

( $user, $repo, $source ) = $self->github_user_repo_from_resources($v)
if ( ref $v eq 'HASH' );
return ( $user, $repo, $source ) if ($user);
if is_hashref($v);

return ( $user, $repo, $source ) if $user;
}

return ();
}

# rt issues are counted for all dists (the download tsv contains everything).
sub index_rt_bugs {
my ($self) = @_;
my $self = shift;

log_debug {'Fetching RT bugs'};

my $resp = $self->ua->request( GET $self->rt_summary_url );

Expand Down