~sungo/conch-api

conch-api/misc/ghch -rwxr-xr-x 2.6 KiB
49826ec5 — Karen Etheridge Merge pull request #885 from joyent/ether/v3-collapse-validation_result-more 1 year, 6 months ago
                                                                                
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
#!/usr/bin/env perl

use warnings;
use strict;
use v5.20;

use Mojo::JSON 'decode_json';
use HTTP::Tiny;

sub get {
    my $short = shift;
    my $url = "https://api.github.com$short";
    if (my $token = $ENV{TOKEN} // $ENV{GITHUB_OAUTH_TOKEN}) {
        $url .= "?access_token=$token";
    }
    my $res = HTTP::Tiny->new->get($url);
    if ($res->{success}) {
        return decode_json($res->{content});
    }
    else {
        die $url.' - '.$res->{status}.' '.$res->{reason}."\n".$res->{content};
    }
}

chomp(my $end = $ARGV[1] // 'HEAD');
chomp $end;

chomp(my $start = $ARGV[0] // `git tag --merged $end --sort version:refname | tail -n 1`);

print "# using start: $start\n";
print "# using end: $end\n";

my @lines = (`git --no-pager log --oneline --merges --no-decorate $start...$end`);

my $lines_used = 0;
foreach my $line (reverse @lines) {
    $line =~ /^(.+?) Merge pull request #(\d+) / or next;
    ++$lines_used;

    my $hash = $1;
    my $pr = $2;

    my $pull_data = get "/repos/joyent/conch/pulls/$pr";

    my $labels = join(", ", map $_->{name}, $pull_data->{labels}->@*);

    say <<EOF;
[PR #$pr]($pull_data->{html_url}) - `$pull_data->{title}`
===
* Branch: $pull_data->{head}->{ref}
* Revision: $hash
* Labels: $labels
EOF

    my $body = join('', map "> $_\n", split "\n", ($pull_data->{body} // ''));
    say $body if $body;

    my $review_data = get "/repos/joyent/conch/pulls/$pr/reviews";
    my $reviews = join("\n", map "* Reviewed By: [$_->{user}{login} - $_->{state}]($_->{html_url})", $review_data->@*);

    say <<EOF;
People
---
* Author: [$pull_data->{user}{login}]($pull_data->{user}{html_url})
$reviews
* Merged By: [$pull_data->{merged_by}{login}]($pull_data->{merged_by}{html_url})
* Merged: $pull_data->{merged_at}
EOF

    say "Commits\n---\n";

    my $commit_data = get "/repos/joyent/conch/pulls/$pr/commits";
    for my $commit ($commit_data->@*) {
        my $h = substr($commit->{sha},0,6);
        my @bits = split("\n", $commit->{commit}->{message});

        say "* [$h]($commit->{html_url}) - \`$bits[0]\`";
    }
    say "\n- - -\n";
}

# if this is a release that doesn't contain pull requests but rather cherry-picks, we need to
# do something different...
exit if $lines_used;

@lines = (`git --no-pager log --oneline --no-decorate $start...$end`);
say "Commits\n---\n";
foreach my $line (reverse @lines) {
    my ($hash, $rest) = split(/ /, $line, 2);

    my $commit = get "/repos/joyent/conch/commits/$hash";

    my $h = substr($commit->{sha},0,6);
    my @bits = split("\n", $commit->{commit}->{message});

    say "* [$h]($commit->{html_url}) - \`$bits[0]\`";
}
say "\n- - -\n";