include changes text in release commit and tag
[p5sagit/Distar.git] / helpers / get-changelog
CommitLineData
c6b7b384 1#!/usr/bin/env perl
2use strict;
3use warnings FATAL => 'all';
4use Getopt::Long qw(:config gnu_getopt);
5GetOptions(
6 "p|prefix=s@" => \(my $prefix = []),
7 "s|suffix=s@" => \(my $suffix = []),
8) or die "Error in command line arguments\n";
9
10my $version = shift or die "no version specified!\n";
11my $changelog = @ARGV ? shift : 'Changes';
12
13$version =~ s/\Av//;
14
15open my $fh, '<:raw', $changelog
16 or die "can't open $changelog: $!\n";
17my $version_log = '';
18my $found_version;
19while (my $line = <$fh>) {
20 if ($found_version) {
21 last
22 if $line =~ /^\S/;
23 $version_log .= $line;
24 }
25 elsif ($line =~ /^v?\Q$version\E/) {
26 $found_version = 1;
27 }
28}
29close $fh;
30die "couldn't find heading for $version in $changelog!\n"
31 unless $found_version;
32
33$version_log =~ s/\r\n?/\n/g;
34$version_log =~ s/\n+\z//;
35
36s/\n\z//
37 for @$prefix, @$suffix;
38
39print join("\n\n", @$prefix, $version_log, @$suffix) . "\n";