Skip to content

Instantly share code, notes, and snippets.

@clintongormley
Created February 8, 2011 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clintongormley/816663 to your computer and use it in GitHub Desktop.
Save clintongormley/816663 to your computer and use it in GitHub Desktop.
es_release_notes.pl
#!/usr/local/bin/perl
use strict;
use warnings;
my $Base_URL = 'http://github.com/api/v2/json/issues/';
my $User_Repo = 'elasticsearch/elasticsearch/';
my $Issue_URL = "http://github.com/${User_Repo}issues/issue/";
my @Groups = qw(breaking feature enhancement bug);
my %Group_Labels = (
breaking => 'Breaking changes',
feature => 'New features',
enhancement => 'Enhancements',
bug => 'Bug fixes',
other => 'Not classified',
);
use JSON::XS();
my $json = JSON::XS->new->utf8(1);
my %All_Labels = fetch_labels();
my $version = shift @ARGV
or dump_labels();
dump_labels("Unknown version '$version'")
unless $All_Labels{$version};
my $issues = fetch_issues($version);
dump_issues( $version, $issues );
#===================================
sub dump_issues {
#===================================
my $version = shift;
my $issues = shift;
$version =~ s/v//;
my ( $day, $month, $year ) = (gmtime)[ 3 .. 5 ];
$month++;
$year += 1900;
print "h1. Release notes: \@elasticsearch-$version\@\n\n";
print
"p. *PLEASE NOTE - These release notes still need to be reviewed.*\n\n";
printf "p. Changes made to \@HEAD\@ since the release of the previous "
. "version, updated on *%4d-%02d-%02d*\n\n", $year, $month, $day;
for my $group (@Groups) {
my $group_issues = $issues->{$group} or next;
print "h2. $Group_Labels{$group}:\n";
for my $header ( sort keys %$group_issues ) {
my $prefix = " * ";
my $header_issues = $group_issues->{$header};
if ( $header && @$header_issues > 1 ) {
print " * $header:\n";
$prefix = " ** ";
}
elsif ($header) {
$prefix = " * $header: ";
}
for my $issue (@$header_issues) {
my $title = $issue->{title};
$title =~ s/`/@/g;
my $number = $issue->{number};
print $prefix. $title
. qq[ ("#$number":${Issue_URL}${number})\n];
}
}
print "\n\n";
}
}
#===================================
sub fetch_issues {
#===================================
my $version = shift;
my @issues;
my $page = 1;
while (1) {
my $tranche
= fetch(
'list/' . $User_Repo . 'label/' . $version . '?page=' . $page )
->{issues}
or die "Couldn't fetch issues for version '$version'";
last unless @$tranche;
push @issues, @$tranche;
$page++;
}
my %group;
ISSUE:
for my $issue (@issues) {
my %labels = map { $_ => 1 } @{ $issue->{labels} };
my $header = $issue->{title} =~ s/^([^:]+):\s+// ? $1 : '';
for (@Groups) {
if ( $labels{$_} ) {
push @{ $group{$_}{$header} }, $issue;
next ISSUE;
}
}
push @{ $group{other}{$header} }, $issue;
}
return \%group;
}
#===================================
sub fetch_labels {
#===================================
my $labels = fetch( 'labels/' . $User_Repo )->{labels}
or die "Couldn't retrieve version labels";
return map { $_ => 1 } grep {/^v/} @$labels;
}
#===================================
sub fetch {
#===================================
my $url = $Base_URL . shift();
my $content = `curl -s '$url'`
or die "Couldn't use curl to fetch '$url'";
my $result = $json->decode($content);
die "ERROR: '" . $result->{error} . "' while fetching '$url'"
if $result->{error};
return $result;
}
#===================================
sub dump_labels {
#===================================
my $error = shift || '';
if ($error) {
$error = "\nERROR: $error\n";
}
my $labels = join( "\n - ", '', ( sort keys %All_Labels ) );
die <<USAGE
$error
USAGE: $0 version > outfile
Known versions:$labels
USAGE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment