check_pgsql: update copyright
[monitoring-plugins.git] / tools / generate-change-log
blobad19ce96a2b7b9198e1fe0c9b11547db3f9565e3
1 #!/usr/bin/env perl
3 # Copyright (c) 2013 Monitoring Plugins Development Team
5 # Originally written by Holger Weiss <holger@zedat.fu-berlin.de>.
7 # This file is free software; the Monitoring Plugins Development Team gives
8 # unlimited permission to copy and/or distribute it, with or without
9 # modifications, as long as this notice is preserved.
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY, to the extent permitted by law; without even the implied
13 # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 use warnings;
17 use strict;
18 use Text::Wrap;
20 # The lines will have a length of no more than $columns - 1.
21 $Text::Wrap::columns = 81;
22 $Text::Wrap::huge = 'overflow';
24 if (system('git rev-parse --git-dir >/dev/null 2>&1') != 0) {
25 print "Not a Git repository, so I won't update the ChangeLog.\n";
26 exit 0;
29 my $regex =
30 '^commit [0-9a-f]+\n' .
31 '^Author: (?<name>.+) <(?<email>.*)>\n' .
32 '^Date: (?<date>\d{4}-\d{2}-\d{2})\n' .
33 '^\n' .
34 '(?<message>(^ .*\n)+)' .
35 '^\n' .
36 '(?<files>(^.+\n)+)';
38 my $git_log = qx'git log -M -C --stat --name-only --date=short';
39 die "Cannot get `git log' output\n" if $? != 0;
41 my ($prev_date, $prev_name, $prev_email);
43 while ($git_log =~ /$regex/gm) {
44 my %commit = %+;
46 if (not defined $prev_date
47 or $commit{date} ne $prev_date
48 or $commit{name} ne $prev_name
49 or $commit{email} ne $prev_email) {
50 print "$commit{date} $commit{name} <$commit{email}>\n\n";
52 $prev_date = $commit{date};
53 $prev_name = $commit{name};
54 $prev_email = $commit{email};
55 $commit{message} =~ s/\s*Signed\-off\-by.*$//sgmx;
57 my @files = split(/\n/, $commit{files});
58 my @message = map { s/^ {4}//; $_ } split(/\n/, $commit{message});
59 my $first_line = shift(@message);
60 $first_line =~ s/^$files[-1]: //;
61 my $intro = sprintf('* %s: %s', join(', ', @files), $first_line);
63 print fill("\t", "\t", $intro), "\n";
64 foreach my $line (@message) {
65 print "\t$line" if length($line) > 0;
66 print "\n";
68 print "\n";