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

alexm-guest pushed a commit to branch master
in repository pkg-perl-tools.

commit 21df757acd7486199f7ec728b5f8e967a296a673
Author: Alex Muntada <al...@alexm.org>
Date:   Mon Nov 28 04:19:04 2016 +0100

    Move forward logic to Debian::PkgPerl::GitHub
---
 lib/Debian/PkgPerl/GitHub.pm | 129 +++++++++++++++++++++++++++++++++++++++++++
 scripts/forward              |  53 +++++++-----------
 2 files changed, 150 insertions(+), 32 deletions(-)

diff --git a/lib/Debian/PkgPerl/GitHub.pm b/lib/Debian/PkgPerl/GitHub.pm
index a93a08d..a46125d 100644
--- a/lib/Debian/PkgPerl/GitHub.pm
+++ b/lib/Debian/PkgPerl/GitHub.pm
@@ -46,6 +46,8 @@ our @EXPORT_OK = qw(
     create_fork
     clone_branch_patch_push
     create_pull_request
+    forward_patch_as_pull_request
+    forward_bug_as_issue
 );
 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
 
@@ -233,6 +235,133 @@ sub create_pull_request {
     return $pull && $pull->{html_url};
 }
 
+=head2 forward_patch_as_pull_request($gh, $user, $repo, $orgname, $branch, 
$patch, $title, $comment, $labels)
+
+=head3 Parameters:
+
+=over
+
+=item * $gh
+
+Net::GitHub object that must be already authenticated.
+
+=item * $user
+
+User forwarding the patch.
+
+=item * $repo
+
+Repository receiving the patch.
+
+=item * $orgname
+
+Organization that owns the forked repository.
+
+=item * $branch
+
+Name of the branch being created.
+
+=item * $patch
+
+Full pathname to the file containing the patch.
+
+=item * $title
+
+Title of the bug report.
+
+=item * $comment
+
+Message used in the bug report.
+
+=item * $labels
+
+Labels to be set in the bug report.
+
+=back
+
+=cut
+
+sub forward_patch_as_pull_request {
+    my ($gh, $user, $repo, $orgname, $branch, $patch, $title, $comment, 
$labels) = @_;
+
+    die "Cannot find your GitHub user in $orgname organization"
+        unless $gh->user->show($orgname)->{login} eq $orgname;
+
+    create_fork($gh, $user, $repo, $orgname)
+        unless fork_exists($gh, $orgname, $repo);
+
+    clone_branch_patch_push($user, $repo, $orgname, $branch, $patch, $title);
+
+    $issue_url = create_pull_request($gh, $user, $repo, {
+        title  => $title,
+        body   => $comment,
+        head   => "$orgname:$branch",
+        base   => 'master',
+        labels => [ split( /,/, $labels ) ],
+    });
+
+    return $issue_url;
+}
+
+=head2 forward_bug_as_issue($gh, $user, $repo, $ticket, $title, $comment, 
$labels)
+
+=head3 Parameters:
+
+=over
+
+=item * $gh
+
+Net::GitHub object that must be already authenticated.
+
+=item * $user
+
+User forwarding the bug.
+
+=item * $repo
+
+Repository receiving the bug report.
+
+=item * $ticket
+
+Use an existing ticket number to make the report.
+
+=item * $title
+
+Title of the bug report.
+
+=item * $comment
+
+Message used in the bug report.
+
+=item * $labels
+
+Labels to be set in the bug report.
+
+=back
+
+=cut
+
+sub forward_bug_as_issue {
+    my ($gh, $user, $repo, $ticket, $title, $comment, $labels) = @_;
+
+    $gh->set_default_user_repo( $user, $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 => [ split( /,/, $labels ) ],
+        });
+    }
+
+    return $issue->{html_url};
+}
+
 =head1 LICENSE AND COPYRIGHT
 
 =over
diff --git a/scripts/forward b/scripts/forward
index 3e9fde6..7b03bf8 100755
--- a/scripts/forward
+++ b/scripts/forward
@@ -611,41 +611,30 @@ sub submit_github {
 
     if ($patch) {
         my $orgname = 'pkg-perl-tools';
-        die "Cannot find your GitHub user in $orgname organization"
-            unless $gh->user->show($orgname)->{login} eq $orgname;
-
-        create_fork($gh, $gh_user, $gh_repo, $orgname)
-            unless fork_exists($gh, $orgname, $gh_repo);
-
         my $branch = "pkg-perl-$^T";
-        clone_branch_patch_push($gh_user, $gh_repo, $orgname, $branch, $patch, 
$subject);
-
-        $issue_url = create_pull_request($gh, $gh_user, $gh_repo, {
-            title  => $subject,
-            body   => $body,
-            head   => "$orgname:$branch",
-            base   => 'master',
-            labels => [ split( /,/, $gh_labels ) ],
-        });
+
+        $issue_url = forward_patch_as_pull_request(
+            $gh,
+            $gh_user,
+            $gh_repo,
+            $orgname,
+            $branch,
+            $patch,
+            $subject,
+            $body,
+            $gh_labels,
+        );
     }
     else {
-        $gh->set_default_user_repo( $gh_user, $gh_repo );
-
-        my $issue;
-        if ($opt_ticket) {
-            $issue = $gh->issue->issue($opt_ticket);
-            $gh->issue->create_comment( $opt_ticket, { body => $body } );
-        }
-        else {
-            $issue = $gh->issue->create_issue(
-                {   title  => $subject,
-                    body   => $body,
-                    labels => [ split( /,/, $gh_labels ) ],
-                }
-            );
-        }
-
-        $issue_url = $issue->{html_url};
+        $issue_url = forward_bug_as_issue(
+            $gh,
+            $gh_user,
+            $gh_repo,
+            $opt_ticket,
+            $subject,
+            $body,
+            $gh_labels,
+        );
     }
 
 ISSUE_CREATED:

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

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to