public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Format of patterns recognized in commit messages for auto-posting in bugs
@ 2022-04-22 17:49 Simon Marchi
  2022-04-22 18:11 ` Joel Brobecker
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Marchi @ 2022-04-22 17:49 UTC (permalink / raw)
  To: gdb; +Cc: Joel Brobecker

Hi Joel,

What are the formats recognized by the git hooks to detect that a commit
refers to a Bugzilla bug, and post a message on that bug?  We used to
write "PR gdb/1234" and it was recognized.  Now, we use "Bug:" trailers,
like in this commit:

https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=152a17495663ae9099d5efdc38322c9ad348014e

... but it doesn't seem recognized.  Would it be possible to recognize
Bugzilla URLs?

Simon

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Format of patterns recognized in commit messages for auto-posting in bugs
  2022-04-22 17:49 Format of patterns recognized in commit messages for auto-posting in bugs Simon Marchi
@ 2022-04-22 18:11 ` Joel Brobecker
  0 siblings, 0 replies; 2+ messages in thread
From: Joel Brobecker @ 2022-04-22 18:11 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb, Joel Brobecker

[-- Attachment #1: Type: text/plain, Size: 910 bytes --]

> What are the formats recognized by the git hooks to detect that a commit
> refers to a Bugzilla bug, and post a message on that bug?  We used to
> write "PR gdb/1234" and it was recognized.  Now, we use "Bug:" trailers,
> like in this commit:
> 
> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=152a17495663ae9099d5efdc38322c9ad348014e
> 
> ... but it doesn't seem recognized.  Would it be possible to recognize
> Bugzilla URLs?

This is actually not handled by the git-hooks themselves.
The hooks are simply configured to pass the information
to a script which already exists prior to the hooks themselves.

     # Send a copy to bugzilla if a commit has a PR number in it.
     file-commit-cmd = "/sourceware/infra/bin/email-to-bugzilla -G 'gdb binutils'"

I'm attaching the script to this email. Not sure who maintains
that script, though. It doesn't look hard to enhance it further.

-- 
Joel

[-- Attachment #2: email-to-bugzilla --]
[-- Type: text/plain, Size: 3411 bytes --]

#!/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 <hampton@cisco.com>
#
# hacked greatly by Greg A. Woods <woods@web.net>
#
# Then chopped down just to send bugzilla email, for git.
use strict;

use POSIX;
use DBI;
use Mail::Header;
use Mail::Internet;

my $bugzillaproduct;

#
#	Subroutines
#
sub see_if_bugzilla_bug_exists {    
  my ($dbh, $product, $id) = @_;

  # Split $PRODUCT and SQL-ify.
  my $sql_product = '';
  for my $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 {
    my $name = shift;
    my $subject = shift;
    my $head = Mail::Header->new;
    $head->add('From', 'cvs-commit@gcc.gnu.org');
    $head->add('Subject', $subject);
    $head->add('To', $name);
    my $mail = Mail::Internet->new(Header => $head, Body => \@_);
    die "email send failed\n" if !$mail->send;
}

#
#	Main Body
#

# Initialize basic variables
#
my $debug = 0;

# Parse command line arguments.

while (my $arg = shift @ARGV) {
    if ($arg eq '-d') {
	$debug = 1;
	print STDERR "Debug turned on...\n";
    } elsif ($arg eq '-G') {
	die "Too many '-G' args\n" if $bugzillaproduct;
	$bugzillaproduct = shift @ARGV;
    }
}

# Used with sprintf to form name of Gnats notification mailing list.
# %s argument comse from -G option.
my $MAIL_FORMAT = '%s-bugzilla@localhost';

# Collect the body of the commit message.
binmode STDIN, ":utf8";
my @text = ();
while (<STDIN>) {
    push (@text, $_);
}

my $log_txt = join ('', @text);
my %done_ids = {};

# fche/jakub 2020-04-01 ... this following matches "Apr" and spams PR1
#while ($log_txt =~ m/[^Aa]?(?:bug|PR|BZ)\s+\#?\s*(?:[a-z+-]+\/)?(?:\/)?(\d+)(.*)$/si) {

while ($log_txt =~ m/\s(?:bug|PR|BZ)\s+\#?\s*(?:[a-z0-9+-]+\/)?(?:\/)?(\d+)(.*)$/si) {
    my $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", "swbugz", "everythingroses");
	    } else  {# elsif ($bugzillaproduct eq 'glibc')
		$dbh = DBI->connect ("dbi:mysql:sourcesbugs", "swbugz", "everythingroses");
	    }
	    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 ($MAIL_FORMAT, "sourceware"), "[Bug $bug_id]", @text);
		} else { 
		    mail_bug_notification( sprintf ($MAIL_FORMAT, $bugzillaproduct), "[Bug $bug_id]", @text);
		}
	    }
	    $dbh->disconnect if defined $dbh;
	}
    }
}

exit 0;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-22 18:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-22 17:49 Format of patterns recognized in commit messages for auto-posting in bugs Simon Marchi
2022-04-22 18:11 ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).