Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Rt bug count tests #156

Closed
wants to merge 6 commits into from

3 participants

Matthew Horsfall (alh) Olaf Alders Florian Ragwitz
Matthew Horsfall (alh)
Collaborator

No description provided.

Olaf Alders
Owner

This is now on wolfsage/rt_bugs branch, so I'll close this pull request.

Olaf Alders oalders closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 14, 2012
  1. Florian Ragwitz

    Use Catalyst's native PSGI engine

    rafl authored
    This currently depends on the no_state_in_engine branch of Catalyst-Runtime.
Commits on Jan 15, 2012
  1. Florian Ragwitz

    Add a distribution document

    rafl authored
  2. Florian Ragwitz
  3. Florian Ragwitz
  4. Florian Ragwitz

    Index bug summary data

    rafl authored
  5. Matthew Horsfall (alh)

    New tests for rt bug counts

    wolfsage authored
This page is out of date. Refresh to see the latest.
13 lib/MetaCPAN/Document/Distribution.pm
View
@@ -0,0 +1,13 @@
+package MetaCPAN::Document::Distribution;
+
+use Moose;
+use ElasticSearchX::Model::Document;
+use namespace::autoclean;
+
+has id => (is => 'ro', id => ['name']);
+has name => (is => 'ro', required => 1);
+has rt_bug_count => (is => 'ro');
+
+__PACKAGE__->meta->make_immutable;
+
+1;
1  lib/MetaCPAN/Script/Release.pm
View
@@ -217,6 +217,7 @@ sub import_tarball {
|| $create->{abstract} eq 'null' );
my $release = $cpan->type('release')->put( $create, { refresh => 1 } );
+ my $dist = $cpan->type('distribution')->put({ name => $d->dist }, { refresh => 1 });
my @files;
my $meta_file;
74 lib/MetaCPAN/Script/Tickets.pm
View
@@ -0,0 +1,74 @@
+package MetaCPAN::Script::Tickets;
+
+use Moose;
+use Log::Contextual qw( :log :dlog );
+use List::AllUtils 'sum';
+use LWP::UserAgent;
+use Text::CSV;
+use HTTP::Request::Common;
+use namespace::autoclean;
+
+with 'MooseX::Getopt', 'MetaCPAN::Role::Common';
+
+has rt_summary_url => (
+ is => 'ro',
+ required => 1,
+ default => 'https://rt.cpan.org/Public/bugs-per-dist.tsv',
+);
+
+sub run {
+ my ($self) = @_;
+
+ my $bug_summary = $self->retrieve_bug_summary;
+ $self->index_bug_summary($bug_summary);
+
+ return 1;
+}
+
+sub index_bug_summary {
+ my ($self, $summary) = @_;
+
+ for my $dist (keys %{ $summary }) {
+ my $dist_data = $self->index->type('distribution')->inflate(0)->get({
+ name => $dist,
+ }) or next;
+
+ use Data::Dump 'pp';
+ pp $dist_data;
+
+ $self->index->type('distribution')->put({
+ %{ $dist_data->{_source} },
+ rt_bug_count => $summary->{$dist},
+ }, { refresh => 1 });
+ }
+}
+
+sub retrieve_bug_summary {
+ my ($self) = @_;
+
+ my $ua = LWP::UserAgent->new;
+ my $resp = $ua->request(GET $self->rt_summary_url);
+
+ confess $resp->reason unless $resp->is_success;
+
+ return $self->parse_tsv($resp->content);
+}
+
+sub parse_tsv {
+ my ($self, $tsv) = @_;
+ $tsv =~ s/^#.*\n//mg;
+
+ my $tsv_parser = Text::CSV->new({ sep_char => "\t" });
+ open my $tsv_io, '<', \$tsv or confess $!;
+
+ my %summary;
+ while (my $row = $tsv_parser->getline($tsv_io)) {
+ $summary{ $row->[0] } = sum @{ $row }[1..3];
+ }
+
+ return \%summary;
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
5 lib/MetaCPAN/Server.pm
View
@@ -70,13 +70,10 @@ __PACKAGE__->setup(
OAuth2::Provider
)
);
-__PACKAGE__->setup_engine('PSGI');
__PACKAGE__->meta->make_immutable( replace_constructor => 1 );
my $app = Plack::Middleware::ReverseProxy->wrap(
- sub {
- __PACKAGE__->run(@_);
- }
+ __PACKAGE__->psgi_app,
);
Plack::Middleware::ServerStatus::Lite->wrap(
25 lib/MetaCPAN/Server/Controller/Distribution.pm
View
@@ -0,0 +1,25 @@
+package MetaCPAN::Server::Controller::Distribution;
+
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'MetaCPAN::Server::Controller' }
+with 'MetaCPAN::Server::Role::JSONP';
+
+sub index : Chained('/') : PathPart('distribution') : CaptureArgs(0) {
+}
+
+sub get : Chained('index') : PathPart('') : Args(1) {
+ my ( $self, $c, $name ) = @_;
+ eval {
+ $c->stash(
+ $c->model('CPAN::Distribution')->inflate(0)->get({
+ name => $name,
+ })->{_source},
+ );
+ } or $c->detach('/not_found');
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
10 t/fakecpan.t
View
@@ -8,6 +8,7 @@ use MetaCPAN::Script::Runner;
use MetaCPAN::Script::Mapping;
use MetaCPAN::Script::Release;
use MetaCPAN::Script::Author;
+use MetaCPAN::Script::Tickets;
use Path::Class qw(dir file);
use File::Copy;
use Config::General;
@@ -53,11 +54,18 @@ ok(
copy(file(qw(t var fakecpan 00whois.xml)),file($config->{cpan}, qw(authors 00whois.xml)));
copy(file(qw(t var fakecpan author-1.0.json)),file($config->{cpan}, qw(authors id M MO MO author-1.0.json)));
+copy(file(qw(t var fakecpan bugs.tsv)),file($config->{cpan}, qw(bugs.tsv)));
local @ARGV = ('author', '--cpan', $config->{cpan});
ok(
MetaCPAN::Script::Author->new_with_options($config)->run,
'index authors'
);
+
+ok(
+ MetaCPAN::Script::Tickets->new_with_options({%$config, rt_summary_url => "file://" . file($config->{cpan}, 'bugs.tsv')->absolute})->run,
+ 'tickets'
+);
+
wait_for_es();
sub wait_for_es {
@@ -74,4 +82,4 @@ my $tests = Test::Aggregate->new( {
verbose => 2,
} );
-$tests->run;
+$tests->run;
19 t/release/bugs.t
View
@@ -0,0 +1,19 @@
+use Test::More;
+use strict;
+use warnings;
+
+use MetaCPAN::Model;
+
+my $model = MetaCPAN::Model->new( es => ':9900' );
+my $idx = $model->index('cpan');
+my $release = $idx->type('distribution')->get(
+ {
+ name => 'Moose',
+ }
+);
+
+is($release->name, 'Moose', 'Got correct release');
+
+is($release->rt_bug_count, 39, 'Got correct bug count');
+
+done_testing;
32 t/server/controller/distribution.t
View
@@ -0,0 +1,32 @@
+use strict;
+use warnings;
+use Test::More;
+use MetaCPAN::Server::Test;
+
+my @tests = (
+ [ '/distribution' => 200 ],
+ [ '/distribution/Moose' => 200 ],
+ [ '/distribution/DOESNEXIST' => 404 ],
+);
+
+test_psgi app, sub {
+ my $cb = shift;
+ for my $test (@tests) {
+ my ($k, $v) = @{ $test };
+ ok( my $res = $cb->( GET $k), "GET $k" );
+ is( $res->code, $v, "code $v" );
+ is( $res->header('content-type'),
+ 'application/json; charset=utf-8',
+ 'Content-type'
+ );
+ ok( my $json = eval { decode_json( $res->content ) }, 'valid json' );
+ if ( $k eq '/distribution' ) {
+ ok( $json->{hits}->{total}, 'got total count' );
+ }
+ elsif ( $v eq 200 ) {
+ ok( $json->{name} eq 'Moose', 'Moose' );
+ }
+ }
+};
+
+done_testing;
4 t/var/fakecpan/bugs.tsv
View
@@ -0,0 +1,4 @@
+# A fake https://rt.cpan.org/Public/bugs-per-dist.tsv
+Monkey-Patch 0 0 0 1 0
+Moo 2 5 0 2 1
+Moose 15 20 4 122 23
Something went wrong with that request. Please try again.