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

alexm-guest pushed a commit to branch forward-github-pr
in repository pkg-perl-tools.

commit c5a3c2a1b84637e848a8d7cdc2d792f691985e09
Author: Alex Muntada <al...@alexm.org>
Date:   Sat May 28 22:23:26 2016 +0200

    Refactor PR workflow
---
 t/github.t | 103 ++++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 71 insertions(+), 32 deletions(-)

diff --git a/t/github.t b/t/github.t
index f80b780..5a7f7a7 100644
--- a/t/github.t
+++ b/t/github.t
@@ -16,44 +16,83 @@ BEGIN {
         and eval "use Git::Repository; 1";
 }
 
+# Defaults
+my $owner   = 'alexm';
+my $repo    = 'pkg-perl-dummy';
+my $orgname = 'pkg-perl-tools';
+my $branch  = "pkg-perl-$^T";
+my $patch   = 't/dummy.txt.patch';
+my $comment = "Test patch $^T";
+my $body    = 'Pull request by Debian pkg-perl team.';
+my $base    = 'master';
+
+# Test GitHub API access
 my $gh = new_ok('Net::GitHub::V3', [
     access_token => $ENV{DPT_GITHUB_OAUTH},
 ]);
-
-my $orgname = 'pkg-perl-tools';
 is( $gh->user->show($orgname)->{login}, $orgname, $orgname );
 
-my $repos = $gh->repos;
-$repos->set_default_user_repo('alexm', 'pkg-perl-dummy');
-my $fork = $repos->create_fork($orgname);
-isnt( $fork, undef, 'create fork' );
-
-my $workdir = tempdir( CLEANUP => 1 );
-Git::Repository->run(
-    clone => "git\@github.com:$orgname/pkg-perl-dummy.git",
-    $workdir,
-    { quiet => 1 },
-);
-my $r = Git::Repository->new( work_tree => $workdir, { quiet => 1 } );
-$r->run( checkout => '-b', "test-branch-$^T" );
-
-my $patched = system( "cat t/dummy.txt.patch | (cd $workdir && patch -p1)" ) 
== 0;
-ok( $patched, 'patch dummy.txt' );
-
-$r->run( add => '.' );
-$r->run( commit => '-m', "Test patch $^T" );
-$r->run( push => 'origin', "test-branch-$^T" );
-
-my $pull_request = $gh->pull_request;
-$pull_request->set_default_user_repo('alexm', 'pkg-perl-dummy');
-my $pull = $pull_request->create_pull({
-    title => "Test patch $^T",
-    body  => "Testing pull requests from pkg-perl-tools.",
-    head  => "$orgname:test-branch-$^T",
-    base  => "master",
+create_fork($gh, $owner, $repo, $orgname)
+    unless fork_exists($gh, $orgname, $repo);
+
+clone_branch_patch_push($orgname, $repo, $branch, $patch, $comment);
+
+my $url = create_pull_request($gh, $owner, $repo, {
+    title => $comment,
+    body  => $body,
+    head  => "$orgname:$branch",
+    base  => $base,
 });
-isnt( $pull, undef, 'create pull request' );
 
-diag $pull->{html_url};
+isnt( $url, undef, 'pull request' );
+diag $url;
 
 done_testing();
+
+sub fork_exists {
+    my ($gh, $user, $repo) = @_;
+
+    return !!$gh->repos->set_default_user_repo($user, $repo);
+}
+
+sub create_fork {
+    my ($gh, $owner, $repo, $orgname) = @_;
+
+    $gh->repos->set_default_user_repo($owner, $repo);
+    return $gh->repos->create_fork($orgname);
+}
+
+sub clone_branch_patch_push {
+    my ($user, $repo, $branch, $patch, $comment) = @_;
+
+    # Clone
+    my $workdir = tempdir( CLEANUP => 1 );
+    Git::Repository->run(
+        clone => "git\@github.com:$user/$repo.git",
+        $workdir,
+        { quiet => 1 },
+    );
+    my $r = Git::Repository->new(
+        work_tree => $workdir,
+        { quiet => 1 },
+    );
+
+    # Branch
+    $r->run( checkout => '-b', $branch, { quiet => 1 } );
+
+    # Patch
+    my $patched = system("cat $patch|(cd $workdir && patch -p1)") == 0;
+
+    # Push
+    $r->run( add => '.' );
+    $r->run( commit => '-m', $comment, { quiet => 1 } );
+    $r->run( push => 'origin', $branch, { quiet => 1 } );
+}
+
+sub create_pull_request {
+    my ($gh, $user, $repo, $params) = @_;
+
+    $gh->pull_request->set_default_user_repo($user, $repo);
+    my $pull = $gh->pull_request->create_pull($params);
+    return $pull->{html_url} if $pull;
+}

-- 
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