Giter Site home page Giter Site logo

perl-net-github's Introduction

Build Status Actions Status Actions Status

NAME

Net::GitHub - Perl Interface for github.com

SYNOPSIS

use Net::GitHub;

my $github = Net::GitHub->new(  # Net::GitHub::V3
    login => 'fayland', pass => 'secret'
);

# If you use two factor authentication you can pass in the OTP. Do
# note that OTPs expire quickly and you will need to generate an oauth
# token to do anything non-trivial.
my $github = Net::GitHub->new(
    login =>   'fayland',
    pass =>    'secret',
    otp =>     '123456',
);

# Pass api_url for GitHub Enterprise installations. Do not include a
# trailing slash
my $github = Net::GitHub->new(  # Net::GitHub::V3
    login =>   'fayland',
    pass =>    'secret',
    api_url => 'https://gits.aresweet.com/api/v3'
);

# suggested
# use OAuth to create token with user/pass
my $github = Net::GitHub->new(  # Net::GitHub::V3
    access_token => $token
);

# L<Net::GitHub::V3::Users>
my $user = $github->user->show('nothingmuch');
$github->user->update( bio => 'Just Another Perl Programmer' );

# L<Net::GitHub::V3::Repos>
my @repos = $github->repos->list;
my $rp = $github->repos->create( {
    "name" => "Hello-World",
    "description" => "This is your first repo",
    "homepage" => "https://github.com"
} );

DESCRIPTION

http://github.com is a popular git host.

This distribution provides easy methods to access GitHub via their APIs.

Check http://developer.github.com/ for more details of the GitHub APIs.

Read Net::GitHub::V3 for API usage.

Read Net::GitHub::V4 for GitHub GraphQL API.

If you prefer object oriented way, Pithub is 'There is more than one way to do it'.

FAQ

  • create access_token for Non-Web Application

    my $gh = Net::GitHub::V3->new( login => 'fayland', pass => 'secret' );
    my $oauth = $gh->oauth;
    my $o = $oauth->create_authorization( {
        scopes => ['user', 'public_repo', 'repo', 'gist'], # just ['public_repo']
        note   => 'test purpose',
    } );
    print $o->{token};

    after create the token, you can use it without your password publicly written

    my $github = Net::GitHub->new(
        access_token => $token, # from above
    );

Git

http://github.com/fayland/perl-net-github/

SEE ALSO

Pithub

AUTHOR

Fayland Lam, <fayland at gmail.com>

Everyone who is listed in Changes.

COPYRIGHT & LICENSE

Copyright 2009-2012 Fayland Lam all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

perl-net-github's People

Contributors

atoomic avatar bentglasstube avatar bigpresh avatar briandfoy avatar c9s avatar fayland avatar fcuny avatar finn avatar grantm avatar gregoa avatar haarg avatar haraldjoerg avatar hiroraba avatar ioanrogers avatar jidanni avatar jj avatar jrmash avatar kimmel avatar lkundrak avatar mschilli avatar nebulous avatar obra avatar schwern avatar spang avatar sunnavy avatar toddr avatar waniji avatar warthog9 avatar worr avatar zw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

perl-net-github's Issues

Caching and conditional requests

Github supports the awkwardly named Conditional Requests to check if a resource has been modified. This allows one to cache API responses and cheaply check if there has been a change.

I plan on adding cache support to Net::GitHub::V3, on by default, with a simple Least Recently Used cache limited by number of queries stored. I plan on adding it at the query level so every query is cached. This allows Gitpan to make API requests as needed to check for changes rather than try to implement its own caching, make a bunch of redundant API calls, or just hope there's been no change.

What do you think?

new

my ticket

Unitialized value

I could be simply calling languages incorrectly, in which case this issue should be changed to "proper docs needed", or something of the like. But, when I call languages, with or without parameters, I get the following warning:

Use of uninitialized value $uargs[0] in sprintf at
    perl5/perlbrew/perls/perl-5.20.1/lib/site_perl/5.20.1/Net/GitHub/V3/Query.pm line 271 (#1)
    (W uninitialized) An undefined value was used as if it were already
    defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
    To suppress this warning assign a defined value to your variables.

    To help you figure out what was undefined, perl will try to tell you
    the name of the variable (if any) that was undefined.  In some cases
    it cannot do this, so it also tells you what operation you used the
    undefined value in.  Note, however, that perl optimizes your program
    and the operation displayed in the warning may not necessarily appear
    literally in your program.  For example, "that $foo" is usually
    optimized into "that " . $foo, and the warning will refer to the
    concatenation (.) operator, even though there is no . in
    your program.

Uncaught exception from user code:
    Use of uninitialized value $uargs[0] in sprintf at perl5/perlbrew/perls/perl-5.20.1/lib/site_perl/5.20.1/Net/GitHub/V3/Query.pm line 271.
    Net::GitHub::V3::Query::__ANON__() called at main.pl line 22
    main::main() called at main.pl line 40
Command terminated with non-zero status.
Command [perl main.pl] terminated with exit code 255 ($? = 65280) under the following perl environment:
Current perl:
  Name: perl-5.20.1
  Path: perl5/perlbrew/perls/perl-5.20.1/bin/perl
  Config: -de -Dprefix=perl5/perlbrew/perls/perl-5.20.1 -Aeval:scriptdir=perl5/perlbrew/perls/perl-5.20.1/bin
  Compiled at: Dec  6 2014 00:08:51

perlbrew:
  version: 0.71

I have snipped paths and such for my own privacy. The code I am trying to run can be found Here.

Branch protection rules?

Hello,

Apologies, but it wasn't clear to me, but is there a means to get/set branch protection rules for a repo/branch?

TIA!

Net::GitHub::V2::Commits() docs unclear

According to the documentation for Net::GitHub::V2::Commits, I can use:

use Net::GitHub::V2::Commits;
my $commit = Net::GitHub::V2::Commits->new();
my $co_detail = $commit->show( '0e2e9d452f807f4b7138ae707e84577c10891d0c' );

However, trying that gives:

  DB<4> $c = Net::GitHub::V2::Commits->new();
Attribute (owner) is required at (eval 34)[/usr/share/perl/5.10/perl5db.pl:638] line 2

I think the synopsis should be modified to show the use of the basic attributes that are required for that synopsis to actually function?

Also, it should probably use a better variable name than $commit for the object - I would expect $commit to contain details of a commit, or an object representing a single commit.

Latest Net::GitHub can install on Perl 5.16 and lower?

When trying to install the latest version of Net::Github package on Perl 5.16 on Windows, ExtUtils-MakeMaker generates an nmake makefile that is incomplete. When trying to build with it, an EOF error occurs. This would not be a problem on perls 5.18 and higher because those are built with mingw whereas the older perls are built with Visual Studio. Was this package regardless of version intended to work with older perls? If so, I can look at fixing the EOF problem.

No authentication in Repos->upload_asset()

Looking inside Net::GitHub::V3::Repos, the method is making request on its own, but not setting the access token by itself.
upload_asset() fails if it is the first one to call REST API with $ua.

new

my ticket

Bug in upload_asset: unknown method 'jsonToObj'

"sub upload_asset" has the line

$data = eval { $self->json->jsonToObj($json) };

perl doesn't like jsonToObj (unknown method).
The other functions use decode.
Changing the code to use decode fixes thing (for me :-)

Warnings in V3 when calling repos_issues

use strict;
use warnings;
use 5.010;
use Data::Dumper qw(Dumper);

my $access_token = shift or die "Usage: $0 ACCESS_TOKEN\n";

use Net::GitHub;
my $gh = Net::GitHub->new(
    version => 3,
    access_token => $access_token,
);

my @issues = $gh->issue->repos_issues;
Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/Net/GitHub/V3/Issues.pm line 72.
Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/Net/GitHub/V3/Issues.pm line 72.
Not Found at /usr/share/perl5/Net/GitHub/V3/Issues.pm line 45.

Note mimimum perl of 5.14, or change __build_methods

___build_methods does the following:

my $glob = do {
    no strict 'refs';
    no warnings 'once';
    *{"${package}::${m}"};
};
*$glob = sub {
    # ...
};

On perl 5.14, the fact that this is the glob of a glob causes the subroutine to not be callable:

#!/usr/bin/env perl
use strict;
use warnings;

package SomeThing;
sub real { print "Real!\n" }
sub build {
    print "Building!\n";
    my $glob = do {
        no strict 'refs';
        no warnings 'once';
        *{"SomeThing::fake"};
    };
    *$glob = sub { print "Fake!\n"; };
}
build();

package main;
SomeThing->real();
SomeThing->fake();

...produces (on 5.12):

Building!
Real!
Can't locate object method "fake" via package "SomeThing" at test.pl line 20.

This can be either fixed by not assigning to a glob of a glob:

no strict 'refs';
no warnings 'once';
*{"${package}::${name}"} = sub { print "Fake!\n"; };

..or adding an explicit perl dependency on 5.14.0. The perl commit which fixed this was Perl/perl5@2acc3314 (though Perl/perl5@0fe688f5 previously papered over it)

Bug with named parameters and repos->commit

Since version 1.02 (commit #102), I cannot use $ng->repos->commit anymore, it always errors with "Not found"

apparently the URL is constructed wrongly

sample code:

my $ng = Net::GitHub::V3->new();
$ng->set_default_user_repo(qw(a b));
print $ng->repos->commit("c");

-->

GET https://api.github.com/repos/c//commits/?per_page=100

correct would be

GET https://api.github.com/repos/a/b/commits/c

typo in README

The README file has a typo in it:

my $rp = $github->->create( {

It seems to me that there should be just 1 arrow.

Can't create GitHub client

Hi @fayland,

After the latest release(0.97:PR #89), I've faced with issue(example):
test.pl
`use strict;
use warnings;
use Net::GitHub::V3;
use TryCatch;
use Data::Dumper;

my $g;

try {

$g = Net::GitHub::V3->new (
	api_url=> 'https://blabla.com/api/v3',
	access_token => 'token',
);

} catch($e) {
print $e;
}

print Dumper $g;`
FAILED: Rate limiting is not enabled. at (eval 491) line 820.
image

It looks like I am not able to create Perl GitHub client due to that reason that rate limits are disabled on the server-side.

Could you please fix this issue ASAP or tell me where I am wrong?

CC: @toddr

Best Regards, Vasyl

JSON typing borken

f4bf04d has introduced a bug; code that does this:

my $resp = Net::GitHub->new( %gh_args )->repos->create_fork( $owner , $repo_name );

which used to work, now throws this error:

Reference bless( do{\(my $o = "")}, 'Cpanel::JSON::XS' ) did not pass type constraint (not isa     JSON::MaybeXS) (in $self->{"json"}) at (eval 163) line 32
    "InstanceOf["JSON::MaybeXS"]" requires that the reference isa JSON::MaybeXS
    The reference (in $self->{"json"}) isa Cpanel::JSON::XS and Exporter

Maybe that type check should be changed to check for all three things JSON::MaybeXS might return?

OAuth Access Token Support

Hi fayland,

I am using Net::GitHub from Plack::MIddleware::OAuth,

And for no-repo usage, i'd like to retrieve some information from API only, so I dont have an owner and an repo arguments.

what I only got this an access token (to support OAuth).

The request is like:

   GET https://github.com/api/v2/json/user/show?access_token=token_here

Can pagination be automatic?

Filed as an issue because I'm not sure if it's worthy of pull request, but the following has worked reasonably well for me to automatically dig thru pages. 1c3ba0a

rate limit headers

I just updated to Net::GitHub 0.75 from 0.54 and it broke my program. Prior to 0.60 WWW::Mechanize::GZip was being used to connect to the GitHub API endpoint. This allowed access to the custom response headers GitHub sends about rate limits. LWP::UserAgent does not work the same way so I added rate_limit, rate_limit_remaining, and rate_limit_reset variables to Net::GitHub::V3::Query as a way to expose that data to the developer. The official GitHub Ruby library has these variables as well https://github.com/octokit/octokit.rb/blob/master/lib/octokit/rate_limit.rb

All of that is the first commit. The second commit is just adding more documentation.

api_throttle should work with unauthenticated requests

Using App::SD, which uses Net::GitHub::V2, fetching github issues will often fail because github has throttled the request.

HTTP/1.1 403 Forbidden
Cache-Control: no-cache
Connection: close
Date: Wed, 21 Mar 2012 17:51:20 GMT
Server: nginx/1.0.13
Content-Encoding: gzip
Content-Length: 53
Content-Type: application/json; charset=utf-8
Client-Date: Wed, 21 Mar 2012 17:51:20 GMT
Client-Peer: 207.97.227.239:80
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
Status: 403 Forbidden
X-Content-Length: 73
X-Frame-Options: deny
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 0
X-Runtime: 3

{"error":["API Rate Limit Exceeded for 76.115.1.76"]}

There is code in Net::GitHub::V2::NoRepo->_get_json_to_obj_authed to deal with throttling, but none in get_json_to_obj. App::SD is doing $repo->issue->comment which uses $repo->get_json_to_obj.

The solution would seem to be to add the same throttling feature to get_json_to_obj.

what is returned by create_issue() ?

I am trying to update a script for migrating issues from Bugzilla to Github (https://github.com/vladak/BugzillaMigrate). For complete migration, it is necessary to migrate also bugs with status CLOSED/RESOLVED so I'd like to do something like this:

        my $iss = $issue->create_issue({
            title => $title,
            labels => @labels,
            body => $body});
        my $issue_id = $iss ???
        print "Bugzilla bug #$id migrated to Github Issue $issue_id\n";
        # If the original bug was closed then close the Github issue too.
        if ($status eq "CLOSED" || $status eq "RESOLVED") {
            $iss->update_issue( $issue_id, {
                state => 'closed'
            } );
        }

However, it is not clear how to get the issue ID of the newly created bug. What exactly is returned by create_issue() and how do I get issue ID out of it ?

GraphQL interface - link up with GraphQL module?

I see the ::V4 module interfaces with GitHub's GraphQL API. Soon the Perl GraphQL will gain code to do GraphQL queries, in order to facilitate "schema stitching", or what I call "schema federating".

What do you think of having your module's remote-querying code become part of GraphQL's so there is only one instead of several "out there"?

Feature request: add support for repos/releases

Looking at the code, it seems that repository "downloads" are supported (though this feature was deprecated on December 11, 2012), but the "releases" API which replaced it is not supported. It would be nice if the new API could be supported, too :-).

TFA?

I'm using two-factor authentication, and I'm willing to open my authenticator and give the number, but I don't see it mentioned (in either Net::GitHub or GitHub docs) how to add it.

Is it best to drop TFA to do this?

new

my ticket

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.