App-GitHubPullRequest
view release on metacpan or search on metacpan
lib/App/GitHubPullRequest.pm view on Meta::CPAN
$0 [<command> <args> ...]
Where command is one of these:
help Show this page
list [<state>] Show all pull requests (state: open/closed)
show <number> Show details for the specified pull request
patch <number> Fetch a properly formatted patch for specified pull request
checkout <number> Create tracking branch for specified pull request
login [<user>] [<password>] [<two-factor-auth-token>]
Login to GitHub and receive an access token (deprecated)
authorize Create a GitHub OAuth personal access token
comment <number> [<text>] Create a comment on the specified pull request
close <number> Close the specified pull request
open <number> Reopen the specified pull request
EOM
return 1;
}
lib/App/GitHubPullRequest.pm view on Meta::CPAN
my $count = unlink $filename;
warn("Unable to remove temporary file $filename: $!\n")
unless $count;
}
return 0;
}
sub login {
my ($self, $user, $password, $two_factor_token) = @_;
# Add deprecation message
say "\nThis authorization method is deprecated and will be removed on November 13, 2020.";
say "Please use the 'authorize' command to authenticate with GitHub.\n";
# Try to fetch user/password from git config (or prompt)
$user ||= _qx('git', "config github.user") || _prompt('GitHub username');
$password ||= _qx('git', "config github.password") || _prompt('GitHub password', 'hidden');
die("Please specify a user name.\n") unless $user;
die("Please specify a password.\n") unless $password;
# Prompt for two-factor auth token
$two_factor_token ||= _prompt('GitHub two-factor authentication token (if any)');
# Perform authentication
my $auth = _api_create(
"/authorizations",
{
"scopes" => [qw( public_repo repo )],
"note" => __PACKAGE__,
"note_url" => 'https://metacpan/module/' . __PACKAGE__,
},
$user,
$password,
$two_factor_token,
);
die("Unable to authenticate with GitHub.\n")
unless defined $auth;
my $token = $auth->{'token'};
die("Authentication data does not include a token.\n")
unless $token;
# Store authorization token
my ($content, $rc) = _run_ext(qw(git config --global github.pr-token), $token);
lib/App/GitHubPullRequest.pm view on Meta::CPAN
if $repo_info->{'fork'};
# Not a fork, use this repo
return $repo;
}
die("No valid GitHub repo found. List of remotes exhausted.\n");
}
# Ask the user for some information
# Disable local echo if $hide_echo is true (for passwords)
sub _prompt {
my ($label, $hide_echo) = @_;
_echo('off') if $hide_echo;
print "$label: " if defined $label;
my $input = scalar <STDIN>;
chomp $input;
print "\n";
_echo('on') if $hide_echo;
return $input;
}
lib/App/GitHubPullRequest.pm view on Meta::CPAN
. $content
) if $code == 422;
die("Patching URL $url failed with code $code:\n$content");
}
return $content;
}
# Perform HTTP POST
sub _post_url {
my ($url, $mimetype, $data, $user, $password, $two_factor_token) = @_;
croak("Please specify a URL") unless $url;
croak("Please specify a mimetype") unless $mimetype;
croak("Please specify some data") unless $data;
# See if we should use credentials
my @credentials;
if ( _is_api_url($url) ) {
my $token = _qx('git', 'config github.pr-token');
die("You must login before you can modify information.\n")
unless $token or ( $user and $password );
if ( $user and $password ) {
@credentials = ( '-u', "$user:$password" );
push @credentials, '-H', "X-GitHub-OTP: $two_factor_token"
if $two_factor_token;
}
else {
@credentials = ( '-H', "Authorization: token $token" ) if $token;
}
}
# Send request
my ($content, $rc) = _run_ext(
lib/App/GitHubPullRequest.pm view on Meta::CPAN
Creates a comment on the specified pull request with the specified text. If
text is not specified, an editor will be opened for you to type in the text.
If your C<EDITOR> environment variable has been set, that editor is used to
edit the text. If it has not been set, it will try to use the L<editor(1)>
external program. This is usually a symlink set up by your operating system
to the most recently installed text editor.
The text must be encoded using UTF-8.
=head2 login [<user>] [<password>] [<2fa-token>]
DEPRECATED: Logs you in to GitHub and creates a new access token used
instead of your password and two-factor authentication token. If you don't
specify either of the options, they are looked up in your git config github
section. If none of those are found, you'll be prompted for them.
=head2 authorize [<access-token>]
Logs you in to GitHub by manually creating an OAuth personal access token.
Follow the directions on-screen to generate one and insert it when prompted.
If you already have an access token you want to use you can also specify it
on the command line.
( run in 1.191 second using v1.01-cache-2.11-cpan-49f99fa48dc )