#!/usr/bin/perl # # I really dislike having to enter bugs via a web browser # I much rather have the ability to batch (easily) from the cli # so - heres bugzilla for the cli. # # this requires a cgi script installed on the bugzilla server # called cli.cgi - these scripts should be found together # Copyright (C) 2002 Dennis Cox - dcox@durrow.com # All rights reserved. $VERSION = "v0.5"; $CREATE_DATE = "August 13, 2002"; ############################ # Defines ############################ $DEFAULT_SERVER = "ori"; $DIRECTORY = "/cgi-bin/bugzilla"; $CLI_URI = "/cli.cgi"; $STATUS = "NONE"; # STATUS can be NONE, ALL, or specified ############################ # Includes ############################ # for web request use LWP::Simple; # for cmd line arguments use Getopt::Std; # I tried the html formattext and parser libs # and the problem is it's a pain to load on all the machines # with all the additional packages (it took over 100 packages) # now the problem is without them - you change the bugzilla # webpage and you may need to change the script # another way is to use the bugzilla xml (dtd) stuff # however, that may be more of a hack on a hack # so i'll leave this be # note: recent discussions on the bugzilla mailing list # suggest that 3.0 the engine and the html frontend (which # are currently tied together will be seperate and in that # case things will be much better for those wanting # to format output their own way (such as me!) # bugzilla is a pretty neat tool - got lot'o' options so arguments list # is gonna be scary - i'll go for basic first [a detailed person # will make this really cool] # h = help # s = server # u = user # b = bugid # p = priority # t = bug status # c = component # d = directory # n = no display of header # w = wide getopts("s:st:su:sb:ip:id:sc:shnw"); if($opt_h) { print "bugcli $VERSION $CREATE_DATE dcox\@durrow.com\n"; print "[options]\n"; print " -b bugid [detail report on a single bug]\n"; print " -u userid [will us environment variable USER]\n"; print " [ALL] will dump bugs for all users\n"; print " -t bug status\n"; print " [ALL, UNCONFIRMED, NEW, ASSIGNED, REOPENED, RESOLVED, VERIFIED, CLOSED]\n"; print " If don't specify a status NEW, ASSIGNED and REOPENED are\n"; print " selected by default.\n"; print " -c component\n"; print " -p priority [1-5]\n"; print " -s server [will use environment variable BUGCLI_SERVER]\n"; print " -d directory of bugzilla [will use env var of BUGCLI_DIRECTORY]\n"; print " -w wide listing\n"; print " -h this command you are reading\n"; print " -n Do not display header\n"; print "\n"; print "By default it will use environment variables and display the list\n"; print "of bugs you have open.\n"; # please do this # print " - If you improve upon this script or fix a bug please drop me a\n"; # print "note so I can modifiy the original and share it with the rest of\n"; # print "the world.\n"; exit; } if($opt_l) { $Lite = 1; } elsif($ENV{BUGCLI_LITE}) { $Lite = 1; } if($opt_t) { $status = $opt_t; } else { $status = $STATUS; } ######## COMPONENT if($opt_c) { $component = $opt_c; } else { $component = "ALL"; } ######### PRIORITY if($opt_p) { $priority = $opt_p } else { $priority = 0; } if($opt_s) { $SERVER = $opt_s; } elsif($ENV{BUGCLI_SERVER}) { $SERVER = $ENV{BUGCLI_SERVER}; } else { $SERVER = $DEFAULT_SERVER; } if($opt_d) { $DIRECTORY = $opt_d; } elsif($ENV{BUGCLI_DIRECTORY}) { $DIRECTORY = $ENV{BUGCLI_DIRECTORY}; } if($opt_u) { $USER = $opt_u; } elsif($ENV{USER}) { $USER = $ENV{USER}; } else { if(!$BUGID) { print "error: user unknown\n"; exit; } } if($opt_b) { $BUGID = $opt_b; } ################################ # Display single bug by id ################################ if($BUGID) { $request = sprintf("http://%s%s%s?bug=%s",$SERVER,$DIRECTORY,$CLI_URI,$BUGID); $content = get $request; ($component, $priority, $short_desc, $creation_ts, $bug_status, $bug_severity, $assigned_to, $product, $longdesc) = split(/:jaeger:/,$content); print "******************************************************\n"; print "BugId: $BUGID Assigned: $assigned_to\n"; print "Severity: $bug_severity Status: $bug_status\n"; print "Priority: $priority Created: $creation_ts\n"; print "Product: $product\n"; print "Component: $component\n"; print "Summary: $short_desc\n"; print "Description:\n"; print "$longdesc\n"; print "******************************************************\n"; } ########################### # Display list of bugs ########################### else { if ($opt_w) { $~ = FMT_OUTPUT_WIDE; } else { $~ = FMT_OUTPUT_NARROW; } $request = sprintf("http://%s%s%s?bug=all&user=%s&status=%s&component=%s&priority=%s",$SERVER,$DIRECTORY,$CLI_URI,$USER,$status,$component,$priority); $content = get $request; if(!$opt_n) { $bug_id = "Id"; $bug_status = "Status"; $priority = "Priority"; $bug_severity = "Severity"; $creation_ts = "Date"; $component = "Component"; $short_desc = "Description"; print "*************************************************************************\n"; write(); print "*************************************************************************\n"; } @values = split /\n/, $content; foreach $line (@values) { chomp($line); ($component, $priority, $short_desc, $creation_ts, $bug_status, $bug_severity, $bug_id) = split(/:jaeger:/,$line); write(); # print "$bug_id $bug_status $priority $bug_severity $creation_ts $component $short_desc\n"; } } format FMT_OUTPUT_NARROW = @<<<< @<<<<<<< @< @<<<<< @<<<<<<<<< @<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<< $bug_id, $bug_status, $priority, $bug_severity,$creation_ts,$component,$short_desc . format FMT_OUTPUT_WIDE = @<<<< @<<<<<<< @< @<<<<< @<<<<<<<<< @<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $bug_id, $bug_status, $priority, $bug_severity,$creation_ts,$component,$short_desc ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $short_desc ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $short_desc .