generate-change-log 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env perl
  2. #
  3. # Copyright (c) 2013-2014 Nagios Plugins Development Team
  4. #
  5. # Originally written by Holger Weiss <holger@zedat.fu-berlin.de>.
  6. #
  7. # This file is free software; the Nagios 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.
  10. #
  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.
  14. #
  15. use warnings;
  16. use strict;
  17. use Text::Wrap;
  18. # The lines will have a length of no more than $columns - 1.
  19. $Text::Wrap::columns = 81;
  20. $Text::Wrap::huge = 'overflow';
  21. if (system('git rev-parse --git-dir >/dev/null 2>&1') != 0) {
  22. print "Not a Git repository, so I won't update the ChangeLog.\n";
  23. exit 0;
  24. }
  25. my $regex =
  26. '^commit [0-9a-f]+\n' .
  27. '^Author: (?<name>.+) <(?<email>.*)>\n' .
  28. '^Date: (?<date>\d{4}-\d{2}-\d{2})\n' .
  29. '^\n' .
  30. '(?<message>(^ .*\n)+)' .
  31. '^\n' .
  32. '(?<files>(^.+\n)+)';
  33. my $git_log = qx'git log -M -C --stat --name-only --date=short';
  34. die "Cannot get `git log' output\n" if $? != 0;
  35. my ($prev_date, $prev_name, $prev_email);
  36. while ($git_log =~ /$regex/gm) {
  37. my %commit = %+;
  38. if (not defined $prev_date
  39. or $commit{date} ne $prev_date
  40. or $commit{name} ne $prev_name
  41. or $commit{email} ne $prev_email) {
  42. print "$commit{date} $commit{name} <$commit{email}>\n\n";
  43. }
  44. $prev_date = $commit{date};
  45. $prev_name = $commit{name};
  46. $prev_email = $commit{email};
  47. $commit{message} =~ s/\s*Signed\-off\-by.*$//sgmx;
  48. my @files = split(/\n/, $commit{files});
  49. my @message = map { s/^ {4}//; $_ } split(/\n/, $commit{message});
  50. my $first_line = shift(@message);
  51. $first_line =~ s/^$files[-1]: //;
  52. my $intro = sprintf('* %s: %s', join(', ', @files), $first_line);
  53. print fill("\t", "\t", $intro), "\n";
  54. foreach my $line (@message) {
  55. print "\t$line" if length($line) > 0;
  56. print "\n";
  57. }
  58. print "\n";
  59. }