[pkg-perl-tools] 05/05: Add fallback for GitHub pull-requests

Alex Muntada alexm-guest at moszumanska.debian.org
Sat Dec 3 03:58:35 UTC 2016


This is an automated email from the git hooks/post-receive script.

alexm-guest pushed a commit to branch fallback-for-github-pull-requests
in repository pkg-perl-tools.

commit 410cf68909f7bfff28cae5dfdcabb36c853d2e1c
Author: Alex Muntada <alexm at alexm.org>
Date:   Sat Dec 3 04:57:17 2016 +0100

    Add fallback for GitHub pull-requests
---
 lib/Debian/PkgPerl/GitHub.pm | 49 +++++++++++++++++++++++++++++++++++++++++++-
 scripts/forward              |  8 ++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/lib/Debian/PkgPerl/GitHub.pm b/lib/Debian/PkgPerl/GitHub.pm
index c4d41bd..74375f5 100644
--- a/lib/Debian/PkgPerl/GitHub.pm
+++ b/lib/Debian/PkgPerl/GitHub.pm
@@ -45,6 +45,7 @@ Debian::PkgPerl::GitHub - Help forwarding a bug or a patch to GitHub
     );
     print Debian::PkgPerl::GitHub->new(
         message  => $patch_msg,
+        fallback => 0,
     )->forward();
 
 =head1 DESCRIPTION
@@ -72,6 +73,11 @@ use Cwd 'realpath';
 
 Message to be forwarded to an upstream project.
 
+=item * fallback
+
+Enables fallback to forwarding a patch as an issue if pull-request
+fails for any reason. Default is false.
+
 =back
 
 =head3 Environment:
@@ -278,6 +284,46 @@ sub forward_patch_as_pull_request {
     return $issue_url;
 }
 
+=head2 forward_patch_as_ticket()
+
+Fallback to forwarding a patch as a bug.
+
+=head3 Returns:
+
+Issue URL on success, nothing otherwise.
+
+=cut
+
+sub forward_patch_as_ticket {
+    my $self = shift;
+
+    # Do nothing unless fallback is enabled.
+    return unless $self->{fallback};
+
+    my $gh      = $self->{github};
+    my $owner   = $self->{owner};
+    my $repo    = $self->{repo};
+    my $ticket  = $self->{ticket};
+    my $title   = $self->{message}->get_subject();
+    my $comment = $self->{message}->prepare_body();
+
+    $gh->set_default_user_repo( $owner, $repo );
+    my $issue;
+    if ($ticket) {
+        $issue = $gh->issue->issue($ticket);
+        $gh->issue->create_comment( $ticket, { body => $comment } );
+    }
+    else {
+        $issue = $gh->issue->create_issue({
+            title  => $title,
+            body   => $comment,
+            labels => $self->{labels},
+        });
+    }
+
+    return $issue && $issue->{html_url};
+}
+
 =head2 forward_bug_as_issue()
 
 =cut
@@ -320,7 +366,8 @@ sub forward {
     my $self = shift;
 
     my $issue_url = $self->{message}->get_patch()
-        ? $self->forward_patch_as_pull_request()
+        ? eval { $self->forward_patch_as_pull_request() }
+              || $self->forward_patch_as_ticket()
         : $self->forward_bug_as_issue()
         ;
 
diff --git a/scripts/forward b/scripts/forward
index 711da35..8d9af8e 100755
--- a/scripts/forward
+++ b/scripts/forward
@@ -106,6 +106,11 @@ 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.
 
+=item B<--fallback>
+
+Enable fallback to forwarding patches as bug reports when pull requests
+fail for any reason. Defaults to false.
+
 =back
 
 =cut
@@ -122,6 +127,7 @@ my $opt_meta_file;
 my $opt_ticket;
 my $opt_use_mail;
 my $opt_mailto;
+my $opt_fallback;
 
 GetOptions(
     'd|dist=s'        => \$opt_dist,
@@ -134,6 +140,7 @@ GetOptions(
     'ticket=s'        => \$opt_ticket,
     'use-mail!'       => \$opt_use_mail,
     'mailto=s'        => \$opt_mailto,
+    'fallback!'       => \$opt_fallback,
 ) or exit 1;
 
 die
@@ -381,6 +388,7 @@ sub submit_github {
     my $gh = Debian::PkgPerl::GitHub->new(
         ticket   => $opt_ticket,
         message  => $message,
+        fallback => $opt_fallback,
     );
 
     my $issue_url = $opt_offline_test ? $gh->test() : $gh->forward();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/pkg-perl-tools.git



More information about the Pkg-perl-cvs-commits mailing list