Commit 82c8f3d4 authored by Alex Muntada's avatar Alex Muntada

Remove scripts/forward-patch

parent ba0a8992
......@@ -15,8 +15,6 @@ TODOS:
should not go into in the package.
- lintian check: ensure that arch-dep packages use M-A:same
- lintian check: check for unversioned 'perl' in Depends
- forward: adopt the mail bug reporting interface from forward-patch/-bug
and then drop -patch/-bug
- forward: when forwarding patches to github, pull request would be nicer
than an issue with a link to the patch
- forward: read from d/u/metadata as well
......
......@@ -111,10 +111,6 @@ See L<dpt-debian-upstream(1)>.
See L<dpt-forward(1)>.
=item B<forward-patch> - forward a patch to CPAN's request tracker
See L<dpt-forward-patch(1)>.
=item B<gc> - swipe pkg-perl working directories
See L<dpt-gc(1)>.
......
......@@ -14,6 +14,7 @@ use Term::ReadLine;
use Time::Piece qw(localtime);
use Text::Wrap qw(wrap);
use Proc::InvokeEditor;
use MIME::Lite;
use warnings;
use strict;
......@@ -93,6 +94,16 @@ resources->bugtracker->web >> field of F<META>. Defaults to C<<
https://rt.cpan.org/Public/Dist/Display.html?Name=I<dist-name> >> for B<cpan> and
is mandatory for B<github>.
=item B<--use-mail>
Send bug and patch submissions by e-mail instead.
=item B<--mailto> I<address>
This option sets the e-mail address to forward to. The default
is determined from the C<< resources->bugtracker->mailto >>
field of F<META> or CPAN RT bug address if that field is not present.
=back
=cut
......@@ -107,6 +118,8 @@ my $opt_mode;
my $opt_offline_test;
my $opt_meta_file;
my $opt_ticket;
my $opt_use_mail;
my $opt_mailto;
GetOptions(
'd|dist=s' => \$opt_dist,
......@@ -117,6 +130,8 @@ GetOptions(
'offline-test!' => \$opt_offline_test,
'meta=s' => \$opt_meta_file,
'ticket=s' => \$opt_ticket,
'use-mail!' => \$opt_use_mail,
'mailto=s' => \$opt_mailto,
) or exit 1;
die
......@@ -138,13 +153,13 @@ die "Unable to determine distribution name.\n"
. "Please use the --dist option.\n"
unless $opt_dist;
$opt_tracker_url ||= $meta->resources->{bugtracker}{web}
if $meta
and $meta->resources
and $meta->resources->{bugtracker};
if ( $meta and $meta->resources and $meta->resources->{bugtracker} ) {
$opt_tracker_url ||= $meta->resources->{bugtracker}{web};
$opt_mailto ||= $meta->resources->{bugtracker}{mailto};
}
unless ($opt_tracker_url) {
warn "Bug tracker not found in META.\n";
warn "Bug tracker web not found in META.\n";
$opt_tracker_url
= "https://rt.cpan.org/Public/Dist/Display.html?Name=$opt_dist";
......@@ -152,6 +167,14 @@ unless ($opt_tracker_url) {
warn "Falling back to $opt_tracker_url\n";
}
unless ($opt_mailto) {
warn "Bug tracker mail not found in META.\n";
$opt_mailto = 'bug-' . lc($opt_dist) . '@rt.cpan.org';
warn "Falling back to $opt_mailto\n";
}
$opt_tracker ||= detect_tracker();
$opt_mode ||= 'patch'
......@@ -210,10 +233,12 @@ if ($patch) {
}
unless ( $patch_info{Subject} ) {
# TODO: Use basename($patch) instead?
# default subject is the patch name
my $fn = ( File::Spec->splitpath($patch) )[-1];
$fn =~ s/\.(?:patch|diff)$//; # strip extension
$fn =~ s/^\d+[-_]?//; # strip leading number
$fn =~ s/(\_|\-)/ /g; # spaces make reading easier
$patch_info{Subject} = $fn;
}
}
......@@ -273,7 +298,7 @@ sub get_subject {
my $term = Term::ReadLine->new('forward');
return $term->readline( 'Subject:', $default );
return $term->readline( 'Subject: ', $default );
}
sub detect_dist {
......@@ -419,6 +444,49 @@ sub prepare_body {
return edit_message($body);
}
sub send_by_mail {
my $from = "$name <$email>";
my $text = prepare_body();
my $subject = get_subject();
my $msg = MIME::Lite->new(
From => $from,
To => $opt_mailto,
Subject => $subject,
Type => 'multipart/mixed'
) or die "Error creating multipart container: $!\n";
$msg->attach(
Type => 'TEXT',
Data => $text
) or die "Error adding the text message part: $!\n";
# add the patch as attachment
$msg->attach(
Type => 'TEXT',
Path => $patch,
Filename => basename($patch),
Disposition => 'attachment'
) or die "Error adding attachment: $!\n";
# the email is not currently sent
MIME::Lite->send( 'sendmail', '/usr/sbin/sendmail -t' )
; # change mailer to your needs
$msg->send;
if (!$opt_mailto) {
# TODO
# find bug on https://rt.cpan.org/Public/Dist/Display.html?Name=$opt_dist
# or via RT::Client::REST and add the URL to the Forwarded header in the patch
print "Find your ticket on\n"
. "$opt_tracker_url\n"
. "and add the ticket URL to $patch\n\n"
. "Trying to open the URL with sensible-browser now.\n";
system( 'sensible-browser', $opt_tracker_url );
}
}
sub submit_cpan_rt {
# prepare subject
my $subject = get_subject();
......@@ -660,7 +728,10 @@ sub detect_tracker {
die "Unable to determine bug tracker from URL '$opt_tracker_url'.\n";
}
if ( $opt_tracker eq 'cpan' ) {
if ($opt_use_mail) {
send_by_mail();
}
elsif ( $opt_tracker eq 'cpan' ) {
submit_cpan_rt();
}
elsif ( $opt_tracker eq 'github' ) {
......@@ -676,14 +747,22 @@ else {
=item Alessandro Ghedini <ghedo@debian.org>.
=item Alex Muntada <alexm@alexm.org>.
=item Damyan Ivanov <dmn@debian.org>.
=item Salvatore Bonaccorso <carnil@debian.org>.
=back
=head1 LICENSE AND COPYRIGHT
=over
=item Copyright 2016 Alex Muntada.
=item Copyright 2014 Salvatore Bonaccorso.
=item Copyright 2014 Damyan Ivanov.
=item Copyright 2011 Alessandro Ghedini.
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment