Giter VIP home page Giter VIP logo

octokit.rb's Introduction

Octokit

Note We've recently renamed the 4-stable branch to main. This might affect you if you're making changes to Octokit's code locally. For more details and for the steps to reconfigure your local clone for the new branch name, check out this post.

Ruby toolkit for the GitHub API.

logo

Upgrading? Check the Upgrade Guide before bumping to a new major version.

Table of Contents

  1. Philosophy
  2. Installation
  3. Making requests
    1. Additional Query Parameters
  4. Consuming resources
  5. Accessing HTTP responses
  6. Handling errors
  7. Authentication
    1. Basic Authentication
    2. OAuth access tokens
    3. Two-Factor Authentication
    4. Using a .netrc file
    5. Application authentication
    6. GitHub App
  8. Default results per_page
  9. Pagination
    1. Auto pagination
  10. Working with GitHub Enterprise
  11. Interacting with the GitHub.com APIs in GitHub Enterprise
  12. Interacting with the GitHub Enterprise Admin APIs
  13. Interacting with the GitHub Enterprise Management Console APIs
  14. SSL Connection Errors
  15. Configuration and defaults
    1. Configuring module defaults
    2. Using ENV variables
    3. Timeouts
  16. Hypermedia agent
    1. Hypermedia in Octokit
    2. URI templates
    3. The Full Hypermedia Experience™
  17. Upgrading guide
    1. Upgrading from 1.x.x
  18. Advanced usage
    1. Debugging
    2. Caching
  19. Hacking on Octokit.rb
    1. Code of Conduct
    2. Running and writing new tests
  20. Supported Ruby Versions
  21. Versioning
  22. Making Repeating Requests
  23. License

Philosophy

API wrappers should reflect the idioms of the language in which they were written. Octokit.rb wraps the GitHub API in a flat API client that follows Ruby conventions and requires little knowledge of REST. Most methods have positional arguments for required input and an options hash for optional parameters, headers, or other options:

client = Octokit::Client.new

# Fetch a README with Accept header for HTML format
client.readme 'al3x/sovereign', :accept => 'application/vnd.github.html'

Installation

Install via Rubygems

gem install octokit

... or add to your Gemfile

gem "octokit"

Access the library in Ruby:

require 'octokit'

Making requests

API methods are available as client instance methods.

# Provide authentication credentials
client = Octokit::Client.new(:access_token => 'personal_access_token')

# You can still use the username/password syntax by replacing the password value with your PAT.
# client = Octokit::Client.new(:login => 'defunkt', :password => 'personal_access_token')

# Fetch the current user
client.user

Additional query parameters

When passing additional parameters to GET based request use the following syntax:

 # query: { parameter_name: 'value' }
 # Example: Get repository listing by owner in ascending order
 client.repos({}, query: {type: 'owner', sort: 'asc'})

 # Example: Get contents of a repository by ref
 # https://api.github.com/repos/octokit/octokit.rb/contents/path/to/file.rb?ref=some-other-branch
 client.contents('octokit/octokit.rb', path: 'path/to/file.rb', query: {ref: 'some-other-branch'})

Consuming resources

Most methods return a Resource object which provides dot notation and [] access for fields returned in the API response.

client = Octokit::Client.new

# Fetch a user
user = client.user 'jbarnette'
puts user.name
# => "John Barnette"
puts user.fields
# => <Set: {:login, :id, :gravatar_id, :type, :name, :company, :blog, :location, :email, :hireable, :bio, :public_repos, :followers, :following, :created_at, :updated_at, :public_gists}>
puts user[:company]
# => "GitHub"
user.rels[:gists].href
# => "https://api.github.com/users/jbarnette/gists"

Note: URL fields are culled into a separate .rels collection for easier Hypermedia support.

Accessing HTTP responses

While most methods return a Resource object or a Boolean, sometimes you may need access to the raw HTTP response headers. You can access the last HTTP response with Client#last_response:

user      = client.user 'andrewpthorp'
response  = client.last_response
etag      = response.headers[:etag]

Handling errors

When the API returns an error response, Octokit will raise a Ruby exception.

A range of different exceptions can be raised depending on the error returned by the API - for example:

  • A 400 Bad Request response will lead to an Octokit::BadRequest error
  • A 403 Forbidden error with a "rate limited exceeded" message will lead to a Octokit::TooManyRequests error

All of the different exception classes inherit from Octokit::Error and expose the #response_status, #response_headers and #response_body. For validation errors, #errors will return an Array of Hashes with the detailed information returned by the API.

Authentication

Octokit supports the various authentication methods supported by the GitHub API:

Basic Authentication

Using your GitHub username and password is the easiest way to get started making authenticated requests:

client = Octokit::Client.new(:login => 'defunkt', :password => 'c0d3b4ssssss!')

user = client.user
user.login
# => "defunkt"

While Basic Authentication allows you to get started quickly, OAuth access tokens are the preferred way to authenticate on behalf of users.

OAuth access tokens

OAuth access tokens provide two main benefits over using your username and password:

  • Revocable access. Access tokens can be revoked, removing access for only that token without having to change your password everywhere.
  • Limited access. Access tokens have access scopes which allow for more granular access to API resources. For instance, you can grant a third party access to your gists but not your private repositories.

To use an access token with the Octokit client, pass your token in the :access_token options parameter in lieu of your username and password:

client = Octokit::Client.new(:access_token => "<your 40 char token>")

user = client.user
user.login
# => "defunkt"

You can create access tokens through your GitHub Account Settings.

Two-Factor Authentication

Two-Factor Authentication brings added security to the account by requiring more information to login.

Using two-factor authentication for API calls is as simple as adding the required header as an option:

client = Octokit::Client.new \
  :login    => 'defunkt',
  :password => 'c0d3b4ssssss!'

user = client.user("defunkt", :headers => { "X-GitHub-OTP" => "<your 2FA token>" })

Using a .netrc file

Octokit supports reading credentials from a netrc file (defaulting to ~/.netrc). Given these lines in your netrc:

machine api.github.com
  login defunkt
  password c0d3b4ssssss!

You can now create a client with those credentials:

client = Octokit::Client.new(:netrc => true)
client.login
# => "defunkt"

But I want to use OAuth you say. Since the GitHub API supports using an OAuth token as a Basic password, you totally can:

machine api.github.com
  login defunkt
  password <your 40 char token>

Note: Support for netrc requires adding the netrc gem to your Gemfile or .gemspec.

Application authentication

Octokit also supports application-only authentication using OAuth application client credentials. Using application credentials will result in making anonymous API calls on behalf of an application in order to take advantage of the higher rate limit.

client = Octokit::Client.new \
  :client_id     => "<your 20 char id>",
  :client_secret => "<your 40 char secret>"

user = client.user 'defunkt'

GitHub App

Octokit.rb also supports authentication using a GitHub App, which requires a generated JWT token.

client = Octokit::Client.new(:bearer_token => "<your jwt token>")
client.app
# => about GitHub App info

Default results per_page

Default results from the GitHub API are 30, if you wish to add more you must do so during Octokit configuration.

Octokit::Client.new(access_token: "<your 40 char token>", per_page: 100)

Pagination

Many GitHub API resources are paginated. While you may be tempted to start adding :page parameters to your calls, the API returns links to the next, previous, and last pages for you in the Link response header as Hypermedia link relations.

issues = client.issues 'rails/rails'
issues.concat client.get(client.last_response.rels[:next].href)

Auto pagination

For smallish resource lists, Octokit provides auto pagination. When this is enabled, calls for paginated resources will fetch and concatenate the results from every page into a single array:

client.auto_paginate = true
issues = client.issues 'rails/rails'
issues.length

# => 702

You can also enable auto pagination for all Octokit client instances:

Octokit.configure do |c|
  c.auto_paginate = true
end

Note: While Octokit auto pagination will set the page size to the maximum 100, and seek to not overstep your rate limit, you probably want to use a custom pattern for traversing large lists.

Working with GitHub Enterprise

With a bit of setup, you can also use Octokit with your GitHub Enterprise instance.

Interacting with the GitHub.com APIs in GitHub Enterprise

To interact with the "regular" GitHub.com APIs in GitHub Enterprise, simply configure the api_endpoint to match your hostname. For example:

Octokit.configure do |c|
  c.api_endpoint = "https://<hostname>/api/v3/"
end

client = Octokit::Client.new(:access_token => "<your 40 char token>")

Interacting with the GitHub Enterprise Admin APIs

The GitHub Enterprise Admin APIs are under a different client: EnterpriseAdminClient. You'll need to have an administrator account in order to use these APIs.

admin_client = Octokit::EnterpriseAdminClient.new(
  :access_token => "<your 40 char token>",
  :api_endpoint => "https://<hostname>/api/v3/"
)

# or
Octokit.configure do |c|
  c.api_endpoint = "https://<hostname>/api/v3/"
  c.access_token = "<your 40 char token>"
end

admin_client = Octokit.enterprise_admin_client.new

Interacting with the GitHub Enterprise Management Console APIs

The GitHub Enterprise Management Console APIs are also under a separate client: EnterpriseManagementConsoleClient. In order to use it, you'll need to provide both your management console password as well as the endpoint to your management console. This is different from the API endpoint provided above.

management_console_client = Octokit::EnterpriseManagementConsoleClient.new(
  :management_console_password => "secret",
  :management_console_endpoint = "https://hostname:8633"
)

# or
Octokit.configure do |c|
  c.management_console_endpoint = "https://hostname:8633"
  c.management_console_password = "secret"
end

management_console_client = Octokit.enterprise_management_console_client.new

SSL Connection Errors

You may need to disable SSL temporarily while first setting up your GitHub Enterprise install. You can do that with the following configuration:

client.connection_options[:ssl] = { :verify => false }

Do remember to turn :verify back to true, as it's important for secure communication.

Configuration and defaults

While Octokit::Client accepts a range of options when creating a new client instance, Octokit's configuration API allows you to set your configuration options at the module level. This is particularly handy if you're creating a number of client instances based on some shared defaults. Changing options affects new instances only and will not modify existing Octokit::Client instances created with previous options.

Configuring module defaults

Every writable attribute in {Octokit::Configurable} can be set one at a time:

Octokit.api_endpoint = 'http://api.github.dev'
Octokit.web_endpoint = 'http://github.dev'

or in batch:

Octokit.configure do |c|
  c.api_endpoint = 'http://api.github.dev'
  c.web_endpoint = 'http://github.dev'
end

Using ENV variables

Default configuration values are specified in {Octokit::Default}. Many attributes will look for a default value from the ENV before returning Octokit's default.

# Given $OCTOKIT_API_ENDPOINT is "http://api.github.dev"
client.api_endpoint

# => "http://api.github.dev"

Deprecation warnings and API endpoints in development preview warnings are printed to STDOUT by default, these can be disabled by setting the ENV OCTOKIT_SILENT=true.

Timeouts

By default, Octokit does not timeout network requests. To set a timeout, pass in Faraday timeout settings to Octokit's connection_options setting.

Octokit.configure do |c|
  c.api_endpoint = ENV.fetch('GITHUB_API_ENDPOINT', 'https://api.github.com/')
  c.connection_options = {
    request: {
      open_timeout: 5,
      timeout: 5
    }
  }
end

You should set a timeout in order to avoid Ruby’s Timeout module, which can hose your server. Here are some resources for more information on this:

Hypermedia agent

Starting in version 2.0, Octokit is hypermedia-enabled. Under the hood, {Octokit::Client} uses Sawyer, a hypermedia client built on Faraday.

Hypermedia in Octokit

Resources returned by Octokit methods contain not only data but hypermedia link relations:

user = client.user 'technoweenie'

# Get the repos rel, returned from the API
# as repos_url in the resource
user.rels[:repos].href
# => "https://api.github.com/users/technoweenie/repos"

repos = user.rels[:repos].get.data
repos.last.name
# => "faraday-zeromq"

When processing API responses, all *_url attributes are culled into the link relations collection. Any url attribute becomes .rels[:self].

URI templates

You might notice many link relations have variable placeholders. Octokit supports URI Templates for parameterized URI expansion:

repo = client.repo 'pengwynn/pingwynn'
rel = repo.rels[:issues]
# => #<Sawyer::Relation: issues: get https://api.github.com/repos/pengwynn/pingwynn/issues{/number}>

# Get a page of issues
rel.get.data

# Get issue #2
rel.get(:uri => {:number => 2}).data

The Full Hypermedia Experience™

If you want to use Octokit as a pure hypermedia API client, you can start at the API root and follow link relations from there:

root = client.root
root.rels[:repository].get :uri => {:owner => "octokit", :repo => "octokit.rb" }
root.rels[:user_repositories].get :uri => { :user => "octokit" },
                                  :query => { :type => "owner" }

Octokit 3.0 aims to be hypermedia-driven, removing the internal URL construction currently used throughout the client.

Upgrading guide

Version 4.0

Version 3.0 includes a couple breaking changes when upgrading from v2.x.x:

The default media type is now v3 instead of beta. If you need to request the older media type, you can set the default media type for the client:

Octokit.default_media_type = "application/vnd.github.beta+json"

or per-request

client.emails(:accept => "application/vnd.github.beta+json")

The long-deprecated Octokit::Client#create_download method has been removed.

Upgrading from 1.x.x

Version 2.0 includes a completely rewritten Client factory that now memoizes client instances based on unique configuration options. Breaking changes also include:

  • :oauth_token is now :access_token
  • :auto_traversal is now :auto_paginate
  • Hashie::Mash has been removed. Responses now return a Sawyer::Resource object. This new type behaves mostly like a Ruby Hash, but does not fully support the Hashie::Mash API.
  • Two new client error types are raised where appropriate: Octokit::TooManyRequests and Octokit::TooManyLoginAttempts
  • The search_* methods from v1.x are now found at legacy_search_*
  • Support for netrc requires including the netrc gem in your Gemfile or gemspec.
  • DateTime fields are now proper DateTime objects. Previous versions outputted DateTime fields as 'String' objects.

Advanced usage

Since Octokit employs Faraday under the hood, some behavior can be extended via middleware.

Debugging

Often, it helps to know what Octokit is doing under the hood. You can add a logger to the middleware that enables you to peek into the underlying HTTP traffic:

stack = Faraday::RackBuilder.new do |builder|
  builder.use Faraday::Retry::Middleware, exceptions: Faraday::Request::Retry::DEFAULT_EXCEPTIONS + [Octokit::ServerError] # or Faraday::Request::Retry for Faraday < 2.0
  builder.use Octokit::Middleware::FollowRedirects
  builder.use Octokit::Response::RaiseError
  builder.use Octokit::Response::FeedParser
  builder.response :logger do |logger|
    logger.filter(/(Authorization: "(token|Bearer) )(\w+)/, '\1[REMOVED]')
  end
  builder.adapter Faraday.default_adapter
end
Octokit.middleware = stack

client = Octokit::Client.new
client.user 'pengwynn'
I, [2013-08-22T15:54:38.583300 #88227]  INFO -- : get https://api.github.com/users/pengwynn
D, [2013-08-22T15:54:38.583401 #88227] DEBUG -- request: Accept: "application/vnd.github.beta+json"
User-Agent: "Octokit Ruby Gem 2.0.0.rc4"
I, [2013-08-22T15:54:38.843313 #88227]  INFO -- Status: 200
D, [2013-08-22T15:54:38.843459 #88227] DEBUG -- response: server: "GitHub.com"
date: "Thu, 22 Aug 2013 20:54:40 GMT"
content-type: "application/json; charset=utf-8"
transfer-encoding: "chunked"
connection: "close"
status: "200 OK"
x-ratelimit-limit: "60"
x-ratelimit-remaining: "39"
x-ratelimit-reset: "1377205443"
...

See the Faraday README for more middleware magic.

Caching

If you want to boost performance, stretch your API rate limit, or avoid paying the hypermedia tax, you can use Faraday Http Cache.

Add the gem to your Gemfile

gem 'faraday-http-cache'

Next, construct your own Faraday middleware:

stack = Faraday::RackBuilder.new do |builder|
  builder.use Faraday::HttpCache, serializer: Marshal, shared_cache: false
  builder.use Octokit::Response::RaiseError
  builder.adapter Faraday.default_adapter
end
Octokit.middleware = stack

Once configured, the middleware will store responses in cache based on ETag fingerprint and serve those back up for future 304 responses for the same resource. See the project README for advanced usage.

Hacking on Octokit.rb

If you want to hack on Octokit locally, we try to make bootstrapping the project as painless as possible. To start hacking, clone and run:

script/bootstrap

This will install project dependencies and get you up and running. If you want to run a Ruby console to poke on Octokit, you can crank one up with:

script/console

Using the scripts in ./script instead of bundle exec rspec, bundle console, etc. ensures your dependencies are up-to-date.

Code of Conduct

We want both the Octokit.rb and larger Octokit communities to be open and welcoming environments. Please read and follow both in spirit and letter Code of Conduct.

Running and writing new tests

Octokit uses VCR for recording and playing back API fixtures during test runs. These cassettes (fixtures) are part of the Git project in the spec/cassettes folder. If you're not recording new cassettes you can run the specs with existing cassettes with:

script/test

Octokit uses environmental variables for storing credentials used in testing. If you are testing an API endpoint that doesn't require authentication, you can get away without any additional configuration. For the most part, tests use an authenticated client, using a token stored in ENV['OCTOKIT_TEST_GITHUB_TOKEN']. There are several different authentication methods used across the api. Here is the full list of configurable environmental variables for testing Octokit:

ENV Variable Description
OCTOKIT_TEST_GITHUB_LOGIN GitHub login name (preferably one created specifically for testing against).
OCTOKIT_TEST_GITHUB_PASSWORD Password for the test GitHub login.
OCTOKIT_TEST_GITHUB_TOKEN Personal Access Token for the test GitHub login.
OCTOKIT_TEST_GITHUB_CLIENT_ID Test OAuth application client id.
OCTOKIT_TEST_GITHUB_CLIENT_SECRET Test OAuth application client secret.
OCTOKIT_TEST_GITHUB_REPOSITORY Test repository to perform destructive actions against, this should not be set to any repository of importance. Automatically created by the test suite if nonexistent Default: api-sandbox
OCTOKIT_TEST_GITHUB_ORGANIZATION Test organization.
OCTOKIT_TEST_GITHUB_ENTERPRISE_LOGIN GitHub Enterprise login name.
OCTOKIT_TEST_GITHUB_ENTERPRISE_TOKEN GitHub Enterprise token.
OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD GitHub Enterprise management console password.
OCTOKIT_TEST_GITHUB_ENTERPRISE_ENDPOINT GitHub Enterprise hostname.
OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT GitHub Enterprise Management Console endpoint.
OCTOKIT_TEST_GITHUB_INTEGRATION GitHub Integration owned by your test organization.
OCTOKIT_TEST_GITHUB_INTEGRATION_INSTALLATION Installation of the GitHub Integration specified above.
OCTOKIT_TEST_INTEGRATION_PEM_KEY File path to the private key generated from your integration.

Since we periodically refresh our cassettes, please keep some points in mind when writing new specs.

  • Specs should be idempotent. The HTTP calls made during a spec should be able to be run over and over. This means deleting a known resource prior to creating it if the name has to be unique.
  • Specs should be able to be run in random order. If a spec depends on another resource as a fixture, make sure that's created in the scope of the spec and not depend on a previous spec to create the data needed.
  • Do not depend on authenticated user info. Instead of asserting actual values in resources, try to assert the existence of a key or that a response is an Array. We're testing the client, not the API.

Supported Ruby Versions

This library aims to support and is tested against the following Ruby implementations:

  • Ruby 2.7
  • Ruby 3.0
  • Ruby 3.1
  • Ruby 3.2

If something doesn't work on one of these Ruby versions, it's a bug.

This library may inadvertently work (or seem to work) on other Ruby implementations, but support will only be provided for the versions listed above.

If you would like this library to support another Ruby version, you may volunteer to be a maintainer. Being a maintainer entails making sure all tests run and pass on that implementation. When something breaks on your implementation, you will be responsible for providing patches in a timely fashion. If critical issues for a particular implementation exist at the time of a major release, support for that Ruby version may be dropped.

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that version should be immediately yanked and/or a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions. As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision. For example:

spec.add_dependency 'octokit', '~> 3.0'

The changes made between versions can be seen on the project releases page.

Making Repeating Requests

In most cases it would be best to use webhooks, but sometimes webhooks don't provide all of the information needed. In those cases where one might need to poll for progress or retry a request on failure, we designed Octopoller. Octopoller is a micro gem perfect for making repeating requests.

Octopoller.poll(timeout: 15.seconds) do
  begin
    client.request_progress # ex. request a long running job's status
  rescue Error
    :re_poll
  end
end

This is useful when making requests for a long running job's progress (ex. requesting a Source Import's progress).

License

Copyright (c) 2009-2014 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

octokit.rb's People

Contributors

andrew avatar benbalter avatar carvil avatar catsby avatar dependabot[bot] avatar gjtorikian avatar glow-mdsol avatar greysteil avatar icco avatar jasonrudolph avatar jdpace avatar joeyw avatar joshpuetz avatar jylitalo avatar kfcampbell avatar koraktor avatar laserlemon avatar lizzhale avatar luke-engle avatar mathroule avatar nickfloyd avatar pengwynn avatar raws avatar reinh avatar sferik avatar tarebyte avatar timrogers avatar willrax avatar ybiquitous avatar zqzas 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  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

octokit.rb's Issues

Add support for Milestones

V3 of the API lest you manage Milestones

Methods:

  • List Milestones for an Issue

    GET /repos/:user/:repo/milestones

  • Create a Milestone

    POST /repos/:user/:repo/milestones

  • Get a single Milestone

    GET /repos/:user/:repo/milestones/:id

  • Update a Milestone

    PATCH /repos/:user/:repo/milestones/:id

  • Delete a Milestone

    DELETE /repos/:user/:repo/milestones/:id

Documentation

Octokit.commits raises Faraday::Error::ResourceNotFound

According to lib/faraday/response/raise_error.rb this should never happen.

It happens for me with all my Rubies, all of them having Octokit 0.6.3 and Faraday 0.6.1 installed. So I made the mistake and rescue Faraday::Error::ResourceNotFound where Octokit::NotFound would be correct. One of my users gets the Octokit::NotFound instead.

I don't really get why Faraday::Error::ResourceNotFound is raised on my setup.

Paging issues

As a dev
I want to be able to page through issues
So that I can load absolutely all the issues in a Repository

bug with rails

irb(main):020:0> github_client = Octokit::Client.new login: user, :oauth_token => token
=> #<Octokit::Client:0x007f9729c0f4c8 @adapter=:net_http, @api_version=3, @api_endpoint="https://api.github.com/", @web_endpoint="https://github.com/", @login="user", @password=nil, @proxy=nil, @oauth_token="...", @user_agent="Octokit Ruby Gem 1.9.2", @auto_traversal=false, @per_page=nil>
irb(main):021:0> github_client.repositories("user").count
=> 19
irb(main):022:0>github_client.list_issues("user/repo", :state => "open").count
=> 25
irb(main):021:0> github_client.repositories("user").count
=> 2

first return 19 and after run list_issues it return 2 why??

Markdown API throws an error

I'm trying to make a context-specific call to the markdown API.

For instance, it looks to me like I should be able to replicate the example on that page with:

Octokit.markdown({:text => "Hello world github/linguist#1 **cool**, and #1!", :mode => "gfm", :context => "github/gollum"})

But I get the following error instead:

Octokit::InternalServerError: POST https://api.github.com/markdown: 500: Server Error
    from /var/lib/gems/1.9.1/gems/octokit-1.9.1/lib/faraday/response/raise_octokit_error.rb:22:in `on_complete'
    from /var/lib/gems/1.9.1/gems/faraday-0.8.0/lib/faraday/response.rb:9:in `block in call'
    from /var/lib/gems/1.9.1/gems/faraday-0.8.0/lib/faraday/response.rb:63:in `on_complete'
    from /var/lib/gems/1.9.1/gems/faraday-0.8.0/lib/faraday/response.rb:8:in `call'
    from /var/lib/gems/1.9.1/gems/faraday_middleware-0.8.8/lib/faraday_middleware/request/encode_json.rb:23:in `call'
    from /var/lib/gems/1.9.1/gems/faraday-0.8.0/lib/faraday/connection.rb:226:in `run_request'
    from /var/lib/gems/1.9.1/gems/faraday-0.8.0/lib/faraday/connection.rb:99:in `post'
    from /var/lib/gems/1.9.1/gems/octokit-1.9.1/lib/octokit/request.rb:40:in `request'
    from /var/lib/gems/1.9.1/gems/octokit-1.9.1/lib/octokit/request.rb:18:in `post'
    from /var/lib/gems/1.9.1/gems/octokit-1.9.1/lib/octokit/client/markdown.rb:17:in `markdown'
    from /var/lib/gems/1.9.1/gems/octokit-1.9.1/lib/octokit.rb:18:in `method_missing'
    from (irb):136
    from /usr/bin/irb:12:in `<main>'

Simpler calls seem to work fine for me:

irb(main):139:0> Octokit.markdown("Hello world github is **cool**")
=> "<p>Hello world github is <strong>cool</strong></p>"

Am I doing something wrong in constructing the call?

OAuth 2 token

The readme is a little unclear

"Alternately, you can authenticate with a GitHub OAuth2 token. Note: this is NOT the GitHub API token on your account page."

client = Octokit::Client.new(:login => "me", :oauth_token => "oauth2token")

Where can I generate an oauth token from github?

Do i have to create a separate app?

`concat_without_safety': can't convert Hash into String (TypeError)

I have some code to add a comment to a pull request:

comment = "blah"
number = "2"
@gh_client = Octokit::Client.new(:login => @gh_user, :token => @gh_token)
@gh_client.add_comment({:username => @gh_org, :repository => repo}, number, comment)

The pull request exists and the auth succeeds but it's returning the following error:

/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/output_safety.rb:34:in concat_without_safety': can't convert Hash into String (TypeError) from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/output_safety.rb:34:in<<'
from /usr/lib/ruby/1.8/openssl/buffering.rb:171:in do_write' from /usr/lib/ruby/1.8/openssl/buffering.rb:193:inwrite'
from /usr/lib/ruby/1.8/net/protocol.rb:177:in write0' from /usr/lib/ruby/1.8/net/protocol.rb:153:inwrite'
from /usr/lib/ruby/1.8/net/protocol.rb:168:in writing' from /usr/lib/ruby/1.8/net/protocol.rb:152:inwrite'
from /usr/lib/ruby/1.8/net/http.rb:1548:in send_request_with_body' from /usr/lib/ruby/1.8/net/http.rb:1533:inexec'
from /usr/lib/ruby/1.8/net/http.rb:1049:in request' from /usr/lib/ruby/1.8/net/http.rb:1037:inrequest'
from /usr/lib/ruby/1.8/net/http.rb:543:in start' from /usr/lib/ruby/1.8/net/http.rb:1035:inrequest'
from /usr/lib/ruby/gems/1.8/gems/faraday-0.6.0/lib/faraday/adapter/net_http.rb:50:in call' from /usr/lib/ruby/gems/1.8/gems/faraday-0.6.0/lib/faraday/response.rb:8:incall'
from /usr/lib/ruby/gems/1.8/gems/faraday-0.6.0/lib/faraday/request.rb:88:in run' from /usr/lib/ruby/gems/1.8/gems/faraday-0.6.0/lib/faraday/request.rb:28:inrun'
from /usr/lib/ruby/gems/1.8/gems/faraday-0.6.0/lib/faraday/connection.rb:170:in run_request' from /usr/lib/ruby/gems/1.8/gems/faraday-0.6.0/lib/faraday/connection.rb:69:inpost'
from /usr/lib/ruby/gems/1.8/gems/octokit-0.6.1/lib/octokit/client/request.rb:23:in send' from /usr/lib/ruby/gems/1.8/gems/octokit-0.6.1/lib/octokit/client/request.rb:23:inrequest'
from /usr/lib/ruby/gems/1.8/gems/octokit-0.6.1/lib/octokit/client/request.rb:9:in post' from /usr/lib/ruby/gems/1.8/gems/octokit-0.6.1/lib/octokit/client/issues.rb:56:inadd_comment'
from /home/james/src/ghostred/lib/ghostred.rb:101:in close_pull_request' from /home/james/src/ghostred/lib/ghostred.rb:90:inopen_redmine_ticket'
from /home/james/src/ghostred/lib/ghostred.rb:64:in get_pull_requests' from /home/james/src/ghostred/lib/ghostred.rb:55:ineach'
from /home/james/src/ghostred/lib/ghostred.rb:55:in get_pull_requests' from /home/james/src/ghostred/lib/ghostred.rb:22:inrun'
from bin/ghostred:84

Any ideas? I am bit stuck.

Thanks!

401 Not authorized when dealing with SSH Keys

Hey, I've been trying to change SSH Keys with Octokit. I have authorized the Client with an access token. Getting information about repositories works, but attempting to get a list of, update, change, delete, etc. SSH keys doesn't, and returns a 401 Not Authorized error. Similarly, trying to get information about the current user returns a 401. I have managed to do these things with this access token on this account from CURL with no errors, but Octokit errors out.

I'm running on Ruby 1.9.2, Rails 3.0.9 and Octokit 0.6.4.

Thanks for your time,

Indigo

How to stub octokit calls?

I haven't found a good way to test Octokit usage in my app. Closest I've come is this:

test = Octokit::Client.new :adapter => :test
test.user('bronson')
 => RuntimeError: no stubbed request for get /api/v2/json/user/show/bronson

Looks great so far. I just haven't figured out how to stub that request. I've tried all sorts of variations mentioned in Faraday's readme, nothing's worked.

Is there a good way to test Octokit calls in my app?

Add support for Issue Events

V3 of the API lest you manage Events on Issues or Pull Requests

  • Get Events for an Issue

    GET /repos/:user/:repo/issues/:issue_id/events

  • Get Events for a Repository

    GET /repos/:user/:repo/issues/events

  • Get a single Issue Event

    GET /repos/:user/:repo/issues/events/:id

Documentation

1.0.3 fails with uninitialized constant Faraday::Request::JSON

I couldn't figure out what exactly is broken, but it seems like one of the dependencies breaks octokit.

Gems included by the bundle:
  * addressable (2.2.7)
  * bundler (1.1.3)
  * faraday (0.8.0)
  * faraday_middleware (0.8.7)
  * hashie (1.2.0)
  * multi_json (1.3.2)
  * multipart-post (1.1.5)
  * octokit (1.0.3)
$ irb
ruby-1.8.7-p249 :001 > require 'rubygems'
 => true 
ruby-1.8.7-p249 :002 > require 'octokit'
Faraday: you may want to install system_timer for reliable timeouts
 => true 
ruby-1.8.7-p249 :003 > Octokit.user('codec')
NameError: uninitialized constant Faraday::Request::JSON
    from /Users/codec/.rvm/gems/ruby-1.8.7-p249/gems/octokit-1.0.3/lib/octokit/connection.rb:27:in `connection'
    from /Users/codec/.rvm/gems/ruby-1.8.7-p249/gems/faraday-0.8.0/lib/faraday/connection.rb:48:in `initialize'
    from /Users/codec/.rvm/gems/ruby-1.8.7-p249/gems/faraday-0.8.0/lib/faraday.rb:11:in `new'
    from /Users/codec/.rvm/gems/ruby-1.8.7-p249/gems/faraday-0.8.0/lib/faraday.rb:11:in `new'
    from /Users/codec/.rvm/gems/ruby-1.8.7-p249/gems/octokit-1.0.3/lib/octokit/connection.rb:25:in `connection'
    from /Users/codec/.rvm/gems/ruby-1.8.7-p249/gems/octokit-1.0.3/lib/octokit/request.rb:28:in `request'
    from /Users/codec/.rvm/gems/ruby-1.8.7-p249/gems/octokit-1.0.3/lib/octokit/request.rb:10:in `get'
    from /Users/codec/.rvm/gems/ruby-1.8.7-p249/gems/octokit-1.0.3/lib/octokit/client/users.rb:23:in `user'
    from /Users/codec/.rvm/gems/ruby-1.8.7-p249/gems/octokit-1.0.3/lib/octokit.rb:18:in `send'
    from /Users/codec/.rvm/gems/ruby-1.8.7-p249/gems/octokit-1.0.3/lib/octokit.rb:18:in `method_missing'
    from (irb):3
ruby-1.8.7-p249 :004 > 

"replace_all_labels" throws error

raise_octokit_error.rb:16:in on_complete': PUT https://api.github.com/repos/backlogs/redmine_backlogs/issues/619/labels: 404: Not Found (Octokit::NotFound) from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/response.rb:9:incall'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/response.rb:63:in on_complete' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/response.rb:8:incall'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday_middleware-0.8.7/lib/faraday_middleware/request/encode_json.rb:21:in call' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/connection.rb:226:inrun_request'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/connection.rb:99:in put' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.6.1/lib/octokit/request.rb:40:insend'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.6.1/lib/octokit/request.rb:40:in request' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.6.1/lib/octokit/request.rb:22:input'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.6.1/lib/octokit/client/labels.rb:138:in `replace_all_labels'

raw requests

I had a need for this and when I looked at the spec, I saw that it was pending and decided to take a stab at it: spagalloco/octokit@a828ceff

I'm not sure if this covers all cases and I wasn't able to test YAML failure, but if this looks ok, i'll submit a pull request.

Can't create a team in an organization

I'm using version 1.0.3. The code I wrote followed the spec in organizations_spec.rb:

client = Octokit::Client.new(:login => "mdumrauf", :password => "thepass");

client.create_team("sisoputnfrba", {
  :name => "team name",
  :permission => "push"
  })

The output is:

client.create_team("sisoputnfrba", {:name => "team name", :permission => "push"})
Octokit::UnprocessableEntity: POST https://api.github.com/orgs/sisoputnfrba/teams: 422: Validation Failed
    from /home/mdumrauf/.rvm/gems/ruby-1.9.2-p318/gems/octokit-1.0.3/lib/faraday/response/raise_octokit_error.rb:20:in `on_complete'
    from /home/mdumrauf/.rvm/gems/ruby-1.9.2-p318/gems/faraday-0.7.6/lib/faraday/response.rb:9:in `block in call'
    from /home/mdumrauf/.rvm/gems/ruby-1.9.2-p318/gems/faraday-0.7.6/lib/faraday/response.rb:62:in `on_complete'
    from /home/mdumrauf/.rvm/gems/ruby-1.9.2-p318/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
    from /home/mdumrauf/.rvm/gems/ruby-1.9.2-p318/gems/faraday-0.7.6/lib/faraday/request/json.rb:32:in `call'
    from /home/mdumrauf/.rvm/gems/ruby-1.9.2-p318/gems/faraday-0.7.6/lib/faraday/connection.rb:210:in `run_request'
    from /home/mdumrauf/.rvm/gems/ruby-1.9.2-p318/gems/faraday-0.7.6/lib/faraday/connection.rb:98:in `post'
    from /home/mdumrauf/.rvm/gems/ruby-1.9.2-p318/gems/octokit-1.0.3/lib/octokit/request.rb:28:in `request'
    from /home/mdumrauf/.rvm/gems/ruby-1.9.2-p318/gems/octokit-1.0.3/lib/octokit/request.rb:18:in `post'
    from /home/mdumrauf/.rvm/gems/ruby-1.9.2-p318/gems/octokit-1.0.3/lib/octokit/client/organizations.rb:47:in `create_team'
    from (irb):4
    from /home/mdumrauf/.rvm/rubies/ruby-1.9.2-p318/bin/irb:16:in `<main>'

I'm in the Owner team of the organization. I tried creating repositories with create_repo and it worked.

Parse errors in API v3 when API doesn't return anything

For methods like delete a label, the API doesn't return a body, and then we get parse errors. See: "Delete a label" docs, implemented in my labels-v3 branch, but should occur with other methods where nothing is returned.

/Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/multi_json-1.0.3/lib/multi_json/engines/yajl.rb:10:in `parse': input must be a string or IO (MultiJson::DecodeError)
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/multi_json-1.0.3/lib/multi_json/engines/yajl.rb:10:in `decode'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/multi_json-1.0.3/lib/multi_json.rb:65:in `decode'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday_middleware-0.6.3/lib/faraday/response/parse_json.rb:16:in `parse'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday-0.6.1/lib/faraday/response.rb:17:in `on_complete'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday-0.6.1/lib/faraday/response.rb:9:in `block in call'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday-0.6.1/lib/faraday/response.rb:62:in `on_complete'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday-0.6.1/lib/faraday/response.rb:8:in `call'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday-0.6.1/lib/faraday/response.rb:8:in `call'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday-0.6.1/lib/faraday/response.rb:8:in `call'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday-0.6.1/lib/faraday/request/json.rb:28:in `call'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday-0.6.1/lib/faraday/request.rb:88:in `run'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday-0.6.1/lib/faraday/request.rb:28:in `run'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday-0.6.1/lib/faraday/connection.rb:170:in `run_request'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/faraday-0.6.1/lib/faraday/connection.rb:84:in `delete'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/octokit-0.6.4/lib/octokit/request.rb:24:in `request'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/octokit-0.6.4/lib/octokit/request.rb:18:in `delete'
    from /Users/clint/Developer/.rvm/gems/ruby-1.9.2-head@octokit/gems/octokit-0.6.4/lib/octokit/client/issues.rb:153:in `remove_label'
    from demo.rb:39:in `'

A way around this is to specify calls like delete to use "raw" response, so changing line 153 to read:

delete("repos/#{Repository.new(repo)}/labels/#{URI.encode(label)}", options, 3, true, true)

doesn't trigger the error.

leading path slash in client/contents

I just spent a while debugging an issue I had with the 'contents' endpoint. https://github.com/pengwynn/octokit/blob/master/lib/octokit/client/contents.rb#L29

The leading '/' in the call to get() seems to cause the request to be sent to the web_endpoint instead of the api_endpoint. I noticed that all the methods in this file use that convention, but other files do not.

I'm happy to remove the slashes, make sure tests pass, etc. and generate a PR, but I wanted some sort of feedback this was the right thing to do first.

"Title" and "Body" should be `options` in `update_issue`, not parameters

In issues.rb the update_issue has the method signature (repo, number, title, body, options={}). According to the docs for both v2 and 3, you can post either of those to update the issue, but with the current implementation if you only wanted to update one parameter you still need to pass the same contents of the other in order to not change it.

Installing octokit barfs on Yard documentation

Using Ruby 1.9.3 p194

Output:

$ gem install octokit
Successfully installed octokit-1.0.4
1 gem installed
Installing ri documentation for octokit-1.0.4...
Building YARD (yri) index for octokit-1.0.4...
[error]: ParserSyntaxError: syntax error in `LICENSE`:(1,18): syntax error, unexpected tINTEGER, expecting $end
[error]: Stack trace:
    /Users/michael/.rvm/gems/ruby-1.9.3-p194@github/gems/yard-0.7.5/lib/yard/parser/ruby/ruby_parser.rb:517:in `on_parse_error'
    /Users/michael/.rvm/gems/ruby-1.9.3-p194@github/gems/yard-0.7.5/lib/yard/parser/ruby/ruby_parser.rb:49:in `parse'
    /Users/michael/.rvm/gems/ruby-1.9.3-p194@github/gems/yard-0.7.5/lib/yard/parser/ruby/ruby_parser.rb:49:in `parse'
    /Users/michael/.rvm/gems/ruby-1.9.3-p194@github/gems/yard-0.7.5/lib/yard/parser/ruby/ruby_parser.rb:15:in `parse'
    /Users/michael/.rvm/gems/ruby-1.9.3-p194@github/gems/yard-0.7.5/lib/yard/parser/source_parser.rb:438:in `parse'
    /Users/michael/.rvm/gems/ruby-1.9.3-p194@github/gems/yard-0.7.5/lib/yard/parser/source_parser.rb:361:in `parse_in_order'

Installing RDoc documentation for octokit-1.0.4...

May have something to do with how yard (0.7.5) is being called for the LICENSE file.

create_pull_request gets 404

I have a script like:

#!/usr/bin/env ruby

require "git"
require "octokit"

upstream = "sakaiproject"
client = Octokit::Client.new(:login => "stuartf", :password => "REDACTED")

base = "master"
git = Git.open(Dir.pwd)
ghuser = git.remote.url.slice(/:([^\/]*)/, 1)
head = "#{ghuser}:#{git.current_branch}"
title = git.current_branch
body = "https://jira.sakaiproject.org/browse/#{git.current_branch}"
project = git.remote(upstream).url.slice(/\/([^\/]*)\.git$/, 1)

client.create_pull_request("#{upstream}/#{project}", base, head, title, body)

The idea is you run git pr and it makes a pull request in upstream for the current branch with a title that is the current branch name. But when I run it I get:

/home/stuart/.rvm/gems/ruby-1.9.3-p125/gems/octokit-1.0.0/lib/faraday/response/raise_octokit_error.rb:16:in `on_complete': POST https://api.github.com/repos/sakaiproject/nakamura/pulls: 404: Not Found (Octokit::NotFound)
    from /home/stuart/.rvm/gems/ruby-1.9.3-p125/gems/faraday-0.7.6/lib/faraday/response.rb:9:in `block in call'
    from /home/stuart/.rvm/gems/ruby-1.9.3-p125/gems/faraday-0.7.6/lib/faraday/response.rb:62:in `on_complete'
    from /home/stuart/.rvm/gems/ruby-1.9.3-p125/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
    from /home/stuart/.rvm/gems/ruby-1.9.3-p125/gems/faraday-0.7.6/lib/faraday/request/json.rb:32:in `call'
    from /home/stuart/.rvm/gems/ruby-1.9.3-p125/gems/faraday-0.7.6/lib/faraday/connection.rb:210:in `run_request'
    from /home/stuart/.rvm/gems/ruby-1.9.3-p125/gems/faraday-0.7.6/lib/faraday/connection.rb:98:in `post'
    from /home/stuart/.rvm/gems/ruby-1.9.3-p125/gems/octokit-1.0.0/lib/octokit/request.rb:28:in `request'
    from /home/stuart/.rvm/gems/ruby-1.9.3-p125/gems/octokit-1.0.0/lib/octokit/request.rb:18:in `post'
    from /home/stuart/.rvm/gems/ruby-1.9.3-p125/gems/octokit-1.0.0/lib/octokit/client/pulls.rb:11:in `create_pull_request'
    from /home/stuart/bin/git-pr:17:in `<main>'

Which doesn't make sense to me because a GET to https://api.github.com/repos/sakaiproject/nakamura/pulls works fine. Am I doing something wrong or is this a bug in octokit or the github api?

client.create_issue(...) fails

Hi,
I'm trying to use Octokit to give TicGit-ng the ability to sync with Github Issues, but I've run into a problem. It appears create_issue() is broken.
I've scoured all of the documentation I can find, including the source code itself, and I can't find a usage example other than the way I'm doing it.

This is the problem:
http://pastie.org/pastes/1841681/text

Based on
http://rdoc.info/github/pengwynn/octokit/master/Octokit/Client/Issues:create_issue
it looks like I'm using the right usage but that Octokit may not be formatting something properly.

Deleting a team returns an error

When calling the delete action for teams, the team is deleted via the API but Octokit does not handle the 204 response appropriately.

Versions specified on all requests

Is there a specific reason as to why all api methods specify the version of the API to use as opposed to this being set in 1 place? If not, I'll submit a patch.

Rename Octopussy

I've brought up this issue before, but after listening to Dave Thomas's keynote at RubyConf, I feel strongly compelled to bring it up again.

If you haven't seen the talk yet, please watch it before reading any further. I promise, it will be worth your time.

My primary concern is that the name “Octopussy” may subtly discourage women from contributing to this project.

As a solution to this problem, I propose changing the name to “Octocat”.

This name has many advantages, to name a few:

  1. It retains the “octo-” prefix, so it will be recognizable to people currently using the gem
  2. It is currently available
  3. It comes with a cool mascot

I will gladly entertain a discussion of alternative names, but I do not feel comfortable continuing to work on this project as long as it is named “Octopussy”.

can't run private commands

I'm trying to create a repo programmatically and not having much luck:

o=Octokit::Client.new :login => 'mwotton', :token => token

<Octokit::Client:0xa54743c @adapter=:net_http, @endpoint="https://github.com/", @Format=:json, @login="mwotton", @password=nil, @Proxy=nil, @token="somethingelse", @oauth_token=nil, @user_agent="Octokit Ruby Gem 0.6.1", @Version=2>

o.create_repository "ffff"
NoMethodError: undefined method bytesize' for {:name=>"ffff"}:Hash from /home/mwotton/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/net/http.rb:1727:insend_request_with_body'
from /home/mwotton/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/net/http.rb:1716:in exec' from /home/mwotton/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/net/http.rb:1181:intransport_request'
from /home/mwotton/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/net/http.rb:1169:in request' from /home/mwotton/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/net/http.rb:1162:inblock in request'
from /home/mwotton/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/net/http.rb:627:in start' from /home/mwotton/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/net/http.rb:1160:inrequest'
from /home/mwotton/.rvm/gems/ruby-1.9.2-rc2/gems/faraday-0.6.1/lib/faraday/adapter/net_http.rb:51:in call' from /home/mwotton/.rvm/gems/ruby-1.9.2-rc2/gems/faraday-0.6.1/lib/faraday/response.rb:8:incall'
from /home/mwotton/.rvm/gems/ruby-1.9.2-rc2/gems/faraday-0.6.1/lib/faraday/response.rb:8:in call' from /home/mwotton/.rvm/gems/ruby-1.9.2-rc2/gems/faraday-0.6.1/lib/faraday/response.rb:8:incall'
from /home/mwotton/.rvm/gems/ruby-1.9.2-rc2/gems/faraday-0.6.1/lib/faraday/request.rb:88:in run' from /home/mwotton/.rvm/gems/ruby-1.9.2-rc2/gems/faraday-0.6.1/lib/faraday/request.rb:28:inrun'
from /home/mwotton/.rvm/gems/ruby-1.9.2-rc2/gems/faraday-0.6.1/lib/faraday/connection.rb:170:in run_request' from /home/mwotton/.rvm/gems/ruby-1.9.2-rc2/gems/faraday-0.6.1/lib/faraday/connection.rb:69:inpost'
from /home/mwotton/.rvm/gems/ruby-1.9.2-rc2/gems/octokit-0.6.1/lib/octokit/client/request.rb:23:in request' from /home/mwotton/.rvm/gems/ruby-1.9.2-rc2/gems/octokit-0.6.1/lib/octokit/client/request.rb:9:inpost'
from /home/mwotton/.rvm/gems/ruby-1.9.2-rc2/gems/octokit-0.6.1/lib/octokit/client/repositories.rb:40:in create_repository' from (irb):18 from /home/mwotton/.rvm/rubies/ruby-1.9.2-rc2/bin/irb:17:in

'>>

Am I just calling create_repo incorrectly?

GH Pages

A gh-pages for Octokit could be a nice-to-have. Thoughts?

pretty-print the json fixtures

What do you think about pretty-printing the json in the fixtures? It would add a small overhead, but if it's common for programmers using this library to pull up the fixtures, I think it would be worth it.

Add Gist support for V3

V3 of the API lest you manage Gists

  • List a user’s gists
  • List your gists
  • List public gists
  • List your starred gists
  • Get a single gist
  • Create a new gist
  • Edit a gist
  • Star a gist
  • Unstar a gist
  • Check if a gist is starred
  • Fork a gist
  • Delete a gist

Documentation

[GitHub Enterprise] Calls to custom endpoints return 404

When configuring Octokit (v 1.7.0) to hit our GitHub Enterprise call I get 404 errors on the server.

Octokit.configure do |c|
  c.api_endpoint = 'https://github.company.com/api/v3'
  c.web_endpoint = 'https://github.company.com/'
end

@client = Octokit::Client.new(login: 'USERNAME', password: 'PASSWORD')

@client.repo('USERNAME/REPO')

Outputs

Faraday::Error::ParsingError: 743: unexpected token at '<html><body>You are being <a href="https://github.company.com/login">redirected</a>.</body></html>'
#...

The GHE logs show

55.216.36.166 - USERNAME [28/Jun/2012:16:45:27 -0700] "GET /repos/USERNAME/REPO HTTP/1.1" 404 4585 "-" "Ruby"

It seems like the request is peeling off the /api/v3 portion of the path.

add_labels_to_an_issue throws an error

I've tried add_labels_to_an_issue with an array of strings and an array of labels, both yield the same error

Trace:

/home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.8.1/lib/faraday/response/raise_octokit_error.rb:10:in on_complete': POST https://api.github.com/repos/backlogs/redmine_backlogs/issues/638/labels?access_token=yadiyadiyadi: 400: Body should be a JSON Array (Octokit::BadRequest) from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/response.rb:9:incall'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/response.rb:63:in on_complete' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/response.rb:8:incall'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday_middleware-0.8.8/lib/faraday_middleware/request/encode_json.rb:23:in call' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/connection.rb:226:inrun_request'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/connection.rb:99:in post' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.8.1/lib/octokit/request.rb:40:insend'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.8.1/lib/octokit/request.rb:40:in request' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.8.1/lib/octokit/request.rb:18:inpost'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.8.1/lib/octokit/client/labels.rb:125:in `add_labels_to_an_issue'

deprecated API v2 queries

Hi,
First of all I'm now to github API and I haven't been using v2 so there's a lot of guessing in here.

For example for .blobs there's something like

warn 'DEPRECATED: Please use Octokit.tree instead.'
get("/api/v2/json/blob/all/#{Repository.new(repo)}/#{tree_sha}", options, 2)['blobs']

But API v2 was dropped completely so it fails. Maybe we could make it easier for users to switch doing something ilke:

warn 'DEPRECATED: Please use Octokit.tree instead.'
Hash[*tree(repo, tree_sha, options).tree.map {|t| [t.path, t.sha] }.flatten]

(if I understand correctly that it returned earlier hash with filename => sha). Similar thing can be done with .raw (automatically decoding from base64 if necessary), and probably for other methods so that before user updates API in his project it would still work. I'll happily create some PR but since I'm new to this gem and GH API I'm not sure yet if I'm not talking nonsense.

What do you think?

Can't use octokit with omniauth

This may just be my n00bness (and I apologize if it is), but I keep getting the following error when trying to use octokit with omniauth in a Sinatra project:

raise_if_conflicts': Unable to activate octokit-0.6.4, because addressable-2.2.4 conflicts with addressable (~> 2.2.6), faraday-0.6.1 conflicts with faraday (~> 0.7.3) (Gem::LoadError)`

Is there a way to easily fix this? I've never run into a problem like it, and would be great if I could use the two gems together.

Thank you!

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.