15 use lib "$FindBin::Bin/../lib";
21 # ------------------------------------------------------------------------
27 my $bz = WWW::Bugzilla->new(
28 server => $cfg->{bugzilla}{server},
29 email => $cfg->{bugzilla}{user},
30 password => $cfg->{bugzilla}{pass},
31 bug_number => $set->{bug}
32 ) || croak "Cannot open bz - $!";
36 sprintf( "Git commit: %s/commitdiff/%s\n", $cfg->{gitweb}, $info->{rev} );
37 if ( scalar( @{ $info->{diff} } ) > 50 ) {
39 # big diff - we skip the diff
40 $bz->additional_comments(
42 $header, @{ $info->{info} }, '',
43 @{ $info->{log} }, '----', @{ $info->{diffstat} } )
48 # otherwise we do the whole thing
49 $bz->additional_comments( join( "\n", $header, @{ $info->{all} } ) );
52 $bz->change_status("fixed") if ( $set->{action} =~ /fixes/ );
53 $bz->change_status("closed") if ( $set->{action} =~ /closes/ );
56 try { $bz->commit; } catch { warn "Error from bugzilla commit - $_"; };
58 printf( "[%d] %s %s [%s]\n",
59 $set->{bug}, $info->{rev}, $info->{log}[0], $set->{action} );
62 # ------------------------------------------------------------------------
63 sub find_bugzilla_references {
70 foreach my $line ( @{ $info->{log} } ) {
73 /(closes|fixes|references):?\s*(?:bug(?:zilla)?)?\s*\#?(\d+)/ )
78 elsif ( $line =~ /\b(?:bug(?:zilla)?)\s*\#?(\d+)/ ) {
79 $action = 'references';
88 push( @results, { bug => $bugid, action => $action } );
89 ##printf( "%s\n\taction = %s bugid = %s\n", $info->{rev}, $action, $bugid );
94 # ------------------------------------------------------------------------
101 $git->run( 'show', '-M', '-C', '--patch-with-stat', '--pretty=fuller',
110 all => [@lines], # deliberate copy
113 while ( my $line = shift @lines ) {
114 last if ( $line =~ /^$/ );
115 push( @{ $info->{info} }, $line );
118 while ( my $line = shift @lines ) {
119 last if ( $line =~ /^---\s*$/ );
120 push( @{ $info->{log} }, $line );
123 while ( my $line = shift @lines ) {
124 last if ( $line =~ /^$/ );
125 push( @{ $info->{diffstat} }, $line );
129 $info->{diff} = \@lines;
134 # ------------------------------------------------------------------------
136 sub walk_git_commits {
140 my $lastrev = $git->run( 'rev-parse', $cfg->{lastref} );
141 my $headrev = $git->run( 'rev-parse', $cfg->{branch_head} );
143 return if ( $lastrev eq $headrev );
145 my @revs = $git->run( 'rev-list', '--topo-order', '--no-merges',
146 ( $lastrev . '..' . $headrev ) );
148 foreach my $rev ( reverse(@revs) ) {
149 my $info = git_commit_info( $git, $rev );
152 #dd( $info->{info}, $info->{log}[0] );
153 my @sets = find_bugzilla_references( $info, $cfg );
154 foreach my $set (@sets) {
155 update_bugzilla( $cfg, $info, $set );
161 # ------------------------------------------------------------------------
168 'config=s' => \$config,
170 'verbose!' => \$verbose,
171 ) or die "Incorrect options";
172 die "No config file given\n" unless ( $config and -f $config );
175 %{ Config::Any->load_files( { files => [$config], use_ext => 1 } )
181 die "No git_dir specified\n" unless ( $cfg->{git_dir} );
182 $cfg->{lasttag} ||= $cfg->{git_dir} . '/refs/tags/BugzillaDone';
183 $cfg->{branch_head} ||= 'HEAD';
186 -f $cfg->{lasttag} ? read_file( $cfg->{lasttag} ) : 'HEAD';
187 chomp( $cfg->{lastref} );
189 my $git = Git::Repository->new( git_dir => $cfg->{git_dir} )
190 || die "No valid git repo\n";
192 my $newlast = walk_git_commits( $git, $cfg );
194 write_file( $cfg->{lasttag}, $newlast );