forked from pgjdbc/pgjdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release_notes_filter.pl
executable file
·117 lines (101 loc) · 2.78 KB
/
release_notes_filter.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env perl
use strict;
use utf8;
use open qw(:std :utf8);
use WWW::Curl::Easy;
use JSON;
use JSON::Parse 'json_file_to_perl';
use Unicode::Collate;
my $version = shift;
my $contributors = json_file_to_perl('contributors.json');
my $con_count = keys %$contributors;
sub save_contributors {
if ($con_count == keys %$contributors) {
return;
}
my $fh;
open $fh, ">", "contributors.json";
print $fh JSON->new->pretty->canonical->encode($contributors);
close $fh;
}
my %author_url;
my $fetch = sub {
my $curl = WWW::Curl::Easy->new();
my ( $header, $body );
$curl->setopt( CURLOPT_URL, shift );
$curl->setopt( CURLOPT_WRITEHEADER, \$header );
$curl->setopt( CURLOPT_WRITEDATA, \$body );
$curl->setopt( CURLOPT_FOLLOWLOCATION, 1 );
$curl->setopt( CURLOPT_TIMEOUT, 10 );
$curl->setopt( CURLOPT_SSL_VERIFYPEER, 1 );
$curl->setopt( CURLOPT_USERAGENT, "Awesome-Pgjdbc-App");
$curl->perform;
{
header => $header,
body => $body,
info => $curl->getinfo(CURLINFO_HTTP_CODE),
error => $curl->errbuf,
};
};
sub authorUrl {
my $sha = (shift);
my $res = $fetch->("https://api.github.com/repos/pgjdbc/pgjdbc/commits/$sha");
if ($res->{info} != 200) {
return
}
my $json = decode_json($res->{body});
my $author = $json->{author};
my $url = $author->{html_url};
if ($url) {
return $url;
}
return $json->{commit}->{author}->{email};
}
my %authors;
my $currentAuthor;
while(<>) {
if ($_ !~ /@@@/) {
print $_;
if ($_ =~ /(.*) \(\d+\):/) {
$currentAuthor = $1;
$authors{$currentAuthor} = 1;
print "\n";
}
next;
}
my @c = split('@@@', $_);
my $subject = @c[0];
my $sha = @c[1];
my $shortSha = @c[2];
if (!$contributors->{$currentAuthor}) {
$contributors->{$currentAuthor} = authorUrl($sha);
}
my $pr = '';
# PR id can be either "... (#42)" or just "... #42"
if ($subject =~ /\(?#(\d+)\)?/) {
$subject =~ s;\(?#(\d+)\)?;[PR \1](https://github.com/pgjdbc/pgjdbc/pull/\1);;
} else {
my $body = `git log --format='%B' -n 1 $sha`;
if ($body =~ /(?:fix|fixes|close|closes) *#?(\d+)/) {
$pr = $1;
}
}
if ($pr != '') {
$pr = ' [PR '.$pr.'](https://github.com/pgjdbc/pgjdbc/pull/'.$pr.')';
}
$subject =~ s/^\s+/* /;
print $subject.$pr." [".$shortSha."](https://github.com/pgjdbc/pgjdbc/commit/$sha)\n";
}
print "<a name=\"contributors_{{ page.version }}\"></a>\n";
print "### Contributors to this release\n\n";
print "We thank the following people for their contributions to this release.\n\n";
for my $c (Unicode::Collate->new(level => 2)->sort(keys(%authors))) {
my $url = $contributors->{$c};
if ($url) {
print "[$c]($url)";
} else {
print $c;
}
print " \n"
}
save_contributors();