summaryrefslogtreecommitdiff
path: root/rb-patch
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir@cohens.org.il>2009-07-17 17:19:36 +0300
committerTzafrir Cohen <tzafrir@cohens.org.il>2009-07-17 17:19:36 +0300
commitcf522bfcdabfdc6326e3374845462e08742d0f05 (patch)
treea85ab207a751e6cfd536c114adef0ee1e5648b63 /rb-patch
parent8de0acc8ca86e1ceb36dd3424c7cf06e771700af (diff)
rb-patch: fetch a review-board patch
Fetches a review-board patch into a form that git-am likes.
Diffstat (limited to 'rb-patch')
-rwxr-xr-xrb-patch111
1 files changed, 111 insertions, 0 deletions
diff --git a/rb-patch b/rb-patch
new file mode 100755
index 0000000..c2157a6
--- /dev/null
+++ b/rb-patch
@@ -0,0 +1,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
+