App-GitHub-update

 view release on metacpan or  search on metacpan

lib/App/GitHub/update.pm  view on Meta::CPAN

package App::GitHub::update;
BEGIN {
  $App::GitHub::update::VERSION = '0.0011';
}
# ABSTRACT: Update a github repository (description, homepage, etc.) from the commandline


use strict;
use warnings;

use Config::Identity::GitHub;
use LWP::UserAgent;
use Getopt::Long qw/ GetOptions /;
my $agent = LWP::UserAgent->new;

sub update {
    my $self = shift;
    my %given = @_;
    my ( $login, $token, $repository, $description, $homepage );

    ( $repository, $description, $homepage ) = @given{qw/ repository description homepage /};
    defined $_ && length $_ or die "Missing repository\n" for $repository;

    ( $login, $token ) = @given{qw/ login token /};
    unless( defined $token && length $token ) {
        my %identity = Config::Identity::GitHub->load;
        ( $login, $token ) = @identity{qw/ login token /};
    }

    my @arguments;
    push @arguments, 'values[description]' => $description if defined $description;
    push @arguments, 'values[homepage]' => $homepage if defined $homepage;

    my $uri = "https://github.com/api/v2/json/repos/show/$login/$repository";
    my $response = $agent->post( $uri,
        [ login => $login, token => $token, @arguments ] );

    unless ( $response->is_success ) {
        die $response->status_line, "\n", $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-update [opt]

    --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)

    --repository ...    The repository to update

    --description ...   The new description of the repository
    --homepage ...      A homepage for the repository

    --help, -h, -?      This help


_END_

#    --dzpl              Guess repository and description from Dist::Dzpl
#                        configuration (name and abstract, respectively)

    exit $exit;
}

sub guess_dzpl {
    my $self = shift;
    my %guess;

    eval {
        # Oh god this is hacky
        package App::GitHub::update::Sandbox;
BEGIN {
  $App::GitHub::update::Sandbox::VERSION = '0.0011';
}
        local @ARGV;
        do './dzpl';
        my $dzpl = $Dzpl::dzpl;
        $dzpl = $Dzpl::dzpl;



( run in 0.919 second using v1.01-cache-2.11-cpan-9581c071862 )