14 use lib "$FindBin::Bin/../lib";
20 # ------------------------------------------------------------------------
26 my $bz = WWW::Bugzilla->new(
27 server => $cfg->{bugzilla}{server},
28 email => $cfg->{bugzilla}{user},
29 password => $cfg->{bugzilla}{pass},
30 bug_number => $set->{bug}
31 ) || croak "Cannot open bz - $!";
33 my $header = sprintf( "Git commit: %s/commitdiff/%s\n", $cfg->{gitweb}, $info->{rev} );
34 if ( scalar( @{ $info->{diff} } ) > 50 ) {
36 # big diff - we skip the diff
37 $bz->additional_comments(
38 join( "\n", $header, @{ $info->{info} }, '', @{ $info->{log} }, '----', @{ $info->{diffstat} } ) );
42 # otherwise we do the whole thing
43 $bz->additional_comments( join( "\n", $header, @{ $info->{all} } ) );
46 $bz->change_status("fixed") if ( $set->{action} eq 'fixes' );
47 $bz->change_status("closed") if ( $set->{action} eq 'closes' );
51 printf( "[%d] %s %s [%s]\n", $set->{bug}, $info->{rev}, $info->{log}[0], $set->{action} );
54 # ------------------------------------------------------------------------
55 sub find_bugzilla_references {
62 foreach my $line ( @{ $info->{log} } ) {
64 if ( $line =~ /(closes|fixes|references):?\s*(?:bug(?:zilla)?)?\s*\#?(\d+)/ ) {
68 elsif ( $line =~ /\b(?:bug(?:zilla)?)\s*\#?(\d+)/ ) {
69 $action = 'references';
77 $action = 'closes' if ( $action =~ /^fix/ );
79 push( @results, { bug => $bugid, action => $action } );
80 ##printf( "%s\n\taction = %s bugid = %s\n", $info->{rev}, $action, $bugid );
85 # ------------------------------------------------------------------------
91 my @lines = $git->run( 'show', '-M', '-C', '--patch-with-stat', '--pretty=fuller', $rev );
99 all => [@lines], # deliberate copy
102 while ( my $line = shift @lines ) {
103 last if ( $line =~ /^$/ );
104 push( @{ $info->{info} }, $line );
107 while ( my $line = shift @lines ) {
108 last if ( $line =~ /^---\s*$/ );
109 push( @{ $info->{log} }, $line );
112 while ( my $line = shift @lines ) {
113 last if ( $line =~ /^$/ );
114 push( @{ $info->{diffstat} }, $line );
118 $info->{diff} = \@lines;
123 # ------------------------------------------------------------------------
125 sub walk_git_commits {
129 my $lastrev = $git->run( 'rev-parse', $cfg->{lastref} );
130 my $headrev = $git->run( 'rev-parse', $cfg->{branch_head} );
132 return if ( $lastrev eq $headrev );
134 my @revs = $git->run( 'rev-list', '--topo-order', '--no-merges', ( $lastrev . '..' . $headrev ) );
136 foreach my $rev ( reverse(@revs) ) {
137 my $info = git_commit_info( $git, $rev );
140 #dd( $info->{info}, $info->{log}[0] );
141 my @sets = find_bugzilla_references( $info, $cfg );
142 foreach my $set (@sets) {
143 update_bugzilla( $cfg, $info, $set );
149 # ------------------------------------------------------------------------
156 'config=s' => \$config,
158 'verbose!' => \$verbose,
159 ) or die "Incorrect options";
160 die "No config file given\n" unless ( $config and -f $config );
161 my $cfg = ( values( %{ Config::Any->load_files( { files => [$config], use_ext => 1 } )->[0] } ) )[0];
163 die "No git_dir specified\n" unless ( $cfg->{git_dir} );
164 $cfg->{lasttag} ||= $cfg->{git_dir} . '/refs/tags/BugzillaDone';
165 $cfg->{branch_head} ||= 'HEAD';
167 $cfg->{lastref} = -f $cfg->{lasttag} ? read_file( $cfg->{lasttag} ) : 'HEAD';
168 chomp( $cfg->{lastref} );
170 my $git = Git::Repository->new( git_dir => $cfg->{git_dir} ) || die "No valid git repo\n";
172 my $newlast = walk_git_commits( $git, $cfg );
174 write_file( $cfg->{lasttag}, $newlast );