-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprdiff
executable file
·47 lines (40 loc) · 899 Bytes
/
prdiff
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
#!/usr/bin/perl
use strict;
use warnings;
use v5.030;
use OpenBSD::Paths;
use OpenBSD::Pledge;
use OpenBSD::Unveil;
unveil(OpenBSD::Paths->ftp, 'x') || die $!;
pledge(qw( proc exec )) || die $!;
sub usage
{
say STDERR 'usage: prdiff owner/repo#pr';
exit 1;
}
@ARGV == 1 || usage();
sub ftp_get
{
my $url = shift;
my @cmd = (OpenBSD::Paths->ftp, '-VMo-', $url);
open(my $ftp_stdout, '-|', @cmd) or die "open `@cmd` failed: $!";
my $is_diff;
while (my $line = readline $ftp_stdout) {
unless ($is_diff ||= $line =~ m/^diff /) {
close($ftp_stdout);
die "not a pull request";
}
print $line;
}
close($ftp_stdout);
}
sub print_pr
{
my ($repo, $pull_num) = @_;
my $url = 'https://patch-diff.githubusercontent.com' .
"/raw/$repo/pull/$pull_num.diff";
ftp_get($url);
}
my @args = $ARGV[0] =~ m{^([\w-]+/[\w-]+)#(\d+)$}; # owner/repo#pr
@args == 2 || usage();
print_pr(@args);