[pkg-perl-tools] 01/04: Move subs to Debian::PkgPerl::GitHub module

Alex Muntada alexm-guest at moszumanska.debian.org
Fri Oct 14 18:08:43 UTC 2016


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 296b0fcd733a5b4c53ee6298caef6027e7e24f72
Author: Alex Muntada <alexm at alexm.org>
Date:   Fri Oct 14 18:52:50 2016 +0200

    Move subs to Debian::PkgPerl::GitHub module
---
 t/github.t => lib/Debian/PkgPerl/GitHub.pm | 55 ++++++----------------------
 t/github.t                                 | 57 +++---------------------------
 2 files changed, 14 insertions(+), 98 deletions(-)

diff --git a/t/github.t b/lib/Debian/PkgPerl/GitHub.pm
similarity index 51%
copy from t/github.t
copy to lib/Debian/PkgPerl/GitHub.pm
index 5a7f7a7..c5c7f4f 100644
--- a/t/github.t
+++ b/lib/Debian/PkgPerl/GitHub.pm
@@ -1,53 +1,18 @@
-#!/usr/bin/perl
+package Debian::PkgPerl::GitHub;
 
 use strict;
 use warnings;
 
-use Test::More;
 use File::Temp qw(tempdir);
-
-BEGIN {
-    plan skip_all
-        => "GitHub tests require DPT_GITHUB_OAUTH token,"
-         . " Net::GitHub and Git::Repository"
-        unless $ENV{DPT_GITHUB_OAUTH}
-        and $ENV{DPT_GITHUB_OAUTH} =~ /^\w+$/
-        and eval "use Net::GitHub; 1"
-        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},
-]);
-is( $gh->user->show($orgname)->{login}, $orgname, $orgname );
-
-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( $url, undef, 'pull request' );
-diag $url;
-
-done_testing();
+use Git::Repository;
+
+use Exporter 'import';
+our @EXPORT = qw(
+    fork_exists
+    create_fork
+    clone_branch_patch_push
+    create_pull_request
+);
 
 sub fork_exists {
     my ($gh, $user, $repo) = @_;
diff --git a/t/github.t b/t/github.t
index 5a7f7a7..8b25820 100644
--- a/t/github.t
+++ b/t/github.t
@@ -4,16 +4,15 @@ use strict;
 use warnings;
 
 use Test::More;
-use File::Temp qw(tempdir);
+use Debian::PkgPerl::GitHub;
 
 BEGIN {
     plan skip_all
-        => "GitHub tests require DPT_GITHUB_OAUTH token,"
-         . " Net::GitHub and Git::Repository"
+        => "GitHub tests require DPT_GITHUB_OAUTH token"
+         . " and Net::GitHub"
         unless $ENV{DPT_GITHUB_OAUTH}
         and $ENV{DPT_GITHUB_OAUTH} =~ /^\w+$/
-        and eval "use Net::GitHub; 1"
-        and eval "use Git::Repository; 1";
+        and eval "use Net::GitHub; 1";
 }
 
 # Defaults
@@ -48,51 +47,3 @@ 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



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