Giter VIP home page Giter VIP logo

github's Introduction

github api logo

GithubAPI Gitter

Gem Version Build Status Maintainability Coverage Status Inline docs

Website | Wiki | RDocs

A Ruby client for the official GitHub API.

Supports all the API methods. It's built in a modular way. You can either instantiate the whole API wrapper Github.new or use parts of it i.e. Github::Client::Repos.new if working solely with repositories is your main concern. Intuitive query methods allow you easily call API endpoints.

Features

  • Intuitive GitHub API interface navigation.
  • It's comprehensive. You can request all GitHub API resources.
  • Modular design allows for working with parts of API.
  • Fully customizable including advanced middleware stack construction.
  • Supports OAuth2 authorization.
  • Flexible argument parsing. You can write expressive and natural queries.
  • Requests pagination with convenient DSL and automatic options.
  • Easy error handling split for client and server type errors.
  • Supports multithreaded environment.
  • Custom media type specification through the 'media' parameter.
  • Request results caching
  • Fully tested with unit and feature tests hitting the live api.

Installation

Install the gem by running

gem install github_api

or put it in your Gemfile and run bundle install

gem "github_api"

Contents

1 Usage

To start using the gem, you can either perform requests directly on Github namespace:

Github.repos.list user: 'piotrmurach'

or create a new client instance like so

github = Github.new

and then call api methods, for instance, to list a given user repositories do

github.repos.list user: 'piotrmurach'

1.1 API Navigation

The github_api closely mirrors the GitHub API hierarchy. For example, if you want to create a new file in a repository, look up the GitHub API spec. In there you will find contents sub category underneath the repository category. This would translate to the request:

github = Github.new
github.repos.contents.create 'piotrmurach', 'finite_machine', 'hello.rb',
                             path: 'hello.rb',
                             content: "puts 'hello ruby'"

The whole library reflects the same api navigation. Therefore, if you need to list releases for a repository do:

github.repos.releases.list 'piotrmurach', 'finite_machine'

or to list a user's followers:

github.users.followers.list 'piotrmurach'

The code base has been extensively documented with examples of how to use each method. Please refer to the documentation under the Github::Client class name.

Alternatively, you can find out which methods are supported by an api by calling actions on a class or instance. For example, in order to find out available endpoints for Github::Client::Repos::Contents api call actions method:

Github::Client::Repos::Contents.actions
=> [:archive, :create, :delete, :find, :get, :readme, :update]

1.2 Modularity

The code base is modular. This means that you can work specifically with a given part of GitHub API. If you want to only work with activity starring API do the following:

starring = Github::Client::Activity::Starring.new oauth_token: token
starring.star 'piotrmurach', 'github'

Please refer to the documentation and look under Github::Client to see all available classes.

1.3 Arguments

The github_api library allows for flexible argument parsing.

Arguments can be passed directly inside the method called. The required arguments are passed in first, followed by optional parameters supplied as hash options:

issues = Github::Client::Issues.new
issues.milestones.list 'piotrmurach', 'github', state: 'open'

In the previous example, the order of arguments is important. However, each method also allows you to specify required arguments using hash symbols and thus remove the need for ordering. Therefore, the same example could be rewritten like so:

issues = Github::Client::Issues.new
issues.milestones.list user: 'piotrmurach', repo: 'github', state: 'open'

Furthermore, required arguments can be passed during instance creation:

issues = Github::Client::Issues.new user: 'piotrmurach', repo: 'github'
issues.milestones.list state: 'open'

Similarly, the required arguments for the request can be passed inside the current scope such as:

issues = Github::Client::Issues.new
issues.milestones(user: 'piotrmurach', repo: 'github').list state: 'open'

But why limit ourselves? You can mix and match arguments, for example:

issues = Github::Client::Issues.new user: 'piotrmurach'
issues.milestones(repo: 'github').list
issues.milestones(repo: 'tty').list

You can also use a bit of syntactic sugar whereby "username/repository" can be passed as well:

issues = Github::Client::Issues.new
issues.milestones('piotrmurach/github').list
issues.milestones.list 'piotrmurach/github'

Finally, use the with scope to clearly denote your requests

issues = Github::Client::Issues.new
issues.milestones.with(user: 'piotrmurach', repo: 'github').list

Please consult the method documentation or GitHub specification to see which arguments are required and what are the option parameters.

1.4 Response Querying

The response is of type Github::ResponseWrapper and allows traversing all the json response attributes like method calls. In addition, if the response returns more than one resource, these will be automatically yielded to the provided block one by one.

For example, when request is issued to list all the branches on a given repository, each branch will be yielded one by one:

repos = Github::Client::Repos.new
repos.branches user: 'piotrmurach', repo: 'github' do |branch|
  puts branch.name
end

1.4.1 Response Body

The ResponseWrapper allows you to call json attributes directly as method calls. there is no magic here, all calls are delegated to the response body. Therefore, you can directly inspect request body by calling body method on the ResponseWrapper like so:

response = repos.branches user: 'piotrmurach', repo: 'github'
response.body  # => Array of branches

1.4.2 Response Headers

Each response comes packaged with methods allowing for inspection of HTTP start line and headers. For example, to check for rate limits and status codes do:

response = Github::Client::Repos.branches 'piotrmurach', 'github'
response.headers.ratelimit_limit     # "5000"
response.headers.ratelimit_remaining # "4999"
response.headers.status              # "200"
response.headers.content_type        # "application/json; charset=utf-8"
response.headers.etag                # "\"2c5dfc54b3fe498779ef3a9ada9a0af9\""
response.headers.cache_control       # "public, max-age=60, s-maxage=60"

1.4.3 Response Success

If you want to verify if the response was success, namely, that the 200 code was returned call the success? like so:

response = Github::Client::Repos.branches 'piotrmurach', 'github'
response.success?  # => true

1.5 Request Headers

It is possible to specify additional header information which will be added to the final request.

For example, to set etag and X-Poll_Interval headers, use the :headers hash key inside the :options hash like in the following:

events = Github::Client::Activity::Events.new
events.public headers: {
    'X-Poll-Interval': 60,
    'ETag': "a18c3bded88eb5dbb5c849a489412bf3"
  }

1.5.1 Media Types

In order to set custom media types for a request use the accept header. By using the :accept key you can determine media type like in the example:

issues = Github::Client::Issues.new
issues.get 'piotrmurach', 'github', 108, accept: 'application/vnd.github.raw'

2 Configuration

The github_api provides ability to specify global configuration options. These options will be available to all api calls.

2.1 Basic

The configuration options can be set by using the configure helper

Github.configure do |c|
  c.basic_auth = "login:password"
  c.adapter    = :typheous
  c.user       = 'piotrmurach'
  c.repo       = 'finite_machine'
end

Alternatively, you can configure the settings by passing a block to an instance like:

Github.new do |c|
  c.endpoint    = 'https://github.company.com/api/v3'
  c.site        = 'https://github.company.com'
  c.upload_endpoint = 'https://github.company.com/api/uploads'
end

or simply by passing hash of options to an instance like so

github = Github.new basic_auth: 'login:password',
                    adapter: :typheous,
                    user: 'piotrmurach',
                    repo: 'finite_machine'

The following is the full list of available configuration options:

adapter            # Http client used for performing requests. Default :net_http
auto_pagination    # Automatically traverse requests page links. Default false
basic_auth         # Basic authentication in form login:password.
client_id          # Oauth client id.
client_secret      # Oauth client secret.
connection_options # Hash of connection options.
endpoint           # Enterprise API endpoint. Default: 'https://api.github.com'
oauth_token        # Oauth authorization token.
org                # Global organization used in requests if none provided
per_page           # Number of items per page. Max of 100. Default 30.
repo               # Global repository used in requests in none provided
site               # enterprise API web endpoint
ssl                # SSL settings in hash form.
user               # Global user used for requests if none provided
user_agent         # Custom user agent name. Default 'Github API Ruby Gem'

2.2 Advanced

The github_api will use the default middleware stack which is exposed by calling stack on a client instance. However, this stack can be freely modified with methods such as insert, insert_after, delete and swap. For instance, to add your CustomMiddleware do:

Github.configure do |c|
  c.stack.insert_after Github::Response::Helpers, CustomMiddleware
end

Furthermore, you can build your entire custom stack and specify other connection options such as adapter by doing:

Github.new do |c|
  c.adapter :excon

  c.stack do |builder|
    builder.use Github::Response::Helpers
    builder.use Github::Response::Jsonize
  end
end

2.3 SSL

By default requests over SSL are set to OpenSSL::SSL::VERIFY_PEER. However, you can turn off peer verification by

github = Github.new ssl: { verify: false }

If your client fails to find CA certs, you can pass other SSL options to specify exactly how the information is sourced

ssl: {
  client_cert: "/usr/local/www.example.com/client_cert.pem"
  client_key:  "/user/local/www.example.com/client_key.pem"
  ca_file:     "example.com.cert"
  ca_path:     "/etc/ssl/"
}

For instance, download CA root certificates from Mozilla cacert and point ca_file at your certificate bundle location. This will allow the client to verify the github.com ssl certificate as authentic.

2.4 Caching

Caching is supported through the faraday-http-cache gem.

Add the gem to your Gemfile:

gem 'faraday-http-cache'

You can now configure cache parameters as follows

Github.configure do |config|
  config.stack = proc do |builder|
    builder.use Faraday::HttpCache, store: Rails.cache
  end
end

More details on the available options can be found in the gem's own documentation: https://github.com/plataformatec/faraday-http-cache#faraday-http-cache

3 Authentication

3.1 Basic

To start making requests as authenticated user you can use your GitHub username and password like so

Github.new basic_auth: 'login:password'

Though this method is convenient you should strongly consider using OAuth for improved security reasons.

3.2 Authorizations API

3.2.1 For a User

To create an access token through the GitHub Authorizations API, you are required to pass your basic credentials and scopes you wish to have for the authentication token.

github = Github.new basic_auth: 'login:password'
github.auth.create scopes: ['repo'], note: 'admin script'

You can add more than one scope from the user, public_repo, repo, gist or leave the scopes parameter out, in which case, the default read-only access will be assumed (includes public user profile info, public repo info, and gists).

3.2.2 For an App

Furthermore, to create auth token for an application you need to pass :app argument together with :client_id and :client_secret parameters.

github = Github.new basic_auth: 'login:password'
github.auth.app.create 'client-id', scopes: ['repo']

In order to revoke auth token(s) for an application you must use basic authentication with client_id as login and client_secret as password.

github = Github.new basic_auth: "client_id:client_secret"
github.auth.app.delete 'client-id'

Revoke a specific app token.

github.auth.app.delete 'client-id', 'access-token'

3.3 Scopes

You can check OAuth scopes you have by:

github = Github.new oauth_token: 'token'
github.scopes.list    # => ['repo']

or inidividually for a given user:

github = Github.new
github.scopes.list 'token'

To list the scopes that the particular GitHub API action checks for do:

repos = Github::Client::Repos.new
response = repos.list user: 'piotrmurach'
response.headers.accepted_oauth_scopes  # => ['delete_repo', 'repo', 'public_repo']

To understand what each scope means refer to documentation

3.4 Application OAuth

In order to authenticate your app through OAuth2 on GitHub you need to

You can use convenience methods to help you achieve this using GithubAPI gem:

github = Github.new client_id: '...', client_secret: '...'
github.authorize_url redirect_uri: 'http://localhost', scope: 'repo'
# => "https://github.com/login/oauth/authorize?scope=repo&response_type=code&client_id='...'&redirect_uri=http%3A%2F%2Flocalhost"

After you get your authorization code, call to receive your access_token

token = github.get_token( authorization_code )

Once you have your access token, configure your github instance following instructions under Configuration.

Note: If you are working locally (i.e. your app URL and callback URL are localhost), do not specify a :redirect_uri otherwise you will get a redirect_uri_mismatch error.

3.5 Two-Factor

In order to use Two-Factor authentication you need provide X-GitHub-OTP: required; :2fa-type header.

You can add headers during initialization:

Github.new do |config|
  config.basic_auth         = "user:password"
  config.connection_options = {headers: {"X-GitHub-OTP" => '2fa token'}}
end

or per request:

github = Github.new basic_auth: 'login:password'
github.oauth.create scopes: ["public_repo"],
                    headers: {"X-GitHub-OTP" => "2fa token"}

4 Pagination

Any request that returns multiple items will be paginated to 30 items by default. You can specify custom page and per_page query parameters to alter default behavior. For instance:

repos    = Github::Client::Repos.new
response = repos.list user: 'wycats', per_page: 10, page: 5

Then you can query the pagination information included in the link header by:

response.links.first  # Shows the URL of the first page of results.
response.links.next   # Shows the URL of the immediate next page of results.
response.links.prev   # Shows the URL of the immediate previous page of results.
response.links.last   # Shows the URL of the last page of results.

In order to iterate through the entire result set page by page, you can use convenience methods:

response.each_page do |page|
  page.each do |repo|
    puts repo.name
  end
end

or use has_next_page? and next_page helper methods like in the following:

while response.has_next_page?
  ... process response ...
  res.next_page
end

One can also navigate straight to the specific page by:

res.count_pages  # Number of pages
res.page 5       # Requests given page if it exists, nil otherwise
res.first_page   # Get first page
res.next_page    # Get next page
res.prev_page    # Get previous page
res.last_page    # Get last page

4.1 Auto pagination

You can retrieve all pages in one invocation by passing the auto_pagination option like so:

github = Github.new auto_pagination: true

Depending at what stage you pass the auto_pagination it will affect all or only a single request. For example, in order to auto paginate all Repository API methods do:

Github::ะกlient::Repos.new auto_pagination: true

However, to only auto paginate results for a single request do:

Github::Client::Repos.new.list user: '...', auto_pagination: true

5 Error Handling

The generic error class Github::Error::GithubError will handle both the client (Github::Error::ClientError) and service (Github::Error::ServiceError) side errors.

For instance in your code you can catch errors like

begin
  # Do something with github_api gem
rescue Github::Error::GithubError => e
  puts e.message
  if e.is_a? Github::Error::ServiceError
    # handle GitHub service errors such as 404
  elsif e.is_a? Github::Error::ClientError
    # handle client errors e.i. missing required parameter in request
  end
end

5.1 Client Error

Any time Github client has a problem sending request a Github::Error::ClientError is raised that will provide a summary of the problem and possible solutions.

5.2 Service Error

When the Github client receives a HTTP response from GitHub service that indicates error then Github::Error::ServiceError is raised.

There are number of specific error types such as Github::Error::NotAcceptable when 406 status code is returned.

5.2.1 Data

When Github::Error::ServiceError is raised you can call data to access it payload in JSON format.

5.2.2 Error messages

Anytime there are error messages provided with Github::Error::ServiceError you can access them by calling error_messages helper.

6 Examples

6.1 Rails

A Rails controller that allows a user to authorize their GitHub account and then performs a request.

class GithubController < ApplicationController

  def authorize
    address = github.authorize_url redirect_uri: 'http://...', scope: 'repo'
    redirect_to address
  end

  def callback
    authorization_code = params[:code]
    access_token = github.get_token authorization_code
    access_token.token   # => returns token value
  end

  private

   def github
    @github ||= Github.new client_id: '...', client_secret: '...'
   end
end

6.2 Manipulating Files

In order to be able to create/update/remove files you need to use Contents API like so:

contents = Github::Client::Repos::Contents.new oauth_token: '...'

Having instantiated the contents, to create a file do:

contents.create 'username', 'repo_name', 'full_path_to/file.ext',
  path: 'full_path_to/file.ext',
  message: 'Your commit message',
  content: 'The contents of your file'

Content is all Base64 encoded to/from the API, and when you create a file it encodes it automatically for you.

To update a file, first you need to find the file so you can get the SHA you're updating off of:

file = contents.find path: 'full_path_to/file.ext'

Then update the file just like you do with creating:

contents.update 'username', 'repo_name', 'full_path_to/file.ext',
  path: 'full_path_to/file.ext'
  message: 'Your commit message',
  content: 'The contents to be updated',
  sha: file.sha

Finally to remove a file, find the file so you can get the SHA you're removing:

file = contents.find path: 'full_path_to/file.ext'

Then delete the file like so:

github.delete 'username', 'tome-of-knowledge', 'full_path_to/file.ext',
  path: 'full_path_to/file.ext',
  message: 'Your Commit Message',
  sha: file.sha

7 Testing

The test suite is split into two groups, live and mock.

The live tests are in the features folder and exercise the GitHub API directly by making live requests and then caching responses with VCR in directory named features\cassettes. For details on how to get set up, please navigate to the features folder.

To run all feature tests do:

bundle exec rake features

The mock tests are in the spec folder and their primary concern is to test the gem internals without the hindrance of external calls.

To run all specs do:

bundle exec rake spec

Finally to run all tests do:

bundle exec rake

Development

Questions or problems? Please post them on the issue tracker. You can contribute changes by forking the project and submitting a pull request. You can ensure the tests are passing by running bundle and rake.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/piotrmurach/github. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Copyright

Copyright (c) 2011 Piotr Murach. See LICENSE.txt for further details.

github's People

Contributors

5long avatar agis avatar boyan avatar codenamev avatar fluke avatar gentilfp avatar jcabasc avatar jkeiser avatar jonmchan avatar kennyadsl avatar kmiyake avatar leoarnold avatar lukeasrodgers avatar maksimabramchuk avatar nahiluhmot avatar nickmerwin avatar nicolasleger avatar olleolleolle avatar piotrmurach avatar pkhxcp avatar prasadsurase avatar rhc2104 avatar shadabahmed avatar shwetakale avatar smortex avatar soh335 avatar ssmiech avatar tma avatar trodrigu avatar zenspider 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  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

github's Issues

Hook Payload Missing Keys

I'm using the following code to try creating service hooks:

repo = Github::Repos.new AUTH_HASH
repo.create_hook 'itspriddle', 'test-repo', :name => 'email', :active => true, :config => { :address => '[email protected]' }

From the log:

EXECUTED: post - /repos/itspriddle/test-repo/hooks with {"name"=>"email", "active"=>true, "config"=>{}} and {"resource"=>"", "mime_type"=>""}

It seems the call to Github::Filter#_filter_parameter_keys in hooks.rb is removing values from the config hash. If that is commented out, the request is submitted with the proper parameters.

I've only tested this with create_hook, but I'd imagine it affects the other *_hook methods as well.

Authorization lost during the session

Hi,

I found a bug which is really weird.
I ask the access token to have acces to private repos. It works fine.
I refresh the page, I'm still able to see the private repo.

Then, I go to an other page which shows the commits of a repo. Fine.

I come back to the page with the repos... and I'm not able to see the private repo anymore.. and I have to restart my local server and sign in again to be able to see them..

Do you have an idea of how we can fixe it?

Thanks.

github.issues.milestones.list should default to really listing all milestones

It's a bit confusing for a first timer that the milestones list actually only list open milestones:

...so instead of this:

    milestones = github.issues.milestones.list username, repo

we have to do this:

    milestones_open = github.issues.milestones.list username, repo, {
        'state' => 'open'
    }

    milestones_closed = github.issues.milestones.list username, repo, {
        'state' => 'closed'
    }

selecting on state is problematic because milestone state changes from open to closed if you assign (for example) one closed bug to it. And then it stays closed if you remove that bug from the milestone!

maybe a 'state' => 'all' and default to that?

Incorrect pagination URL (GitHub Enterprise)

res.has_next_page?
=> true
res.next_page

Github::Error::NotFound: GET https://<base_url>/api/v3https:/<base_url>/api/v3/repos/GitHub/issues-dev/issues?access_token=6be0fee68771763564d5580b8ff52f617dde8e7a&page=2&per_page=100: 404 {"message":"Not Found"}

(base_url edited out from the URL)

Question: API commit possible?

Github's API does not provide access to the "online commit" functionality via their web interface right? Therefore, it will not be possible to add it here I guess... :/

Question: create_issue required params

I'm currently doing

gh = Github.new :oauth_token => token, :user => account, :repo => gh_repo
gh.issues.create_issue :title => 'Test title', :body => 'test body'

and I am getting

ArgumentError: Required params are: :title

I've also tried
gh.issues.create_issue 'title' => 'test title'
as noted on the example and getting the same error. Any idea why this is happening?

LOC

Is it possible to retrieve total lines of code from a given branch in a repository?

Why is Github::Error::GithubError#message a Hash and not a String?

I want to test a method which is using this gem. However, since the message attribute is a Hash it's difficult to test and makes the code a bit brittle too. Here's what I have. Is there a better way to do this?

begin
      #Do something with github_api gem
rescue Github::Error::GithubError => e
    puts e.message.class #Hash
    #To get the message, I need to do something like:
    resp = JSON.load(e.response_message[:body])
    resp["errors"][0]["message"] #e.g. 'key is already in use'
    #do something with this message
 end

Querying the events time line

Hi Piotr,

I want to save to a local database segments of the public github timeline and I was wondering what would be the best approach to do that.

In particular I would like to get this type of events:

  • CommitCommentEvent
  • IssueCommentEvent
  • PullRequestReviewCommentEvent

How can I query for the last 10.000 events?
How can I query for the events of a given date, or month?

Thank you!

Repos::Contents sends the wrong request as well as a JSON encoding issue.

It looks like on line 57 of repos.rb you reference @commits instead of @contents. This makes the request go to repos/commits instead of repos/contents.

I fixed this locally and it seems like the request is now going where it needs to. But I then run into another issue where the JSON parsing of that request fails. It looks like instead of returning the base64 encoded string it's decoding it and trying to put that into the JSON object which isn't working.

Is there some kind of setting I can make that will leave the returned base64 encoded string encoded?

bug in repos.list

I have problem with list repo when i get this for many users, the first time do it fine but then it lose the session

def list(*args)
      params = args.extract_options!
      normalize! params
      _merge_user_into_params!(params) if params.has_key?('user')
      filter! %w[ org user type ], params

      response = if (user_name = params.delete("user"))
        get_request("/users/#{user_name}/repos", params)
      elsif (org_name = params.delete("org"))
        get_request("/orgs/#{org_name}/repos", params)
      else
        # For authenticated user
        get_request("/user/repos", params)
      end
      return response unless block_given?
      response.each { |el| yield el }
    end

when I take this line

 _merge_user_into_params!(params) if params.has_key?('user')

this works perfect, why you add this if later you add in the url the user

 get_request("/users/#{user_name}/repos", params)

OpenSSL certificate verify failed

When I issue,```
git_data = Github::GitData.new :basic_auth => 'user:password'
blob = git_data.create_blob "username", "reponame", "content" => 'somecontent', "encoding" => "utf-8"

I get
**OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed**

The traceback is here:
http://pastie.org/3385896

I am using ruby 1.9.2p290

problem with memoization in rails 3.2.6

hi guys I have a problem with rails for example I list all repo from one user and then I list all repo from another user and I get the same repo that the first user, I was seeing the code and it is using many memoization in vars (var ||= value)

anyone has this problem in rails too?

github_api dependencies broken

Currently showing that there is a dependency issue causing installation failure, as seen here at https://gist.github.com/2338724

I currently am not qualified to fix, or I would offer a patch. So, instead I'm opening the bug and providing the gist! :-) If there's anything I can offer or do to assist, feel free to ask.

Relax oauth2 dependencies please

Hi Piotr!

I am really loving this gem!

Please relax the oauth2 @ 0.7 if possible, pretty please.

I have the same problems as explained in #35

Except now the oauth2 dependency for github_api @ 0.7 is higher than omniauth @ 0.6.1

I looked for a version of your github_api gem with oauth2 @ 0.6.0 or greater and it looks like it went from 0.5.2 to 0.7

If this is going to break stuff, I will just move to a different github gem as I am not the kind that only thinks of him/herself!

Thanks!!

Lack of thread safety

While I truly like the way this gem is put together it lacks completely when it comes to security. Github.api_client = instance is and will cause all kinds of trouble if used in a multi threaded application.

All of a sudden users will end up with other peoples tasks so I strongly suggest it either gets fixed or people are warned about it.

Upload fails: Segmentation fault using Ruby 1.9

I am running Ruby 1.9.3p194 (installed with homebrew). When I want to upload a file to a github repository it fails and I get http://pastebin.com/tDkVVUqy as an output.

I am using github_api from your git repository so it's the latest and greatest :)

My code looks like this

github = Github.new :user => $github_username, :repo => $name, :login => $github_username, :password => $github_password
  file = $name + os + ".tar.gz"
  now = File.mtime(file)
  name = $name + os + '-' + now.strftime("%Y-%m-%d-%H-%M-%S") + '.tar.gz'
  size = File.size(file)
  description = 'Release from ' + now.strftime("%Y-%m-%d %H:%M:%S")
  res = github.repos.downloads.create $github_username, $name,
    "name" => name,
    "size" => size,
    "description" => description,
    "content_type" => "application/x-gzip"
  github.repos.downloads.upload res, file

"Problems parsing JSON" everywhere

after trying, reading, trying, reading, i still don't get it:

gh = Github.new oauth_token: "xxx"
gh.issues.create "the-user", "the-repo", {title: "bar"}

github_api 0.6.2 throws the following at me (with DEBUG=1):

EXECUTED: post - /repos/jamii-gmbh/vipcall-rails/issues with {"title"=>:foo} and {}
OPTIONS:{:headers=>{"Accept"=>"application/vnd.github.v3.raw+json,application/vnd.github.beta.raw+json;q=0.5,application/json;q=0.1", "Accept-Charset"=>"utf-8", "User-Agent"=>"Github Ruby Gem 0.6.2", "Content-Type"=>"application/x-www-form-urlencoded"}, :ssl=>{:verify=>false}, :url=>"https://api.github.com"}
post https://api.github.com/repos/jamii-gmbh/vipcall-rails/issues
Accept: "application/vnd.github.v3.raw+json,application/vnd.github.beta.raw+json;q=0.5,application/json;q=0.1"
Accept-Charset: "utf-8"
User-Agent: "Github Ruby Gem 0.6.2"
Content-Type: "application/x-www-form-urlencoded"
Github::Error::BadRequest: POST https://api.github.com/repos/jamii-gmbh/vipcall-rails/issues?access_token=cedd227dac35bfef863928d3f91aedab37b40cb6: 400 {"message":"Problems parsing JSON"}

if i do the same via curl, it just works.

Problems doing file uploads

Hi,

it seems as if the file reader for the multi-part post in Github::Repos::Downloads#upload isn't hooked up correctly.

      'file'                  => prepend_at_for(filename.to_s)
[..]
  def prepend_at_for(file)
    /^@.*/ =~ file ? '@' + file : file
  end

This will never prepend an @ unless it already exists for the filename. And @ doesn't seem to be the right way to instruct Farady to stream file content during a request anyhow.

When replacing this with

      'file'                  => Faraday::UploadIO.new(filename, 'application/octet-stream')

the Faraday object gets mangled in Github::Request#request:

      request.body = MultiJson.encode(_process_params(params)) unless params.empty?

next to the fact that S3 doesn't want it's values as JSON in the first place: http://developer.github.com/v3/repos/downloads/#create-a-new-download-part-2-upload-file-to-s3

After changing this to:

      request.body = _process_params(params) unless params.empty?

I'm getting a

undefined method `instance_values' for #<File:0x000000013365c0>

and this is where I'm stopping since my Ruby-fu only takes me so far.

Pagination: per_page = -1 ?

I'm trying to use the pagination support (great, job!) but the per_page parameter is somehow getting set to -1 whenever I use next_page

Here is an example:

repos = Github.new(oauth_token: 'XXXX').repos.watched
repos.has_next_page? #true
repos.next_page #results in...
Github::ResourceNotFound: GET https://api.github.com/users/JackCA/watched?access_token=XXXXXXX&page=2&per_page=-1: 404{"message":"Not Found"}
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/github_api-0.4.0/lib/github_api/response/raise_error.rb:18:in `on_complete'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/response.rb:9:in `block in call'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/response.rb:62:in `on_complete'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/response.rb:8:in `call'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/response.rb:8:in `call'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/response.rb:8:in `call'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/response.rb:8:in `call'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/github_api-0.4.0/lib/github_api/request/oauth2.rb:24:in `call'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/response.rb:8:in `call'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/response/logger.rb:20:in `call'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/request/url_encoded.rb:14:in `call'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/request/multipart.rb:13:in `call'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/request/json.rb:32:in `call'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/connection.rb:207:in `run_request'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/connection.rb:89:in `get'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/github_api-0.4.0/lib/github_api/request.rb:46:in `request'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/github_api-0.4.0/lib/github_api/request.rb:19:in `get'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/github_api-0.4.0/lib/github_api/paged_request.rb:30:in `page_request'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/github_api-0.4.0/lib/github_api/page_iterator.rb:41:in `next'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/github_api-0.4.0/lib/github_api/result.rb:68:in `next_page'
    from (irb):181
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
    from /Users/Jack/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'

RDocs broken

When I go to the RDocs page, I get:

Oops,
We Couldn't Find That Github Project

We haven't generated any docs for peter-murach/github. You can add the project yourself by entering the Github project information below. You can also see a list of available projects here.

MultiJson::DecodeError

Hi.

I don't know if I'm doing something wrong, but this code:

github = Github.new :client_id => CLIENT_ID, :client_secret => CLIENT_SECRET
address = github.authorize_url :redirect_uri => 'http://localhost', :scope => 'public_repo'
github.get_request(address)

generate this error in console:

/home/smefju/.gem/ruby/1.9.1/gems/json-1.7.5/lib/json/common.rb:155:in `parse': 
757: unexpected token at '<html><body>You are being <a href="https://github.com/
login?return_to=%2Flogin%2Foauth%2Fauthorize%3Fclient_id%3Da447952fb277157c4528%
26redirect_uri%3Dhttp%253A%252F%252Flocalhost%26response_type%3Dcode%26scope%3Dp
ublic_repo">redirected</a>.</body></html>' (MultiJson::DecodeError)
        from /home/smefju/.gem/ruby/1.9.1/gems/json-1.7.5/lib/json/common.rb:155
:in `parse'
        from /home/smefju/.gem/ruby/1.9.1/gems/multi_json-1.3.6/lib/multi_json/a
dapters/json_common.rb:7:in `load'
        from /home/smefju/.gem/ruby/1.9.1/gems/multi_json-1.3.6/lib/multi_json.r
b:93:in `load'
        from /home/smefju/.gem/ruby/1.9.1/gems/github_api-0.7.2/lib/github_api/j
sonable.rb:11:in `decode'
        from /home/smefju/.gem/ruby/1.9.1/gems/github_api-0.7.2/lib/github_api/r
esponse/jsonize.rb:13:in `block in <class:Jsonize>'
        from /home/smefju/.gem/ruby/1.9.1/gems/github_api-0.7.2/lib/github_api/r
esponse/jsonize.rb:25:in `call'
        from /home/smefju/.gem/ruby/1.9.1/gems/github_api-0.7.2/lib/github_api/r
esponse/jsonize.rb:25:in `parse'
        from /home/smefju/.gem/ruby/1.9.1/gems/faraday-0.8.4/lib/faraday/respons
e.rb:17:in `on_complete'
        from /home/smefju/.gem/ruby/1.9.1/gems/faraday-0.8.4/lib/faraday/respons
e.rb:9:in `block in call'
        from /home/smefju/.gem/ruby/1.9.1/gems/faraday-0.8.4/lib/faraday/respons
e.rb:63:in `on_complete'
        from /home/smefju/.gem/ruby/1.9.1/gems/faraday-0.8.4/lib/faraday/respons
e.rb:8:in `call'
        from /home/smefju/.gem/ruby/1.9.1/gems/faraday-0.8.4/lib/faraday/respons
e.rb:8:in `call'
        from /home/smefju/.gem/ruby/1.9.1/gems/faraday-0.8.4/lib/faraday/respons
e.rb:8:in `call'
        from /home/smefju/.gem/ruby/1.9.1/gems/faraday-0.8.4/lib/faraday/request
/url_encoded.rb:14:in `call'
        from /home/smefju/.gem/ruby/1.9.1/gems/faraday-0.8.4/lib/faraday/request
/multipart.rb:13:in `call'
        from /home/smefju/.gem/ruby/1.9.1/gems/github_api-0.7.2/lib/github_api/r
equest/jsonize.rb:18:in `call'
        from /home/smefju/.gem/ruby/1.9.1/gems/faraday-0.8.4/lib/faraday/connect
ion.rb:226:in `run_request'
        from /home/smefju/.gem/ruby/1.9.1/gems/faraday-0.8.4/lib/faraday/connect
ion.rb:87:in `get'
        from /home/smefju/.gem/ruby/1.9.1/gems/github_api-0.7.2/lib/github_api/r
equest.rb:41:in `request'
        from /home/smefju/.gem/ruby/1.9.1/gems/github_api-0.7.2/lib/github_api/r
equest.rb:11:in `get_request'
        from ./last_commit.rb:121:in `<main>'

I try this code on two independent machines and on both i get error. Is it problem with my code or bug in Gem?

Parameter mismatch when listing issues with 'since' parameter

I'm new to Ruby so my apologies if I'm missing something.

When listing issues for a repository, passing an ISO 8601 date/time for the 'since' parameter such as 2012-05-18T15:38:32Z shows the following:

'String does not match the parameter value.'

Teams is not working.

Been trying to figure this out, since the docs say one thing, and the API says another.

Per API Docs, it looks like the request should be made against the teams' id value, not the name.

I think it's here: https://github.com/peter-murach/github/blob/master/lib/github_api/orgs/teams.rb#L40
where team_name should be the team's ID.

I suspect that the other methods in teams.rb are not working similarilty due to team_name.

Unless I'm completely wrong? It doesn't look like any translation of the team_name to id is done.

Passing user and repo to methods even when API was instantiated with it

Hi,
I like following example very much:

issues = Github::Issues.new user: 'peter-murach', repo: 'github-api'
issues.milestones.list state: 'open', sort: 'due_date', direction: 'asc'

My use case is instantiate api for one user/repo and then call methods on it.
This use case was done by passing nil as user and repo (but would be nicer to pass just hash with options), but in recent version this does not work anymore.

To make it work I have to do:

api = Github::Issues.new user: 'mikz', repo: 'october'
api.milestones.list api.user, api.repo, state: 'open' # ...

Do you plan to support passing user and repo as default in the future or the feature was killed entirely?

Mac OS X Lion Installation Error

I installed github_api gem using the procedure given below. Now when I start irb I get the following error. I am also not able to uninstall the gem. Gem version = 1.3.6

...
--------------------------------------------------------------------------------
Thank you for installing github_api-0.5.1.

*NOTE*: Version 0.5.0 introduces breaking changes to the way github api is queried.
The interface has been rewritten to be more consistent with REST verbs that
interact with GitHub hypermedia resources. Thus, to list resources 'list' or 'all'
verbs are used, to retrieve individual resource 'get' or 'find' verbs are used.
Other CRUDE operations on all resources use preditable verbs as well, such as
'create', 'delete' etc...

Again sorry for the inconvenience but I trust that this will help in easier access to
the GitHub API and library .

For more information: http://rubydoc.info/github/peter-murach/github/master/frames

--------------------------------------------------------------------------------
 \ }
  s.require_paths = ["lib"]
  s.rubygems_version = %q{1.3.6}
  s.summary = %q{Ruby wrapper for the GitHub API v3}

  if s.respond_to? :specification_version then
    current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
    s.specification_version = 3

    if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
      s.add_runtime_dependency(%q<hashie>, ["~> 1.2.0"])
      s.add_runtime_dependency(%q<faraday>, ["~> 0.7.6"])
      s.add_runtime_dependency(%q<multi_json>, ["~> 1.3"])
      s.add_runtime_dependency(%q<oauth2>, ["~> 0.5.2"])
      s.add_runtime_dependency(%q<nokogiri>, ["~> 1.5.2"])
      s.add_development_dependency(%q<rspec>, [">= 0"])
      s.add_development_dependency(%q<cucumber>, [">= 0"])
      s.add_development_dependency(%q<yajl-ruby>, ["~> 1.1.0"])
      s.add_development_dependency(%q<webmock>, ["~> 1.8.0"])
      s.add_development_dependency(%q<vcr>, ["~> 2.1.0"])
      s.add_development_dependency(%q<simplecov>, ["~> 0.6.1"])
      s.add_development_dependency(%q<guard>, ["~> 0.8.8"])
      s.add_development_dependency(%q<guard-rspec>, ["#<YAML::Syck::DefaultKey:0x10d3b90a8> 0.5.7"])
      s.add_development_dependency(%q<guard-cucumber>, ["#<YAML::Syck::DefaultKey:0x10d3b78e8> 0.7.4"])
      s.add_development_dependency(%q<rake>, [">= 0"])
      s.add_development_dependency(%q<bundler>, [">= 0"])
    else
      s.add_dependency(%q<hashie>, ["~> 1.2.0"])
      s.add_dependency(%q<faraday>, ["~> 0.7.6"])
      s.add_dependency(%q<multi_json>, ["~> 1.3"])
      s.add_dependency(%q<oauth2>, ["~> 0.5.2"])
      s.add_dependency(%q<nokogiri>, ["~> 1.5.2"])
      s.add_dependency(%q<rspec>, [">= 0"])
      s.add_dependency(%q<cucumber>, [">= 0"])
      s.add_dependency(%q<yajl-ruby>, ["~> 1.1.0"])
      s.add_dependency(%q<webmock>, ["~> 1.8.0"])
      s.add_dependency(%q<vcr>, ["~> 2.1.0"])
      s.add_dependency(%q<simplecov>, ["~> 0.6.1"])
      s.add_dependency(%q<guard>, ["~> 0.8.8"])
      s.add_dependency(%q<guard-rspec>, ["#<YAML::Syck::DefaultKey:0x10d3b90a8> 0.5.7"])
      s.add_dependency(%q<guard-cucumber>, ["#<YAML::Syck::DefaultKey:0x10d3b78e8> 0.7.4"])
      s.add_dependency(%q<rake>, [">= 0"])
      s.add_dependency(%q<bundler>, [">= 0"])
    end
  else
    s.add_dependency(%q<hashie>, ["~> 1.2.0"])
    s.add_dependency(%q<faraday>, ["~> 0.7.6"])
    s.add_dependency(%q<multi_json>, ["~> 1.3"])
    s.add_dependency(%q<oauth2>, ["~> 0.5.2"])
    s.add_dependency(%q<nokogiri>, ["~> 1.5.2"])
    s.add_dependency(%q<rspec>, [">= 0"])
    s.add_dependency(%q<cucumber>, [">= 0"])
    s.add_dependency(%q<yajl-ruby>, ["~> 1.1.0"])
    s.add_dependency(%q<webmock>, ["~> 1.8.0"])
    s.add_dependency(%q<vcr>, ["~> 2.1.0"])
    s.add_dependency(%q<simplecov>, ["~> 0.6.1"])
    s.add_dependency(%q<guard>, ["~> 0.8.8"])
    s.add_dependency(%q<guard-rspec>, ["#<YAML::Syck::DefaultKey:0x10d3b90a8> 0.5.7"])
    s.add_dependency(%q<guard-cucumber>, ["#<YAML::Syck::DefaultKey:0x10d3b78e8> 0.7.4"])
    s.add_dependency(%q<rake>, [">= 0"])
    s.add_dependency(%q<bundler>, [">= 0"])
  end
end
WARNING:  Invalid .gemspec format in '/Library/Ruby/Gems/1.8/specifications/github_api-0.5.1.gemspec'

After updating my gem version this issue gets resolved.

Test dependency

There are weird test suite dependencies. Running specs in their default order makes them pass, however if rspec order rand option is used some test fail randomly with 'can't convert String into Hash' message. This is exactly the same error/behaviour as can be seen in Travis CI console output/log. Not sure what is causing this?

Pagination: per_page = nil?

Well, I'm back... Looks like my per_page parameter isn't carrying through to the request:

repos = Github.new(oauth_token: 'XXXX').repos(per_page: 100).watched
Produces a lonely:
get https://api.github.com/users/JackCA/watched

On another note, ๐Ÿ‘

Pagination broken for Commits?

Hi Peter,

This is a great gem -- nice work. I've run into one issue with the pagination: It seems to work fine when I use it for e.g. listing repositories for a user, but when trying to retrieve commits it doesn't seem to be working properly.

> api = Github.new(:oauth_token => '....')
> commits = api.repos.commits('ledbettj', 'cnote', :per_page => 30)
> commits[0].sha
    "b05792d6f414006d3944d547829e760d3e3f1cb9"
> commits.has_next_page?
    true
> commits = commits.next_page
> commits[0].sha
    "b05792d6f414006d3944d547829e760d3e3f1cb9"

From the debug output, It looks like it is always requesting page 1: get https://api.github.com/repos/ledbettj/cnote/commits?page=1&per_page=30

Let me know if you need any additional info!

Pagination changed to 25 by default

In the last few days, it seems github changed their default per page to 25.

See this example: curl "https://api.github.com/repos/rails/rails/issues"

I have contacted github support about the issue and also submitted a patch the docs: github/developer.github.com#158 (comment)

I have started a patch to fix github_api gem, but I am hoping that github will just revert it back to 30 items per page. I'll see if I get a response from them before submitting a pull request

Can not use with omniauth

Hi,

This gem looks brilliant but I am unable to install due to this

In Gemfile:
    github_api (>= 0) ruby depends on
      oauth2 (~> 0.5.0) ruby

    omniauth-github (>= 0) ruby depends on
      oauth2 (0.6.1)

Remove post-install message

First things first, thanks for github_api :)

Now to the beef: It's redundant. Personally I think those should be used for things that need the users attention.

Authenticated session is occasionally lost

I have an app that's authenticating with oauth that displays private repos. Most of the time it works fine. Under certain circumstances (which I haven't been able to pinpoint), the oauth session fails and I can only retrieve public repos. The user and oauth token are the same. It's basically the case of "See private repos", refresh, "Don't see private repos". I can get the oauth connection working again by restarting the server in development mode, so I'm fairly certain it's not something I'm doing wrong.

Looking through the gem code isn't leading me in any particular direction, and the logging on Faraday doesn't seem to show me anything Oauth related (working or not).

Ideas?

Pagination support

Whats the plan for adding pagination support? I cannot seem to figure out how to use the link attribute with faraday.

OpenSSL issues on Mountain Lion...

FYI, enabling SSL validation has the unfortunate side-effect of breaking if the user has a properly installed OpenSSL that happens to not have a database of root certificates pre-installed. The default install on OSX traditionally has preinstalled root certs, but OpenSSL doesn't include them by default. You may want to include the root cert for Github and explicitly set the ca_file option to ensure that things work consistently, everywhere.

problem with repos

hi guys I have a really wierd problem, I have integrated the github_api to my rails app, so when I want get the total repositories sometimes return ok and sometime return less, in the moment that it was returning less I put a debbuger so I get this

(rdb:11) g = Github.new :oauth_token => "..."
#<Github::Client:0x007fd3bfe6b460 @adapter=:net_http, @client_id=nil, @client_secret=nil, @oauth_token="...", @endpoint="https://api.github.com", @mime_type=:json, @user_agent="Github Ruby Gem 0.6.3", @connection_options={}, @repo="...", @user="...", @login=nil, @password=nil, @basic_auth=nil>
(rdb:11) g.repos.list.count
2

at the same time I run the code irb console and I get ok

irb(main):001:0> require "rubygems"
=> false
irb(main):002:0> require "github_api"
=> true
irb(main):003:0> github = Github.new :oauth_token => "..."
=> #<Github::Client:0x007fbe031583f8 @adapter=:net_http, @client_id=nil, @client_secret=nil, @oauth_token="...", @endpoint="https://api.github.com", @mime_type=:json, @user_agent="Github Ruby Gem 0.6.3", @connection_options={}, @repo=nil, @user=nil, @login=nil, @password=nil, @basic_auth=nil>
irb(main):004:0> github.repos.list.count
=> 19

it has a kind of cache or something like this in rails?

thanks

Incorrect ArgumentError thrown for GitData::References

A branch in one of my repos has a name that contains 'ref' (inside the word 'refactor'). When trying to get git data about this repo, the gem throws an ArgumentError, telling me that the "Provided 'reference' is invalid". However, the reference is perfectly valid, and the request works fine when querying GitHub's API directly.

I believe this error arises because Github::GitData::References.validate_reference on line 134 checks for the fragment 'ref' in the passed-in string. Since the string (e.g. "heads/lleger-refactor") contains 'ref', index returns truthfully, which sets refs to "heads/lleger-refactor". The regex then checks against that string, and it fails because the regex expects it to contain 'ref/', which it does not, thus throwing the ArgumentError.

If I pass in "refs/heads/lleger-refactor" into ref, the validation passes, but the URL is malformed since it contains an extra "refs/".

Changing line 134 to the following seems to fix the issue for me:

refs = ref.index('ref/') ? ref : "refs/#{ref}"

checking if a branch has merged another

I'm trying to come up with a query that will check many branches, 'i' to see if they contain all the commits of branch 'A'. I wanted to see if 'i' contained the lastest commit 'A', but I can only see the latest commit when looking at branches by "github.repos.branches". Is there another way to check for something like this, perhaps with something beside commits, or is this a feature that could be added to this gem? (disclaimer: I am fairly new to git despite having this account for a while)

GitHub::GitData#create_tree seems not to work

This is not working:

github = Github.new(oauth_token: "XXXX")
user = github.users.get_user
sha = github.git_data.create_blob user.login, 'test', "content" => Base64.encode64(params[:content][:blob_content][:value]), "encoding" => "base64"
tree = github.git_data.create_tree user.login, 'test',
"tree" => [
           {
             "path" => params[:path],
             "mode" => "100644",
             "type" => "blob",
             "sha" => sha.sha
           }
          ]

I get this:

post https://api.github.com/repos/reedlaw/test/git/trees
Accept: "*/*"
User-Agent: "Github Ruby Gem 0.3.6"
Content-Type: "application/x-www-form-urlencoded"
Github::ResourceNotFound Exception: POST https://api.github.com/repos/reedlaw/test/git/trees?access_token=XXXX: 404{"message":"Not Found"}

But it works fine with curl:

$ curl -d '{"tree":[{"path":"test.txt","mode":"040000","type":"tree","content":"testing"}]' -H "Authorization: token XXXX" https://api.github.com/repos/reedlaw/test/git/trees
{
  "tree": [
    {
      "type": "blob",
      "sha": "9a2c7732fab5bcd73ea3ed52d2d9599a4cc47666",
      "size": 7,
      "url": "https://api.github.com/repos/reedlaw/test/git/blobs/9a2c7732fab5bcd73ea3ed52d2d9599a4cc47666",
      "path": "test.txt",
      "mode": "100644"
    }
  ],
  "sha": "df141fba3a315257afbdcac13406ef049106d9bb",
  "url": "https://api.github.com/repos/reedlaw/test/git/trees/df141fba3a315257afbdcac13406ef049106d9bb"
}

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.