From 27766d44b05b020db39ccee071e9c76fd7380b46 Mon Sep 17 00:00:00 2001 From: Mark Glines Date: Sun, 28 Feb 2010 07:16:20 -0500 Subject: [PATCH] Github updates. * Add some sanity checking to make sure the github feed gave us data from the right project. (They apparently had a temporary bug, and the consequences were quite spammy.) * Add a warning message and return semigracefully if a feed no longer exists. * Move the timer registration down a bit, so github parsers can be tested with modules/local/test.pl. * The feed format changed ever so slightly (they added a rel attribute to the link tag), add that to the testsuite just in case. --- modules/local/githubparser.pm | 16 ++++++++++++++-- t/rakudolog.t | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/modules/local/githubparser.pm b/modules/local/githubparser.pm index 9994266..86ac14f 100644 --- a/modules/local/githubparser.pm +++ b/modules/local/githubparser.pm @@ -108,6 +108,10 @@ sub process_branch { my $atom = XML::Atom::Client->new(); $feed = $atom->getFeed($$self{branches}{$branch}{url}); } + if(!defined($feed)) { + warn "could not fetch branch $branch feed " . $$self{branches}{$branch}{url}; + return; + } my @items = $feed->entries; @items = sort { $a->updated cmp $b->updated } @items; # ascending order @@ -118,12 +122,15 @@ sub process_branch { foreach my $item (@items) { my $link = $item->link->href; my ($rev) = $link =~ m|/commit/([a-z0-9]{40})|; + my ($proj) = $link =~ m|http://github.com/[^/]+/([^/]+)/|; if(exists($$self{not_first_time})) { + return unless $proj = $$self{project}; # output new entries to channel next if exists($$self{seen}{$rev}); $$self{seen}{$rev} = 1; $self->output_item($item, $branch, $link, $rev); } else { + die "got bad data from github feed" unless $proj = $$self{project}; # just populate the seen cache $$self{seen}{$rev} = 1; } @@ -206,6 +213,7 @@ sub try_link { # create project, if necessary my $self = $objects_by_package{$modulename}; + my $register_timer = 0; if(!defined($self)) { $objects_by_package{$modulename} = $self = { project => $project, @@ -216,8 +224,7 @@ sub try_link { # create a dynamic subclass to get the timer callback back to us eval "package $modulename; use base 'modules::local::githubparser';"; $objects_by_package{$modulename} = bless($self, $modulename); - main::create_timer($parsername."_process_project_timer", $modulename, - "process_project", 300 + $feed_number++); + $register_timer = 1; main::lprint("github: created project $project ($modulename)"); } @@ -244,6 +251,11 @@ sub try_link { main::lprint("github: $project/$branchname will output to ".join("/",@$target)); } } + + if($register_timer) { + main::create_timer($parsername."_process_project_timer", $modulename, + "process_project", 300 + $feed_number++); + } } diff --git a/t/rakudolog.t b/t/rakudolog.t index 05c50b8..fa4d709 100644 --- a/t/rakudolog.t +++ b/t/rakudolog.t @@ -82,10 +82,10 @@ $output = [output()]; is(scalar @$output, 6, "6 lines of output"); is($$output[0]{net} , 'magnet' , "line to magnet/#parrot"); is($$output[0]{chan}, '#parrot' , "line to magnet/#parrot"); -like($$output[0]{text}, qr|rakudo/master: |, "master branch"); +like($$output[0]{text}, qr|rakudo: |, "master branch"); is($$output[1]{net} , 'freenode', "line to freenode/#perl6"); is($$output[1]{chan}, '#perl6' , "line to freenode/#perl6"); -like($$output[1]{text}, qr|rakudo/master: |, "master branch"); +like($$output[1]{text}, qr|rakudo: |, "master branch"); BEGIN { $tests += 7 }; # update with multiple commits having the same timestamp @@ -131,3 +131,34 @@ my @message_list = ($$output[2]{text}, $$output[8]{text}); is(scalar grep(/Small optimizations/ , @message_list), 1, "log message"); is(scalar grep(/Add some micro-bench/, @message_list), 1, "log message"); BEGIN { $tests += 7 }; + +# update with their post-2010-02-26 feed format (added rel attribute to the tag) +reset_output(); +$xml_footer = << '__XML__' . $xml_footer; + + tag:github.com,2008:Grit::Commit/b131f6052a181bdad8f7b9e5abe30c9c2c2e360e + + Split .defined method and defined vtable method for language interop, as per pmichaud++. + 2010-02-27T16:46:53-08:00 + <pre>m src/builtins/Parcel.pir + +Split .defined method and defined vtable method for language interop, as per pmichaud++.</pre> + + Jonathan Worthington + + +__XML__ +$xml = $xml_header . '2010-02-27T16:46:53-08:00' . $xml_footer; +$feed = XML::Atom::Feed->new(\$xml); +call_func('process_branch', 'master', $feed); +$output = [output()]; +is(scalar @$output, 6, "6 lines of output"); +is($$output[0]{net} , 'magnet' , "line to magnet/#parrot"); +is($$output[0]{chan}, '#parrot' , "line to magnet/#parrot"); +is($$output[1]{net} , 'freenode', "line to freenode/#perl6"); +is($$output[1]{chan}, '#perl6' , "line to freenode/#perl6"); +# The module sorts by time, but the time is the same for these two commits. +# Do it this way so we don't depend on perl's internal sort algorithm details. +@message_list = ($$output[2]{text}); +is(scalar grep(/Split .defined method/ , @message_list), 1, "log message"); +BEGIN { $tests += 6 };