Git-Github-Creator
view release on metacpan or search on metacpan
lib/Git/Github/Creator.pm view on Meta::CPAN
# Setup logging
{
$debug = $ini->val( 'github', 'debug' ) || 0;
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init( $debug ? $DEBUG : $INFO );
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Read config
{
chomp( my @remotes = `git remote` );
my %remotes = map { $_, 1 } @remotes;
DEBUG( "Remotes are [@remotes]\n" );
die "github remote already exists! Exiting\n"
if exists $remotes{'github'};
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Okay, we should run, so pull in the modules
{
require File::Basename;
require File::Find;
require File::Find::Closures;
require File::Spec;
require Net::GitHub::V3;
my %Defaults = (
login_page => "https://github.com/login",
account => $ENV{GITHUB_USER} || '',
password => $ENV{GITHUB_PASS} || '',
remote_name => 'origin',
debug => 0,
'api-token' => $ENV{GITHUB_TOKEN} ||'',
);
foreach my $key ( keys %Defaults ) {
$Config{$key} = $ini->val( $Section, $key ) || $Defaults{$key};
DEBUG( "$key is $Config{$key}" );
}
}
my $opts = $class->_getopt(\@argv);
my $self = bless $opts => $class;
my $meta = $self->_get_metadata;
my $name = $meta->{name};
my $desc = $meta->{desc};
DEBUG( "Project is [$name]" );
DEBUG( "Project description is [$desc]" );
my $homepage = "http://search.cpan.org/dist/$name";
DEBUG( "Project homepage is [$homepage]" );
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Get to Github
my $credentials = do {
if( defined $Config{'api-token'} ) {
my $hash = {
access_token => $Config{'api-token'}
};
}
elsif( defined $Config{'account'} ) {
my $hash = {
login => $Config{account},
pass => $Config{password},
},
}
else {
my $hash = {},
}
};
my $github = Net::GitHub::V3->new( %$credentials );
DEBUG( "Got to GitHub" );
die "Exiting since you are debugging\n" if $Config{debug};
DEBUG( "Logged in" );
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Create the repository
my $resp = $github->repos->create( {
name => $name,
description => $desc,
homepage => $homepage,
}
);
{
no warnings 'uninitialized';
if( $resp->{error} =~ /401 Unauthorized/ ) {
die "Authorization failed! Wrong account or api token.\n";
}
}
if( my $error = $resp->{error} ) {
die $error->[0]{error}, "\n"; # ugh
}
my $private = sprintf 'git@github.com:%s/%s.git',
$Config{account}, $name;
DEBUG( "Private URL is [$private]" );
sleep 5; # github needs a moment to think
system( "git remote add $Config{remote_name} $private" );
system( "git push $Config{remote_name} master" );
}
sub _meta_yml {
my ($self, $name) = @_;
return $self->{meta_yml} ||= do
{
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Get module info from META.yml
if ( ! -e 'META.yml' ) {
if ( -e 'Makefile.PL' ) {
system "$^X Makefile.PL" unless -e 'Makefile';
system "make metafile" if -e 'Makefile';
}
elsif( -e 'Build.PL' ) {
system "$^X Build.PL" unless -e 'Build';
system './Build distmeta' if -e 'Build';
}
}
my @files = grep { -e } qw(MYMETA.yml META.yml), glob( "*/META.yml" );
DEBUG( "$files[0] found" );
die "No META.yml found\n" unless -e $files[0];
( run in 3.066 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )