App-GitHub-create
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/GitHub/create.pm view on Meta::CPAN
my $uri = "https://github.com/api/v2/json/repos/create";
my $response = $agent->post( $uri,
[ login => $login, token => $token, @arguments ] );
unless ( $response->is_success ) {
die $response->status_line, ": ", $response->decoded_content, "\n";
}
return $response;
}
sub usage (;$) {
my $error = shift;
my $exit = 0;
if ( defined $error ) {
if ( $error ) {
if ( $error =~ m/^\-?\d+$/ ) { $exit = $error }
else {
chomp $error;
warn $error, "\n";
$exit = -1;
}
}
}
warn <<_END_;
Usage: github-create [options] <name>
--login ... Your github login
--token ... The github token associated with the given login
Although required, if a login/token are not given,
github-create will attempt to load it from
\$HOME/.github or \$HOME/.github-identity (see
Config::Identity for more information)
--name ... The name of the repository to create (required)
--description ... A description of the repository (optional)
--homepage ... A homepage for the repository (optional)
--private The repository is private (default)
--public The repository is public
--help, -h, -? This help
_END_
exit $exit;
}
sub run {
my $self = shift;
my @arguments = @_;
my ( $login, $token, $help );
my ( $name, $homepage, $description, $private, $public, $dry_run );
usage 0 unless @arguments;
{
local @ARGV = @arguments;
GetOptions(
'help|h|?' => \$help,
'login=s' => \$login,
'token=s' => \$token,
'name=s' => \$name,
'description=s' => \$description,
'homepage=s' => \$homepage,
'private' => \$private,
'public' => \$public,
'dry-run' => \$dry_run,
);
@arguments = @ARGV;
}
usage 0 if $help;
$name = $arguments[0] unless defined $name && length $name;
unless ( defined $name && length $name ) {
usage <<_END_;
github-create: Missing name (--name)
_END_
}
if ( $private and $public ) {
usage <<_END_;
github-create: Repository cannot be both private AND public
_END_
}
$public = $public ? 1 : 0;
eval {
my $owner = $login;
$owner = '<username>' unless defined $owner;
unless ( $dry_run ) {
my $response = $self->create(
login => $login, token => $token,
name => $name, description => $description, homepage => $homepage, public => $public,
);
print $response->as_string;
eval {
no warnings;
require JSON;
my $data = JSON->new->decode( $response->decoded_content );
$_ and $owner = $_ for $data->{repository}->{owner};
};
}
print <<_END_;
Repository $name created. To track it, run the following:
# git remote add origin git\@github.com:$owner/$name.git
# git push origin master
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.335 second using v1.00-cache-2.02-grep-82fe00e-cpan-cec75d87357c )