summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Frécinaux <code@istique.net>2007-01-07 21:10:08 (GMT)
committerSteve Frécinaux <code@istique.net>2007-01-07 21:10:08 (GMT)
commitc933e00091ae533064dcded488ab1e03b0afd419 (patch)
tree2198de69790dea0884739a04ad71ec5a03fe33b2
downloadgit-bugzilla-c933e00091ae533064dcded488ab1e03b0afd419.tar.gz
git-bugzilla-c933e00091ae533064dcded488ab1e03b0afd419.tar.xz
git-send-bugzilla: attach patches to a GNOME bugzilla bug.
Initial commit.
-rwxr-xr-xgit-send-bugzilla.pl105
1 files changed, 105 insertions, 0 deletions
diff --git a/git-send-bugzilla.pl b/git-send-bugzilla.pl
new file mode 100755
index 0000000..0993f35
--- /dev/null
+++ b/git-send-bugzilla.pl
@@ -0,0 +1,105 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use WWW::Mechanize;
+use Getopt::Long;
+
+my $bugid = 0;
+my $username = '';
+my $password = '';
+my $since = "";
+my $until = "";
+my $numbered = 0;
+my $start_number = 1;
+
+# Parse options
+GetOptions("bug|b=i" => \$bugid,
+ "username|u=s" => \$username,
+ "password|p=s" => \$password,
+ "numbered|n" => \$numbered,
+ "start-number" => \$start_number);
+
+my @revs;
+open REVPARSE, '-|', 'git-rev-parse', @ARGV;
+chop (@revs = sort <REVPARSE>);
+close REVPARSE;
+if (@revs eq 1) {
+ $since = $revs[0];
+ $until = 'HEAD';
+} else {
+ $since = substr $revs[1], 1;
+ $until = $revs[0];
+}
+
+unless ($bugid > 0 and $username and $password) {
+ print "bad usage";
+ exit;
+}
+
+# Get revision list
+print "Getting revision list between $since\n";
+print " and $until...\n";
+my @revisions;
+open REVLIST, '-|', "git-rev-list ^$since $until" or die "Cannot call git-rev-list: $!";
+chop (@revisions = reverse <REVLIST>);
+close REVLIST;
+
+die "No patch to send\n" if @revisions eq 0;
+
+# Authenticate
+my $mech = WWW::Mechanize->new(agent => "git-send-bugzilla/0.0");
+print "Logging in as $username...\n";
+$mech->get("http://bugzilla.gnome.org/index.cgi?GoAheadAndLogIn=1");
+die "Can't fetch login form: ", $mech->res->status_line unless $mech->success;
+
+$mech->set_fields(Bugzilla_login => $username,
+ Bugzilla_password => $password);
+$mech->submit;
+die "Login submission failed: ", $mech->res->status_line unless $mech->success;
+
+print "Attaching patches...\n";
+my $i = $start_number;
+my $n = @revisions - 1 + $i;
+for $until (@revisions) {
+ my $description = $numbered ? "[$i/$n]" : '[PATCH]';
+ my $comment = '';
+
+ open COMMIT, '-|', "git-cat-file commit $until";
+ # skip headers
+ while (<COMMIT>) {
+ chop;
+ last if $_ eq "";
+ }
+ chop ($description .= ' ' . <COMMIT>);
+ chop ($comment = join "", grep {1} <COMMIT>) unless eof COMMIT;
+ close COMMIT;
+
+ $comment .= "\n---\n" unless $comment eq '';
+ $comment .= `git-diff-tree --stat ^$since $until`;
+ my $patch = `git-diff-tree -p ^$since $until`;
+
+ print " - $description\n";
+
+ # Attach a patch to the bug
+ $mech->get("http://bugzilla.gnome.org/attachment.cgi?bugid=$bugid&action=enter");
+ die "Can't get attachment form: ", $mech->res->status_line unless $mech->success;
+
+ my $form = $mech->form_name('entryform');
+
+ $form->value('description', $description);
+ $form->value('ispatch', 1);
+ $form->value('comment', $comment);
+
+ my $file = $form->find_input('data', 'file');
+ $file->filename("patch-$i.patch");
+ $file->content($patch);
+
+ $mech->submit;
+ die "Attachment failed: ", $mech->res->status_line unless $mech->success;
+ #print $mech->title, "\n";
+
+ $since = $until;
+ $i++;
+}
+print "Done.\n"