summaryrefslogtreecommitdiff
path: root/rb-patch
blob: c2157a65978b3c46a48472a4a45895a7972c44ab (plain)
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
#!/usr/bin/perl -w

use strict;
use LWP::Simple;
use Getopt::Long;
use Pod::Usage;

my %opt = (
);

GetOptions(
        'review-num|review|r=i' => \$opt{review_num},
        'help|?' => \$opt{help},
        man => \$opt{man}
) or pod2usage(2);
pod2usage(1) if ($opt{help});
if (not defined $opt{review_num}) {
	print STDERR "$0: Error: review number (-r) is required\n";
	pod2usage(2);
}
pod2usage(-exitstatus => 0, -verbose => 2) if $opt{man};


my $BASE_URL="https://reviewboard.asterisk.org";



my $review_url = "$BASE_URL/r/$opt{review_num}";
my $diff_page_url = "$review_url/diff";
my $diff_url = "$diff_page_url/raw";

my $content = get($diff_page_url);
die "$0: Failed to get reviewboard page $diff_page_url\n" unless defined $content;

# Simple lines-based parsing will do hor now
my @page = split(/\n/, $content);
$content =~ m{<h1 id="summary" class="editable">([^<]*)</h1>};
my $summary = $1;
$content =~ m{<a id="submitter" href="([^"]*)">([^<]*)</a>};
my ($url, $name) = ($1, $2);
$url = "$BASE_URL$url";
$content =~ m{<h1>Diff revision (\d+) \(Latest\)</h1>};
my $diff_count = $1;

my $raw_diff = get($diff_url);
die "$0: Failed to get raw diff $diff_url\n" unless defined $raw_diff;

# Fix patch-level from -p0 to -p1
# Alternatively you could use git-am -p0
$raw_diff =~ s{\n--- }   {$&a/}g;
$raw_diff =~ s{\n\+\+\+ }{$&b/}g;

print 
"From <Fill in cookie> <fill in date>
From: $name <$url>
Date: <fill in date>
Subject: [PATCH] $summary

<fill in further description>

$raw_diff

-- 
$0
"

__END__

=head1 NAME
rb-patch

=head1 SYNOPSIS

rb-patch -r I<NUM>

Options:
  -r --review  number of reivewboard review to fetch. Required.  
  --help       brief help message
  --man        full documentation

=head1 OPTIONS

=over

=item B<--review> I<num>

Fetch ReviewBoard review number I<num>. This parameter is required.

=item B<--help>

Print a brief help message and exits.

=item B<--man>

Prints the manual page and exits.

=back

=head1 DESCRIPTION

This script is intended, in the long run, to convert a review-board review
to a mailbox that could be merged into a git repository through git-am(1).

At the moment, however, it only fetches latest review. Use:

  git checkout -b test-branch
  ../asterisk-tools/rb-patch -r I<num> >patch
  git am patch

=cut