]> git.donarmstrong.com Git - infobot.git/commitdiff
* Bring in don's DebianBugs patch
authordjmcgrath <djmcgrath@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 19 Oct 2007 09:23:22 +0000 (09:23 +0000)
committerdjmcgrath <djmcgrath@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 19 Oct 2007 09:23:22 +0000 (09:23 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1567 c11ca15a-4712-0410-83d8-924469b57eb5

src/Modules/DebianBugs.pm [new file with mode: 0644]
src/Modules/DebianExtra.pl

diff --git a/src/Modules/DebianBugs.pm b/src/Modules/DebianBugs.pm
new file mode 100644 (file)
index 0000000..661247c
--- /dev/null
@@ -0,0 +1,123 @@
+# This module is a plugin for WWW::Scraper, and allows one to search
+# google, and is released under the terms of the GPL version 2, or any
+# later version. See the file README and COPYING for more
+# information. Copyright 2002 by Don Armstrong <don@donarmstrong.com>.
+
+# $Id:  $
+
+package DebianBugs;
+
+use warnings;
+use strict;
+
+use vars qw($VERSION $DEBUG);
+
+use LWP::UserAgent;
+
+$VERSION = q($Rev: $);
+$DEBUG ||= 0;
+
+sub get_url($){
+     my $url = shift;
+
+     my $ua = LWP::UserAgent->new;
+     $ua->agent("blootbug_debbugs/$VERSION");
+
+     # Create a request
+     my $req = HTTP::Request->new(GET => $url);
+     # Pass request to the user agent and get a response back
+     my $res = $ua->request($req);
+     # Check the outcome of the response
+     if ($res->is_success) {
+         return $res->content;
+     } else {
+         return undef;
+     }
+}
+
+sub bug_info($;$){
+     my $bug_num = shift;
+     my $options = shift || {};
+
+     if (not $bug_num =~ /^\#?\d+$/) {
+         warn "Bug is not a number!" and return undef if not $options->{return_warnings};
+         return "Bug is not a number!";
+     }
+     $bug_num =~ s/^\#//;
+     my $report = get_url("http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=$bug_num");
+
+     # strip down report to relevant header information.
+     $report =~ /<HEAD>(.+?)<HR>/s;
+     $report = $1;
+     my $bug = {};
+     ($bug->{num},$bug->{title}) = $report =~ m#\#(\d+)\<\/A\>\<BR\>(.+?)\<\/H1\>#is;
+     if ($DEBUG) {
+         print "Bugnum: $bug->{num}\nTitle: $bug->{title}\nReport: $report\n";
+     }
+     $bug->{title} =~ s/&lt;/\</g;
+     $bug->{title} =~ s/&gt;/\>/g;
+     $bug->{title} =~ s/&quot;/\"/g;
+     $bug->{severity} = 'n'; #Default severity is normal
+     my @bug_flags = split /(?<!\&.t)[;\.]\n/s, $report;
+     foreach my $bug_flag (@bug_flags) {
+         print "Bug_flag: $bug_flag\n" if $DEBUG;
+         if ($bug_flag =~ /Severity:/i) {
+              ($bug->{severity}) = $bug_flag =~ /(wishlist|minor|normal|important|serious|grave)/i;
+              # Just leave the leter instead of the whole thing.
+              $bug->{severity} =~ s/^(.).+$/$1/;
+         }
+         elsif ($bug_flag =~ /Package:/) {
+              ($bug->{package}) = $bug_flag =~ /\"\>\s*([^\<\>\"]+?)\s*\<\/a\>/;
+         }
+         elsif ($bug_flag =~ /Reported by:/) {
+              ($bug->{reporter}) = $bug_flag =~ /\"\>\s*(.+?)\s*\<\/a\>/;
+              # strip &lt; and &gt;
+              $bug->{reporter} =~ s/&lt;/\</g;
+              $bug->{reporter} =~ s/&gt;/\>/g;
+         }
+         elsif ($bug_flag =~ /Date:/) {
+              ($bug->{date}) = $bug_flag =~ /Date:\s*(\w.+?)\s*$/;
+              #ditch extra whitespace
+              $bug->{date} =~ s/\s{2,}/\ /;
+         }
+         elsif ($bug_flag =~ /Tags:/) {
+              ($bug->{tags}) = $bug_flag =~ /strong\>\s*(.+?)\s*\<\/strong\>/;
+         }
+         elsif ($bug_flag =~ /merged with /) {
+              $bug_flag =~ s/merged with\s*//;
+              $bug_flag =~ s/\<[^\>]+\>//g;
+               $bug_flag =~ s/\s//sg;
+              $bug->{merged_with} = $bug_flag;
+
+         }
+          elsif ($bug_flag =~ /\>Done:\</) {
+               $bug->{done} = 1;
+          }
+         elsif ($bug_flag =~ /\>Fixed\</) {
+              $bug->{done} = 1;
+         }
+     }
+     # report bug
+
+     $report = '';
+     $report .= 'DONE:' if defined $bug->{done} and $bug->{done};
+     $report .= '#'.$bug->{num}.':'.uc($bug->{severity}).'['.$bug->{package}.'] '.$bug->{title};
+     $report .= ' ('.$bug->{tags}.')' if defined $bug->{tags};
+     $report .= '; ' . $bug->{date};
+     # Avoid reporting so many merged bugs.
+     $report .= ' ['.join(',',splice(@{[split(/,/,$bug->{merged_with})]},0,3)).']' if defined $bug->{merged_with};
+     if ($DEBUG) {
+          use Data::Dumper;
+          print STDERR Dumper($bug);
+     }
+     return $report;
+}
+
+sub package_bugs($){
+
+}
+
+1;
+
+
+__END__
index 8200d4535c322e23a43e8021b1bfad4bb9208466..a9d4d34628a132bc92a3dbc69c088177377ce722 100644 (file)
@@ -15,8 +15,10 @@ sub Parse {
 
     #&::DEBUG("DebianExtra: $args\n");
     if (!defined $args or $args =~ /^$/) {
-       $msg = &debianBugs();
-    } elsif ($args =~ /^(\d+)$/) {
+       &debianBugs();
+    }
+
+    if ($args =~ /^\#?(\d+)$/) {
        # package number:
        $msg = &do_id($args);
     } elsif ($args =~ /^(\S+\@\S+)$/) {
@@ -74,55 +76,56 @@ sub do_id($){
     my $report = join("\n", @results);
 
     # strip down report to relevant header information.
-    $report =~ s/\r//sig;
+#    $report =~ s/\r//sig;
     $report =~ /<BODY[^>]*>(.+?)<HR>/si;
     $report = $1;
     my $bug = {};
-    ($bug->{num}, $bug->{title}) = $report =~ m#\#(\d+)\<\/A\>\<BR\>(.+?)\<\/H1\>#is;
+    ($bug->{num},$bug->{title}) = $report =~ m#\#(\d+)\<\/A\>\<BR\>(.+?)\<\/H1\>#is;
     &::DEBUG("Bugnum: $bug->{num}\n");
     $bug->{title} =~ s/&lt;/\</g;
     $bug->{title} =~ s/&gt;/\>/g;
     $bug->{title} =~ s/&quot;/\"/g;
     &::DEBUG("Title: $bug->{title}\n");
     $bug->{severity} = 'n'; #Default severity is normal
-    my @bug_flags = split /(?<!\&.t);/s, $report;
+    my @bug_flags = split /(?<!\&.t)[;\.]\n/s, $report;
     foreach my $bug_flag (@bug_flags) {
        $bug_flag =~ s/\n//g;
        &::DEBUG("Bug_flag: $bug_flag\n");
-       if ($bug_flag =~ /Severity:/i) {
-           ($bug->{severity}) = $bug_flag =~ /(wishlist|minor|normal|important|serious|grave)/i;
-           # Just leave the leter instead of the whole thing.
-           $bug->{severity} =~ s/^(.).+$/$1/;
-       }
-       elsif ($bug_flag =~ /Package:/) {
-           ($bug->{package}) = $bug_flag =~ /\"\>\s*([^<>]+?)\s*\<\/a\>/;
-           # take packagename out of title if it's there
-           $bug->{title} =~ s/^$bug->{package}: //;
-       }
-       elsif ($bug_flag =~ /Reported by:/) {
-           ($bug->{reporter}) = $bug_flag =~ /\"\>\s*(.+?)\s*\<\/a\>/;
-           # strip &lt; and &gt;
-           $bug->{reporter} =~ s/&lt;/\</g;
-           $bug->{reporter} =~ s/&gt;/\>/g;
-       }
-       elsif ($bug_flag =~ /Date:/) {
-           ($bug->{date}) = $bug_flag =~ /Date:\s*(\w.+?)\s*$/;
-           #ditch extra whitespace
-           $bug->{date} =~ s/\s{2,}/\ /;
-       }
-       elsif ($bug_flag =~ /Tags:/) {
-           ($bug->{tags}) = $bug_flag =~ /strong\>\s*(.+?)\s*\<\/strong\>/;
-       }
-       elsif ($bug_flag =~ /merged with /) {
-           $bug_flag =~ s/merged with\s*//;
-           $bug_flag =~ s/\<[^\>]+\>//g;
-           $bug_flag =~ s/\s//sg;
-           $bug->{merged_with} = $bug_flag;
-
-       }
-       elsif ($bug_flag =~ /\>Done:\</) {
-           $bug->{done} = 1;
-       }
+         if ($bug_flag =~ /Severity:/i) {
+              ($bug->{severity}) = $bug_flag =~ /(wishlist|minor|normal|important|serious|grave)/i;
+              # Just leave the leter instead of the whole thing.
+              $bug->{severity} =~ s/^(.).+$/$1/;
+         }
+         elsif ($bug_flag =~ /Package:/) {
+              ($bug->{package}) = $bug_flag =~ /\"\>\s*([^\<\>\"]+?)\s*\<\/a\>/;
+         }
+         elsif ($bug_flag =~ /Reported by:/) {
+              ($bug->{reporter}) = $bug_flag =~ /\"\>\s*(.+?)\s*\<\/a\>/;
+              # strip &lt; and &gt;
+              $bug->{reporter} =~ s/&lt;/\</g;
+              $bug->{reporter} =~ s/&gt;/\>/g;
+         }
+         elsif ($bug_flag =~ /Date:/) {
+              ($bug->{date}) = $bug_flag =~ /Date:\s*(\w.+?)\s*$/;
+              #ditch extra whitespace
+              $bug->{date} =~ s/\s{2,}/\ /;
+         }
+         elsif ($bug_flag =~ /Tags:/) {
+              ($bug->{tags}) = $bug_flag =~ /strong\>\s*(.+?)\s*\<\/strong\>/;
+         }
+         elsif ($bug_flag =~ /merged with /) {
+              $bug_flag =~ s/merged with\s*//;
+              $bug_flag =~ s/\<[^\>]+\>//g;
+               $bug_flag =~ s/\s//sg;
+              $bug->{merged_with} = $bug_flag;
+
+         }
+          elsif ($bug_flag =~ /\>Done:\</) {
+               $bug->{done} = 1;
+          }
+         elsif ($bug_flag =~ /\>Fixed\</) {
+              $bug->{done} = 1;
+         }
     }
 
     # report bug
@@ -131,7 +134,7 @@ sub do_id($){
     $report .= 'DONE:' if defined $bug->{done} and $bug->{done};
     $report .= '#'.$bug->{num}.':'.uc($bug->{severity}).'['.$bug->{package}.'] '.$bug->{title};
     $report .= ' ('.$bug->{tags}.')' if defined $bug->{tags};
-    $report .= ' ' . $bug->{date};
+    $report .= '; ' . $bug->{date};
     # Avoid reporting so many merged bugs.
     $report .= ' ['.join(',',splice(@{[split(/,/,$bug->{merged_with})]},0,3)).']' if defined $bug->{merged_with};
     if ($::DEBUG) {
@@ -147,11 +150,6 @@ sub old_do_id {
 
     # FIXME
     return "do_id not supported yet.";
-
-    my @results = &::getURL($url);
-    foreach (@results) {
-       &::DEBUG("do_id: $_");
-    }
 }
 
 sub do_email {