#!/usr/bonsaitools/bin/perl -wT # -*- Mode: perl; indent-tabs-mode: nil -*- # # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # implied. See the License for the specific language governing # rights and limitations under the License. # # The Original Code is the Bugzilla Bug Tracking System. # # The Initial Developer of the Original Code is Netscape Communications # Corporation. Portions created by Netscape are # Copyright (C) 1998 Netscape Communications Corporation. All # Rights Reserved. # # Contributor(s): Harrison Page , # Terry Weissman , # Dawn Endico # Bryce Nesbitt , # Added -All- report, change "nobanner" to "banner" (it is strange to have a # list with 2 positive and 1 negative choice), default links on, add show # sql comment. # Joe Robins , # If using the usebuggroups parameter, users shouldn't be able to see # reports for products they don't have access to. # Gervase Markham and Adam Spiers # Added ability to chart any combination of resolutions/statuses. # Derive the choice of resolutions/statuses from the -All- data file # Removed hardcoded order of resolutions/statuses when reading from # daily stats file, so now works independently of collectstats.pl # version # Added image caching by date and datasets # Myk Melez \&most_doomed, "most_doomed_for_milestone" => \&most_doomed_for_milestone, "most_recently_doomed" => \&most_recently_doomed, "show_chart" => \&show_chart, ); # If we're using bug groups for products, we should apply those restrictions # to viewing reports, as well. Time to check the login in that case. ConnectToDatabase(1); quietly_check_login(); GetVersionTable(); # If the usebuggroups parameter is set, we don't want to list all products. # We only want those products that the user has permissions for. my @myproducts; if(Param("usebuggroups")) { push( @myproducts, "-All-"); foreach my $this_product (@legal_product) { if(GroupExists($this_product) && !UserInGroup($this_product)) { next; } else { push( @myproducts, $this_product ) } } } else { push( @myproducts, "-All-", @legal_product ); } if (! defined $FORM{'product'}) { print "Content-type: text/html\n\n"; PutHeader("Bug Reports"); &choose_product; PutFooter(); } else { # For security and correctness, validate the value of the "product" form variable. # Valid values are those products for which the user has permissions which appear # in the "product" drop-down menu on the report generation form. grep($_ eq $FORM{'product'}, @myproducts) || DisplayError("You entered an invalid product name.") && exit; # If usebuggroups is on, we don't want people to be able to view # reports for products they don't have permissions for... Param("usebuggroups") && GroupExists($FORM{'product'}) && !UserInGroup($FORM{'product'}) && DisplayError("You do not have the permissions necessary to view reports for this product.") && exit; # For security and correctness, validate the value of the "output" form variable. # Valid values are the keys from the %reports hash defined above which appear in # the "output" drop-down menu on the report generation form. $FORM{'output'} ||= "most_doomed"; # a reasonable default grep($_ eq $FORM{'output'}, keys %reports) || DisplayError("You entered an invalid output type.") && exit; # Output appropriate HTTP response headers print "Content-type: text/html\n"; # Changing attachment to inline to resolve 46897 - zach@zachlipton.com print "Content-disposition: inline; filename=bugzilla_report.html\n\n"; if ($FORM{'banner'}) { PutHeader("Bug Reports"); } else { print("Bug Reports"); } # Execute the appropriate report generation function # (the one whose name is the same as the value of the "output" form variable). &{$reports{$FORM{'output'}}}; # ??? why is this necessary? formatting looks fine without it print "

"; PutFooter() if $FORM{banner}; } ################################## # user came in with no form data # ################################## sub choose_product { my $product_popup = make_options (\@myproducts, $myproducts[0]); my $datafile = daily_stats_filename('-All-'); # Can we do bug charts? my $do_charts = ($use_gd && -d $dir && -d $graph_dir && open(DATA, "$dir/$datafile")); my $charts = $do_charts ? "

Welcome to the Bugzilla Query Kitchen

FIN if ($do_charts) { print < FIN } print <
Product:
Output:
Chart datasets:
Switches:  Links to Bugs
 Banner
FIN if (Param('usequip')) { print " Quip
"; } else { print ""; } print <

FIN #Add this above to get a control for showing the SQL query: # Show SQL
} sub most_doomed { my $when = localtime (time); print <

Bug Report for $FORM{'product'}

$when

FIN # Build up $query string my $query; $query = <$query

\n" unless (! exists $FORM{'showsql'}); SendSQL ($query); my $c = 0; my $quip = "Summary"; my $bugs_count = 0; my $bugs_new_this_week = 0; my $bugs_reopened = 0; my %bugs_owners; my %bugs_summary; my %bugs_status; my %bugs_totals; my %bugs_lookup; ############################# # suck contents of database # ############################# my $week = 60 * 60 * 24 * 7; while (my ($bid, $st, $who, $ts) = FetchSQLData()) { next if (exists $bugs_lookup{$bid}); $bugs_lookup{$bid} ++; $bugs_owners{$who} ++; $bugs_new_this_week ++ if (time - $ts <= $week); $bugs_status{$st} ++; $bugs_count ++; push @{$bugs_summary{$who}{$st}}, $bid; $bugs_totals{$who}{$st} ++; } if ($FORM{'quip'}) { if (open (COMMENTS, ") { push @cdata, $_; } close COMMENTS; $quip = "" . $cdata[int(rand($#cdata + 1))] . ""; } } ######################### # start painting report # ######################### $bugs_status{'NEW'} ||= '0'; $bugs_status{'ASSIGNED'} ||= '0'; $bugs_status{'REOPENED'} ||= '0'; print <$quip
New Bugs This Week $bugs_new_this_week
Bugs Marked New $bugs_status{'NEW'}
Bugs Marked Assigned $bugs_status{'ASSIGNED'}
Bugs Marked Reopened $bugs_status{'REOPENED'}
Total Bugs $bugs_count

FIN if ($bugs_count == 0) { print "No bugs found!\n"; PutFooter() if $FORM{banner}; exit; } print <Bug Count by Engineer FIN foreach my $who (sort keys %bugs_summary) { my $bugz = 0; print < FIN foreach my $st (@status) { $bugs_totals{$who}{$st} += 0; print <$bugs_totals{$who}{$st} FIN $bugz += $#{$bugs_summary{$who}{$st}} + 1; } print <$bugz FIN } print <

FIN ############################### # individual bugs by engineer # ############################### print <Individual Bugs by Engineer

Owner New Assigned Reopened Total
$who
FIN foreach my $who (sort keys %bugs_summary) { print < FIN foreach my $st (@status) { my @l; foreach (sort { $a <=> $b } @{$bugs_summary{$who}{$st}}) { if ($FORM{'links'}) { push @l, "$_\n"; } else { push @l, $_; } } my $bugz = join ' ', @l; $bugz = " " unless ($bugz); print <$bugz FIN } print < FIN } print <

FIN } sub daily_stats_filename { my ($prodname) = @_; $prodname =~ s/\//-/gs; return $prodname; } sub show_chart { # if we don't have the graphic mouldes don't even try to go # here. Should probably return some decent error message. return unless $use_gd; if (! $FORM{datasets}) { die_politely("You didn't select any datasets to plot"); } print < FIN my $type = chart_image_type(); my $data_file = daily_stats_filename($FORM{product}); my $image_file = chart_image_name($data_file, $type); my $url_image = "$graph_dir/" . url_quote($image_file); if (! -e "$graph_dir/$image_file") { generate_chart("$dir/$data_file", "$graph_dir/$image_file", $type); } print <

FIN } sub chart_image_type { # what chart type should we be generating? my $testimg = Chart::Lines->new(2,2); my $type = $testimg->can('gif') ? "gif" : "png"; undef $testimg; return $type; } sub chart_image_name { my ($data_file, $type) = @_; # Cache charts by generating a unique filename based on what they # show. Charts should be deleted by collectstats.pl nightly. my $id = join ("_", split (":", $FORM{datasets})); return "${data_file}_${id}.$type"; } sub day_of_year { my ($mday, $month, $year) = (localtime())[3 .. 5]; $month += 1; $year += 1900; my $date = sprintf "%02d%02d%04d", $mday, $month, $year; } sub generate_chart { my ($data_file, $image_file, $type) = @_; if (! open FILE, $data_file) { &die_politely ("The tool which gathers bug counts has not been run yet."); } my @fields; my @labels = qw(DATE); my %datasets = map { $_ => 1 } split /:/, $FORM{datasets}; my %data = (); while () { chomp; next unless $_; if (/^#/) { if (/^# fields?: (.*)\s*$/) { @fields = split /\||\r/, $1; &die_politely("`# fields: ' line didn't start with DATE, but with $fields[0]") unless $fields[0] =~ /date/i; push @labels, grep($datasets{$_}, @fields); } next; } &die_politely("`# fields: ' line was not found before start of data") unless @fields; my @line = split /\|/; my $date = $line[0]; my ($yy, $mm, $dd) = $date =~ /^\d{2}(\d{2})(\d{2})(\d{2})$/; push @{$data{DATE}}, "$mm/$dd/$yy"; for my $i (1 .. $#fields) { my $field = $fields[$i]; if (! defined $line[$i] or $line[$i] eq '') { # no data point given, don't plot (this will probably # generate loads of Chart::Base warnings, but that's not # our fault.) push @{$data{$field}}, undef; } else { push @{$data{$field}}, $line[$i]; } } } shift @labels; close FILE; if (! @{$data{DATE}}) { &die_politely ("We don't have enough data points to make a graph (yet)"); } my $img = Chart::Lines->new (800, 600); my $i = 0; my $MAXTICKS = 20; # Try not to show any more x ticks than this. my $skip = 1; if (@{$data{DATE}} > $MAXTICKS) { $skip = int((@{$data{DATE}} + $MAXTICKS - 1) / $MAXTICKS); } my %settings = ( "title" => "Status Counts for $FORM{'product'}", "x_label" => "Dates", "y_label" => "Bug Counts", "legend_labels" => \@labels, "skip_x_ticks" => $skip, "y_grid_lines" => "true", "grey_background" => "false", "colors" => { # default dataset colours are too alike dataset4 => [0, 0, 0], # black }, ); $img->set (%settings); $img->$type($image_file, [ @data{('DATE', @labels)} ]); } sub die_politely { my $msg = shift; print <

Owner New Assigned Reopened
$who
Sorry, but ...

There is no graph available for $FORM{'product'}

$msg

FIN PutFooter() if $FORM{banner}; exit; } sub bybugs { $bugsperperson{$a} <=> $bugsperperson{$b} } sub most_doomed_for_milestone { my $when = localtime (time); my $ms = "M" . Param("curmilestone"); my $quip = "Summary"; print "

\n

"; if( $FORM{'product'} ne "-All-" ) { SendSQL("SELECT defaultmilestone FROM products WHERE product = " . SqlQuote($FORM{'product'})); $ms = FetchOneColumn(); print "Most Doomed for $ms ($FORM{'product'})"; } else { print "Most Doomed for $ms"; } print "

\n$when

\n"; ######################### # start painting report # ######################### if ($FORM{'quip'}) { if (open (COMMENTS, ") { push @cdata, $_; } close COMMENTS; $quip = "" . $cdata[int(rand($#cdata + 1))] . ""; } } # Build up $query string my $query; $query = "select distinct assigned_to from bugs where target_milestone=\"$ms\""; if ($FORM{'product'} ne "-All-" ) { $query .= "and bugs.product=".SqlQuote($FORM{'product'}); } $query .= <\n"; print "\n"; print "$totalpeople engineers have $bugtotal $ms bugs and features.\n"; print "\n"; while (@people) { $person = pop @people; print "\n"; SendSQL("select login_name from profiles where userid=$person"); my $login_name= FetchSQLData(); print("\n"); print("$bugsperperson{$person} bugs and features"); print(""); print(" for \n"); print(""); print("$login_name"); print("\n"); print("\n"); $person = pop @people; if ($person) { SendSQL("select login_name from profiles where userid=$person"); my $login_name= FetchSQLData(); print("\n"); print("$bugsperperson{$person} bugs and features"); print(""); print(" for \n"); print(""); print("$login_name"); print("\n"); print("\n\n"); } } print "\n"; } sub most_recently_doomed { my $when = localtime (time); my $ms = "M" . Param("curmilestone"); my $quip = "Summary"; print "

\n

"; if( $FORM{'product'} ne "-All-" ) { SendSQL("SELECT defaultmilestone FROM products WHERE product = " . SqlQuote($FORM{'product'})); $ms = FetchOneColumn(); print "Most Recently Doomed ($FORM{'product'})"; } else { print "Most Recently Doomed"; } print "

\n$when

\n"; ######################### # start painting report # ######################### if ($FORM{'quip'}) { if (open (COMMENTS, ") { push @cdata, $_; } close COMMENTS; $quip = "" . $cdata[int(rand($#cdata + 1))] . ""; } } # Build up $query string my $query = "select distinct assigned_to from bugs where bugs.bug_status='NEW' and target_milestone='' and bug_severity!='enhancement' and status_whiteboard='' and (product='Browser' or product='MailNews')"; if ($FORM{'product'} ne "-All-" ) { $query .= "and bugs.product=".SqlQuote($FORM{'product'}); } # End build up $query string SendSQL ($query); my @people = (); while (my ($person) = FetchSQLData()) { push @people, $person; } ############################# # suck contents of database # ############################# my $person = ""; my $bugtotal = 0; foreach $person (@people) { my $query = "select count(bug_id) from bugs,profiles where bugs.bug_status='NEW' and userid=assigned_to and userid='$person' and target_milestone='' and bug_severity!='enhancement' and status_whiteboard='' and (product='Browser' or product='MailNews')"; if( $FORM{'product'} ne "-All-" ) { $query .= "and bugs.product='$FORM{'product'}'"; } SendSQL ($query); my $bugcount = FetchSQLData(); $bugsperperson{$person} = $bugcount; $bugtotal += $bugcount; } # sort people by the number of bugs they have assigned to this milestone @people = sort bybugs @people; my $totalpeople = @people; if ($totalpeople > 20) { splice @people, 0, $totalpeople-20; } print "\n"; print "\n"; while (@people) { $person = pop @people; print "\n\n"); } } print "
\n"; print "$totalpeople engineers have $bugtotal untouched new bugs.\n"; if ($totalpeople > 20) { print "These are the 20 most doomed."; } print "
\n"; SendSQL("select login_name from profiles where userid=$person"); my $login_name= FetchSQLData(); print("\n"); print("$bugsperperson{$person} bugs"); print(""); print(" for \n"); print(""); print("$login_name"); print("\n"); print("\n"); $person = pop @people; if ($person) { SendSQL("select login_name from profiles where userid=$person"); my $login_name= FetchSQLData(); print("\n"); print("$bugsperperson{$person} bugs"); print(""); print(" for \n"); print(""); print("$login_name"); print("\n"); print("
\n"; }