App-GitHub-update

 view release on metacpan or  search on metacpan

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

        [ 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;
        $dzpl->zilla->_setup_default_plugins;
        $_->gather_files for ( @{ $dzpl->zilla->plugins_with(-FileGatherer) } );
        $guess{repository} = $dzpl->zilla->name;
        $guess{description} = $dzpl->zilla->abstract;
    };
    die $@ if $@;

    return %guess;
}

sub run {
    my $self = shift;
    my @arguments = @_;

    usage 0 unless @arguments;

    my ( $login, $token, $repository, $dzpl, $help );
    my ( $homepage, $description );
    {
        local @ARGV = @arguments;
        GetOptions(
            'help|h|?' => \$help,

            'login=s' => \$login,
            'token=s' => \$token,
            'repository=s' => \$repository,

            'dzpl' => \$dzpl,

            'description=s' => \$description,
            'homepage=s' => \$homepage,
        );
    }

    usage 0 if $help;

    if ( $dzpl ) {
        my %guess = $self->guess_dzpl;
        $repository ||= $guess{repository};
        $description ||= $guess{description};
    }
    
    eval {
        my $response = $self->update(
            login => $login, token => $token, repository => $repository,
            description => $description, homepage => $homepage,
        );

        print $response->as_string, "\n";
    };
    if ($@) {
        usage <<_END_;
github-update: $@
_END_
    }
}

1;

__END__
=pod

=head1 NAME

App::GitHub::update - Update a github repository (description, homepage, etc.) from the commandline

=head1 VERSION

version 0.0011

=head1 SYNOPSIS

    # Update the description of github:alice/example
    github-update --login alice --token 42fe60... --repository example --description "Xyzzy"

    # Pulling login and token from $HOME/.github
    github-update --repository example --description "Xyzzy"

    # With homepage
    github-update --repository example --description "The incredible Xyzzy" --homepage http://example/xyzzy

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

( run in 1.313 second using v1.00-cache-2.02-grep-82fe00e-cpan-d29e8ade9f55 )