Generating RT bugs out of CPAN Testers’ Reports

Posted in: Technical Track

A few hours ago, I received a CPAN Testers‘s report. The report was a genuine bug (CPANtesters++. Love you guys), and as I made my way to rt.cpan.org to create a ticket to track the issue, I found myself thinking that it’d be nice to have a ‘bug this‘ button straight from the smoke report page.

You all know where that kind of thinking leads to, right?

I didn’t GreaseMonkey’ed a button into the CPAN Testers page (yet), but I did the second-best thing. Namely, a little command-line script that takes a report url and uses it to auto-generate a bug report to the right distribution:

$ ./cpantest2rt.pl https://www.cpantesters.org/cpan/report/8648ea2e-e35d-11df-a329-07bc4e7aadc9

The script is pretty straight-forward. It grabs the bug report off the CPAN Testers site, figures out which distribution we’re talking about, generates an email with the report information, gives you a chance to edit the report (the first line is the bug’s title, the rest will be its description) and sends the email on its merry way to rt.cpan.org.

In a future iteration, I’ll probably switch to using the REST interface to RT, but for now the email interface is proving to be Good Enoughtm.

#!/usr/bin/env perl
use strict;
use warnings;
use URI;
use URI::QueryParam;
use LWP::Simple qw/ get /;
use File::Temp qw/ tempfile /;
use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Simple::Creator;
use HTML::TreeBuilder::XPath;
use autodie;
my $from = '[email protected]';
my $url = URI->new( shift || die );
# we just want the report
$url->query_param( raw => 1 );
my $report = HTML::TreeBuilder::XPath->new;
$report->parse( get $url );
# which distribution?
( my $dist = $report->findvalue('/html/head/title') ) =~
  s/^.*?(\S+)-v?[\d_.]*$/$1/m;
$dist or die;
my ( $fh, $filename ) = tempfile();
# Link to html version of the report
# for the ticket description
$url->query_param( raw => 0 );
print {$fh} join "\n", "CPAN Tester Failure\n", $url,
  $report->findvalue('/html/body/pre');
system $ENV{EDITOR}, $filename;
open $fh, '<', $filename;
chomp( my $subject = <$fh> );
print "sending email... ";
sendmail(
    Email::Simple->create(
        header => [
            To      => "bug-$dist\@rt.cpan.org",
            From    => $from,
            Subject => $subject,
        ],
        body => do { local $/ = <$fh> },
    ) );
print "done\n";
email
Want to talk with an expert? Schedule a call with our team to get the conversation started.

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *