Git-Github-Creator

 view release on metacpan or  search on metacpan

lib/Git/Github/Creator.pm  view on Meta::CPAN


	my $basename = File::Basename::basename( $0 );

	foreach my $dir ( ".", $ENV{HOME} ) {
		my $file = File::Spec->catfile( $dir, ".$basename.ini" );
		DEBUG( "Trying config file [$file]" );
		next unless -e $file;

		$ini = Config::IniFiles->new( -file => $file );

		last;
		}

	die "Could not read config file!\n" unless defined $ini;

	# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
	# 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
		}

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.124 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )