#!/usr/bin/perl # -*-Perl-*- # # Perl filter to handle the log messages from the checkin of files in # a directory. This script will group the lists of files by log # message, and mail a single consolidated log message at the end of # the commit. # # This file assumes a pre-commit checking program that leaves the # names of the first and last commit directories in a temporary file. # # Contributed by David Hampton # # hacked greatly by Greg A. Woods # # Then chopped down just to send bugzilla email, for git. use POSIX; use DBI; # # Configurable options # $TMPDIR = "/sourceware/cvs-tmp"; $BMAILER = "/usr/sbin/sendmail"; # # Subroutines # sub see_if_bugzilla_bug_exists { local ($dbh, $product, $id) = @_; # Split $PRODUCT and SQL-ify. my $sql_product = ''; foreach $i (split (/\s+/, $product)) { if ($sql_product ne '') { $sql_product .= ', '; } $sql_product .= "'" . $i . "'"; } my $sth2 = $dbh->prepare ("SELECT COUNT(*) from bugs where bug_id = $id and product_id = any (select products.id from products where name in ($sql_product))") or return 0; $sth2->execute() or return 0; my $count = $sth2->fetchrow_array (); return $count > 0; } sub mail_bug_notification { local($name, $subject, @text) = @_; open(MAIL, "| $BMAILER -f\"cvs-commit\@gcc.gnu.org\" $name"); print MAIL "From: cvs-commit\@gcc.gnu.org\n"; print MAIL "Subject: $subject\n"; print MAIL "To: $name\n"; print MAIL "\n"; print MAIL join("\n", @text), "\n"; close(MAIL); } # # Main Body # # Initialize basic variables # $debug = 0; chop($hostname = `hostname`); # Parse command line arguments. while (@ARGV) { $arg = shift @ARGV; if ($arg eq '-d') { $debug = 1; print STDERR "Debug turned on...\n"; } elsif ($arg eq '-G') { ($bugzillaproduct) && die("Too many '-G' args\n"); $bugzillaproduct = shift @ARGV; } } if ($hostname !~ /\./) { chop($domainname = `domainname`); $hostdomain = $hostname . "." . $domainname; } else { $hostdomain = $hostname; } # Used with sprintf to form name of Gnats notification mailing list. # %s argument comse from -G option. $GNATS_MAIL_FORMAT = "%s-bugzilla\@$hostdomain"; # Collect the body of the commit message. while () { chop; push (@text, $_); } $log_txt = join ("\n", @text); %done_ids = {}; while ($log_txt =~ m/[^Aa](?:bug|PR|BZ)\s+\#?\s*(?:[a-z+-]+\/)?(?:\/)?(\d+)(.*)$/si) { $bug_id = $1; $log_txt = $2; if (!defined $done_ids{$bug_id}) { $done_ids{$bug_id} = 1; # Send mail to Bugzilla, if required. if ($bugzillaproduct ne '') { my $dbh = undef; if ($bugzillaproduct eq 'gcc') { $dbh = DBI->connect ("dbi:mysql:bugs", "root", "HAHAHA"); } else # elsif ($bugzillaproduct eq 'glibc') { $dbh = DBI->connect ("dbi:mysql:sourcesbugs", "root", "HAHAHA"); } if ($debug) { print STDERR "Attempting to see if bug $bug_id exists\n"; } if (defined $dbh && &see_if_bugzilla_bug_exists ($dbh, $bugzillaproduct, $bug_id)) { if ($debug) { print STDERR "It does\n"; } if ($bugzillaproduct ne 'gcc') { &mail_bug_notification( sprintf ($GNATS_MAIL_FORMAT, "sourceware"), "[Bug $bug_id]", @text); } else { &mail_bug_notification( sprintf ($GNATS_MAIL_FORMAT, $bugzillaproduct), "[Bug $bug_id]", @text); } } if (defined $dbh) { $dbh->disconnect; } } } } exit 0;