[pkg-perl-tools] 04/05: Update Debian::PkgPerl::GitHub
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 230242f360da27f81c018553757495dcdd48a2dd
Author: Alex Muntada <alexm at alexm.org>
Date: Sat Dec 3 04:54:41 2016 +0100
Update Debian::PkgPerl::GitHub
- Add support for Debian::PkgPerl::Message
- Remove bug method.
- Remove patch method.
---
lib/Debian/PkgPerl/GitHub.pm | 200 ++++++++++++-------------------------------
scripts/forward | 26 ++----
t/github.t | 36 +++++---
3 files changed, 82 insertions(+), 180 deletions(-)
diff --git a/lib/Debian/PkgPerl/GitHub.pm b/lib/Debian/PkgPerl/GitHub.pm
index 34c52d1..c4d41bd 100644
--- a/lib/Debian/PkgPerl/GitHub.pm
+++ b/lib/Debian/PkgPerl/GitHub.pm
@@ -10,18 +10,42 @@ Debian::PkgPerl::GitHub - Help forwarding a bug or a patch to GitHub
=head1 SYNOPSIS
+ use Debian::PkgPerl::Bug;
+ use Debian::PkgPerl::Patch;
+ use Debian::PkgPerl::Message;
use Debian::PkgPerl::GitHub;
- my $url = 'https://github.com/foo/bar/issues';
- my $gh = Debian::PkgPerl::GitHub->new(tracker => $url);
-
my %params = (
- subject => $summary,
- body => $comment,
+ url => 'https://github.com/foo/bar/issues',
+ tracker => 'github',
+ dist => 'Foo-Bar',
+ name => 'My Name',
+ email => 'my.name at example.com',
+ mailto => 'your.name at example.com',
+ );
+
+ my %bug_info = Debian::PkgPerl::Bug
+ ->new( bug => 123 )
+ ->retrieve_bug_info();
+ my $bug_msg = Debian::PkgPerl::Message->new(
+ %params,
+ info => \%bug_info,
);
+ print Debian::PkgPerl::GitHub->new(
+ message => $bug_msg,
+ ticket => 456,
+ )->forward();
- my $pull = $gh->patch($file)->forward(%params);
- my $issue = $gh->bug($ticket)->forward(%params);
+ my %patch_info = Debian::PkgPerl::Patch
+ ->new( patch => 'foo-bar.patch' )
+ ->retrieve_patch_info();
+ my $patch_msg = Debian::PkgPerl::Message->new(
+ %params,
+ info => \%patch_info,
+ );
+ print Debian::PkgPerl::GitHub->new(
+ message => $patch_msg,
+ )->forward();
=head1 DESCRIPTION
@@ -44,9 +68,9 @@ use Cwd 'realpath';
=over
-=item * tracker
+=item * message
-Issue tracker URL for an upstream project.
+Message to be forwarded to an upstream project.
=back
@@ -83,17 +107,17 @@ sub new {
unless $ENV{DPT_GITHUB_OAUTH};
die "Unable to determine github issue tracker URL.\n"
- unless $params{tracker};
+ unless $params{message} and $params{message}->get_url();
my ( $owner, $repo, $opts )
- = $params{tracker}
+ = $params{message}->get_url()
=~ m{^https?://github.com/([^/]+)/([^/]+)/issues(?:/?|\?(.*))$};
my @labels;
@labels = split /,/, $1 if $opts and $opts =~ m{labels=([^;&]+)};
die "Unable to determine github user and repository\n"
- . "from $params{tracker}"
+ . "from " . $params{message}->get_url()
unless $owner and $repo;
my $github = Net::GitHub::V3->new(
@@ -101,6 +125,7 @@ sub new {
);
my %obj = (
+ %params,
github => $github,
owner => $owner,
repo => $repo,
@@ -154,22 +179,12 @@ sub create_fork {
return $gh->repos->create_fork($orgname);
}
-=head2 clone_branch_patch_push(%params)
+=head2 clone_branch_patch_push()
Clones a repository in a temporary directory, creates a new branch,
applies the patch, commits the change, pushes it and removes the
temporary working copy.
-=head3 Parameters:
-
-=over
-
-=item * subject
-
-Message used in the commit.
-
-=back
-
=head3 Returns:
Nothing.
@@ -184,8 +199,8 @@ sub clone_branch_patch_push {
my $user = $self->{owner};
my $repo = $self->{repo};
my $branch = $self->{branch};
- my $comment = $params{subject};
- my $patch = $self->{patch};
+ my $comment = $self->{message}->get_subject();
+ my $patch = $self->{message}->get_patch();
# Clone
my $workdir = tempdir( CLEANUP => 1 );
@@ -218,21 +233,7 @@ sub clone_branch_patch_push {
return;
}
-=head2 create_pull_request(%params)
-
-=head3 Parameters:
-
-=over
-
-=item * subject
-
-Title used in the pull request.
-
-=item * body
-
-Comment used as the body of the pull request message.
-
-=back
+=head2 create_pull_request()
=head3 Returns:
@@ -242,7 +243,6 @@ Pull request URL on success, nothing otherwise.
sub create_pull_request {
my $self = shift;
- my %params = @_;
my $gh = $self->{github};
my $user = $self->{owner};
@@ -251,8 +251,8 @@ sub create_pull_request {
$gh->pull_request->set_default_user_repo($user, $repo);
my $pull = $gh->pull_request->create_pull({
- title => $params{subject},
- body => $params{body},
+ title => $self->{message}->get_subject(),
+ body => $self->{message}->prepare_body(),
head => join(":", $self->{orgname}, $self->{branch}),
base => 'master',
labels => $self->{labels},
@@ -260,27 +260,12 @@ sub create_pull_request {
return $pull && $pull->{html_url};
}
-=head2 forward_patch_as_pull_request(%params)
-
-=head3 Parameters:
-
-=over
-
-=item * subject
-
-Title used in the pull request.
-
-=item * body
-
-Comment used as the body of the pull request message.
-
-=back
+=head2 forward_patch_as_pull_request()
=cut
sub forward_patch_as_pull_request {
my $self = shift;
- my %params = @_;
my $gh = $self->{github};
my $orgname = $self->{orgname};
@@ -288,39 +273,24 @@ sub forward_patch_as_pull_request {
unless $gh->user->show($orgname)->{login} eq $orgname;
$self->create_fork() unless $self->fork_exists();
- $self->clone_branch_patch_push(%params);
- my $issue_url = $self->create_pull_request(%params);
+ $self->clone_branch_patch_push();
+ my $issue_url = $self->create_pull_request();
return $issue_url;
}
-=head2 forward_bug_as_issue(%params)
-
-=head3 Parameters:
-
-=over
-
-=item * subject
-
-Title of the bug report.
-
-=item * body
-
-Comment used in the body of the bug report.
-
-=back
+=head2 forward_bug_as_issue()
=cut
sub forward_bug_as_issue {
my $self = shift;
- my %params = @_;
my $gh = $self->{github};
my $user = $self->{owner};
my $repo = $self->{repo};
my $ticket = $self->{ticket};
- my $title = $params{subject};
- my $comment = $params{body};
+ my $title = $self->{message}->get_subject();
+ my $comment = $self->{message}->prepare_body();
$gh->set_default_user_repo( $user, $repo );
@@ -340,82 +310,18 @@ sub forward_bug_as_issue {
return $issue->{html_url};
}
-=head2 patch($file)
-
-Set the filename of the patch to be forwarded.
-
-=head3 Parameters:
-
-=over
-
-=item * $file
-
-Filename containing a patch.
-
-=back
-
-=cut
-
-sub patch {
- my $self = shift;
- my ($file) = @_;
-
- $self->{patch} = $file;
-
- return $self;
-}
-
-=head2 bug($ticket)
-
-Set the bug nuber of the issue to be forwarded.
-
-=head3 Parameters:
-
-=over
-
-=item * $ticket
-
-An existing bug number. Forward will create a new one otherwise.
-
-=back
-
-=cut
-
-sub bug {
- my $self = shift;
- my ($ticket) = @_;
-
- $self->{ticket} = $ticket;
-
- return $self;
-}
-
-=head2 forward(%params)
+=head2 forward()
Forward an issue as a pull request or bug.
-=head3 Parameters:
-
-=over
-
-=item * subject
-
-The title of the forwarded issue.
-
-=item * body
-
-The comment of the forwarded issue.
-
-=back
-
=cut
sub forward {
my $self = shift;
- my $issue_url = $self->{patch}
- ? $self->forward_patch_as_pull_request(@_)
- : $self->forward_bug_as_issue(@_)
+ my $issue_url = $self->{message}->get_patch()
+ ? $self->forward_patch_as_pull_request()
+ : $self->forward_bug_as_issue()
;
return $issue_url;
diff --git a/scripts/forward b/scripts/forward
index b57d5eb..711da35 100755
--- a/scripts/forward
+++ b/scripts/forward
@@ -378,29 +378,13 @@ sub submit_cpan_rt {
}
sub submit_github {
-
- my $gh = Debian::PkgPerl::GitHub->new( tracker => $opt_tracker_url );
-
- # prepare subject
- my $subject = $message->get_subject();
-
- my $body = $message->prepare_body();
-
- my $issue_url;
-
- if ( $opt_offline_test ) {
- $issue_url = $gh->test();
- goto ISSUE_CREATED;
- }
-
- $gh->patch($patch);
- $gh->bug($opt_ticket);
- $issue_url = $gh->forward(
- subject => $subject,
- body => $body,
+ my $gh = Debian::PkgPerl::GitHub->new(
+ ticket => $opt_ticket,
+ message => $message,
);
-ISSUE_CREATED:
+ my $issue_url = $opt_offline_test ? $gh->test() : $gh->forward();
+
mark_patch_as_forwarded($issue_url) if $patch;
mark_bug_as_forwarded($issue_url) if $bug;
}
diff --git a/t/github.t b/t/github.t
index a04ddd0..903714a 100644
--- a/t/github.t
+++ b/t/github.t
@@ -12,29 +12,41 @@ BEGIN {
and -d $ENV{DPT_PACKAGES};
plan skip_all
- => "GitHub tests require DPT_GITHUB_OAUTH token"
- . " and a working Debian::PkgPerl::GitHub"
+ => "GitHub tests require DPT_GITHUB_OAUTH token,"
+ . " a working Debian::PkgPerl::GitHub,"
+ . " Debian::PkgPerl::Message,"
+ . " and Debian::PkgPerl::Patch"
unless $ENV{DPT_GITHUB_OAUTH}
and $ENV{DPT_GITHUB_OAUTH} =~ /^\w+$/
+ and eval { use Debian::PkgPerl::Patch; 1 }
+ and eval { use Debian::PkgPerl::Message; 1 }
and eval { use Debian::PkgPerl::GitHub; 1 };
}
use Test::RequiresInternet ( 'github.com' => 22 );
-# Defaults
-my $tracker = 'https://github.com/alexm/pkg-perl-dummy/issues';
-my $patch = "$ENV{DPT_PACKAGES}/pkg-perl-tools/t/dummy.txt.patch";
-my $comment = "Test patch $^T";
-my $body = 'Pull request by Debian pkg-perl team.';
+my %params = (
+ url => 'https://github.com/alexm/pkg-perl-dummy/issues',
+ tracker => 'github',
+ dist => 'Foo-Bar',
+ name => 'My Name',
+ email => 'my.name at example.com',
+ mailto => 'your.name at example.com',
+);
-my $gh = new_ok( 'Debian::PkgPerl::GitHub', [ tracker => $tracker ] );
-isa_ok( $gh->patch($patch), 'Debian::PkgPerl::GitHub', '$gh->patch' );
+my %info = Debian::PkgPerl::Patch
+ ->new( patch => "$ENV{DPT_PACKAGES}/pkg-perl-tools/t/dummy.txt.patch" )
+ ->retrieve_patch_info();
-my $url = $gh->forward(
- subject => $comment,
- body => $body,
+my $msg = Debian::PkgPerl::Message->new(
+ %params,
+ info => \%info,
+ interactive => 0,
);
+my $gh = new_ok( 'Debian::PkgPerl::GitHub', [ message => $msg ] );
+
+my $url = $gh->forward();
isnt( $url, undef, 'pull request' );
diag $url;
--
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