From: Nigel Metheringham Date: Sat, 30 May 2015 09:08:52 +0000 (+0100) Subject: Attempt to fix failing issue on update X-Git-Url: https://git.exim.org/git-perl-utils.git/commitdiff_plain/135face65feb3b899233f8fff0b5091dbabde727 Attempt to fix failing issue on update --- diff --git a/script/git-to-bugzilla.pl b/script/git-to-bugzilla.pl index 9fbddba..c073b11 100755 --- a/script/git-to-bugzilla.pl +++ b/script/git-to-bugzilla.pl @@ -5,11 +5,12 @@ use strict; use warnings; use Carp; use Config::Any; -use Data::Dump; +use Data::Printer; use File::Slurp; use FindBin; use Getopt::Long; use Git::Repository; +use Try::Tiny; use lib "$FindBin::Bin/../lib"; use WWW::Bugzilla; @@ -29,13 +30,18 @@ sub update_bugzilla { password => $cfg->{bugzilla}{pass}, bug_number => $set->{bug} ) || croak "Cannot open bz - $!"; + p $bz if ($debug); - my $header = sprintf( "Git commit: %s/commitdiff/%s\n", $cfg->{gitweb}, $info->{rev} ); + my $header = + sprintf( "Git commit: %s/commitdiff/%s\n", $cfg->{gitweb}, $info->{rev} ); if ( scalar( @{ $info->{diff} } ) > 50 ) { # big diff - we skip the diff $bz->additional_comments( - join( "\n", $header, @{ $info->{info} }, '', @{ $info->{log} }, '----', @{ $info->{diffstat} } ) ); + join( "\n", + $header, @{ $info->{info} }, '', + @{ $info->{log} }, '----', @{ $info->{diffstat} } ) + ); } else { @@ -45,10 +51,12 @@ sub update_bugzilla { $bz->change_status("fixed") if ( $set->{action} =~ /fixes/ ); $bz->change_status("closed") if ( $set->{action} =~ /closes/ ); + p $bz if ($debug); - $bz->commit; + try { $bz->commit; } catch { warn "Error from bugzilla commit - $_"; }; - printf( "[%d] %s %s [%s]\n", $set->{bug}, $info->{rev}, $info->{log}[0], $set->{action} ); + printf( "[%d] %s %s [%s]\n", + $set->{bug}, $info->{rev}, $info->{log}[0], $set->{action} ); } # ------------------------------------------------------------------------ @@ -61,7 +69,9 @@ sub find_bugzilla_references { my $bugid; foreach my $line ( @{ $info->{log} } ) { $line = lc($line); - if ( $line =~ /(closes|fixes|references):?\s*(?:bug(?:zilla)?)?\s*\#?(\d+)/ ) { + if ( $line =~ + /(closes|fixes|references):?\s*(?:bug(?:zilla)?)?\s*\#?(\d+)/ ) + { $action = $1; $bugid = $2; } @@ -87,7 +97,9 @@ sub git_commit_info { my $git = shift; my $rev = shift; - my @lines = $git->run( 'show', '-M', '-C', '--patch-with-stat', '--pretty=fuller', $rev ); + my @lines = + $git->run( 'show', '-M', '-C', '--patch-with-stat', '--pretty=fuller', + $rev ); my $info = { rev => $rev, @@ -130,7 +142,8 @@ sub walk_git_commits { return if ( $lastrev eq $headrev ); - my @revs = $git->run( 'rev-list', '--topo-order', '--no-merges', ( $lastrev . '..' . $headrev ) ); + my @revs = $git->run( 'rev-list', '--topo-order', '--no-merges', + ( $lastrev . '..' . $headrev ) ); foreach my $rev ( reverse(@revs) ) { my $info = git_commit_info( $git, $rev ); @@ -157,16 +170,24 @@ sub walk_git_commits { 'verbose!' => \$verbose, ) or die "Incorrect options"; die "No config file given\n" unless ( $config and -f $config ); - my $cfg = ( values( %{ Config::Any->load_files( { files => [$config], use_ext => 1 } )->[0] } ) )[0]; + my $cfg = ( + values( + %{ Config::Any->load_files( { files => [$config], use_ext => 1 } ) + ->[0] + } + ) + )[0]; die "No git_dir specified\n" unless ( $cfg->{git_dir} ); $cfg->{lasttag} ||= $cfg->{git_dir} . '/refs/tags/BugzillaDone'; $cfg->{branch_head} ||= 'HEAD'; - $cfg->{lastref} = -f $cfg->{lasttag} ? read_file( $cfg->{lasttag} ) : 'HEAD'; + $cfg->{lastref} = + -f $cfg->{lasttag} ? read_file( $cfg->{lasttag} ) : 'HEAD'; chomp( $cfg->{lastref} ); - my $git = Git::Repository->new( git_dir => $cfg->{git_dir} ) || die "No valid git repo\n"; + my $git = Git::Repository->new( git_dir => $cfg->{git_dir} ) + || die "No valid git repo\n"; my $newlast = walk_git_commits( $git, $cfg ); if ($newlast) {