From cf522bfcdabfdc6326e3374845462e08742d0f05 Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Fri, 17 Jul 2009 17:19:36 +0300 Subject: rb-patch: fetch a review-board patch Fetches a review-board patch into a form that git-am likes. --- rb-patch | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100755 rb-patch (limited to 'rb-patch') 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{

([^<]*)

}; +my $summary = $1; +$content =~ m{([^<]*)}; +my ($url, $name) = ($1, $2); +$url = "$BASE_URL$url"; +$content =~ m{

Diff revision (\d+) \(Latest\)

}; +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 +From: $name <$url> +Date: +Subject: [PATCH] $summary + + + +$raw_diff + +-- +$0 +" + +__END__ + +=head1 NAME +rb-patch + +=head1 SYNOPSIS + +rb-patch -r I + +Options: + -r --review number of reivewboard review to fetch. Required. + --help brief help message + --man full documentation + +=head1 OPTIONS + +=over + +=item B<--review> I + +Fetch ReviewBoard review number I. 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 >patch + git am patch + +=cut + -- cgit v1.2.3