[DRE-commits] [ruby-octokit] 01/03: Imported Upstream version 3.7.0
Miguel Landaeta
nomadium at moszumanska.debian.org
Sun Dec 14 19:49:10 UTC 2014
This is an automated email from the git hooks/post-receive script.
nomadium pushed a commit to branch master
in repository ruby-octokit.
commit c3ad1c262081507fb11e4f47d8f37ca980db936b
Author: Miguel Landaeta <nomadium at debian.org>
Date: Sun Dec 14 16:02:55 2014 -0300
Imported Upstream version 3.7.0
---
README.md | 105 +++++++++----
checksums.yaml.gz | Bin 269 -> 0 bytes
lib/octokit/authentication.rb | 1 +
lib/octokit/client.rb | 23 +--
lib/octokit/client/commit_comments.rb | 24 +--
lib/octokit/client/commits.rb | 42 ++---
lib/octokit/client/contents.rb | 24 +--
lib/octokit/client/deployments.rb | 39 +----
lib/octokit/client/downloads.rb | 12 +-
lib/octokit/client/events.rb | 33 ++--
lib/octokit/client/gists.rb | 8 +-
lib/octokit/client/hooks.rb | 282 ++++++++++++++++++++++++++++++++++
lib/octokit/client/issues.rb | 106 ++++++++-----
lib/octokit/client/labels.rb | 44 +++---
lib/octokit/client/notifications.rb | 8 +-
lib/octokit/client/objects.rb | 24 +--
lib/octokit/client/organizations.rb | 136 ++++++++++++----
lib/octokit/client/pages.rb | 12 +-
lib/octokit/client/pull_requests.rb | 75 ++++-----
lib/octokit/client/refs.rb | 24 +--
lib/octokit/client/releases.rb | 8 +-
lib/octokit/client/repositories.rb | 269 ++++++++------------------------
lib/octokit/client/stats.rb | 14 +-
lib/octokit/client/statuses.rb | 32 +---
lib/octokit/client/users.rb | 58 ++++---
lib/octokit/error.rb | 6 +-
lib/octokit/organization.rb | 17 ++
lib/octokit/rate_limit.rb | 2 +-
lib/octokit/repository.rb | 27 +++-
lib/octokit/response/feed_parser.rb | 5 +-
lib/octokit/user.rb | 19 +++
lib/octokit/version.rb | 2 +-
metadata.yml | 24 ++-
octokit.gemspec | 2 +-
34 files changed, 919 insertions(+), 588 deletions(-)
diff --git a/README.md b/README.md
index 6ca79af..46098c0 100644
--- a/README.md
+++ b/README.md
@@ -5,8 +5,8 @@ Ruby toolkit for the GitHub API.
![Logo][logo]
[logo]: http://cl.ly/image/3Y013H0A2z3z/gundam-ruby.png
-Octokit 2.0 is out, check the [Upgrade Guide](#upgrading-guide) before
-upgrading from 1.x.
+Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new
+[major version][semver].
## Philosophy
@@ -33,11 +33,11 @@ Install via Rubygems
... or add to your Gemfile
- gem "octokit", "~> 2.0"
+ gem "octokit", "~> 3.0"
### Making requests
-API methods are available as module methods (consuming module-level
+[API methods][] are available as module methods (consuming module-level
configuration) or as client instance methods.
```ruby
@@ -59,6 +59,8 @@ client = Octokit::Client.new(:login => 'defunkt', :password => 'c0d3b4ssssss!')
client.user
```
+[API methods]: http://octokit.github.io/octokit.rb/method_list.html
+
### Consuming resources
Most methods return a `Resource` object which provides dot notation and `[]`
@@ -111,7 +113,7 @@ user = client.user
user.login
# => "defunkt"
```
-While Basic Authentication makes it easy to get started quickly, OAuth access
+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
@@ -119,14 +121,14 @@ tokens are the preferred way to authenticate on behalf of users.
[OAuth access tokens][oauth] provide two main benefits over using your username
and password:
-* **Revokable access**. Access tokens can be revoked, removing access for just
+* **Revokable 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, just pass it in lieu of your
-username and password:
+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:
```ruby
client = Octokit::Client.new(:access_token => "<your 40 char token>")
@@ -136,8 +138,17 @@ user.login
# => "defunkt"
```
-You can use `.create_authorization` to create a token using Basic Authorization
-that you can use for subsequent calls.
+You can [create access tokens through your GitHub Account Settings](https://help.github.com/articles/creating-an-access-token-for-command-line-use)
+or with a basic authenticated Octokit client:
+
+```ruby
+client = Octokit::Client.new \
+ :login => 'defunkt',
+ :password => 'c0d3b4ssssss!'
+
+client.create_authorization(:scopes => ["user"], :note => "Name of token")
+# => <your new oauth token>
+```
### Two-Factor Authentication
@@ -160,7 +171,8 @@ client = Octokit::Client.new \
:login => 'defunkt',
:password => 'c0d3b4ssssss!'
-client.create_authorization(:scopes => ["user"], :headers => { "X-GitHub-OTP" => "<your 2FA token>" })
+client.create_authorization(:scopes => ["user"], :note => "Name of token",
+ :headers => { "X-GitHub-OTP" => "<your 2FA token>" })
# => <your new oauth token>
```
@@ -208,12 +220,10 @@ client = Octokit::Client.new \
user = client.user 'defunkt'
```
-
-
[auth]: http://developer.github.com/v3/#authentication
[oauth]: http://developer.github.com/v3/oauth/
[access scopes]: http://developer.github.com/v3/oauth/#scopes
-[app-creds]: http://developer.github.com/v3/#unauthenticated-rate-limited-requests
+[app-creds]: http://developer.github.com/v3/#increasing-the-unauthenticated-rate-limit-for-oauth-applications
## Pagination
@@ -326,10 +336,10 @@ rel = repo.rels[:issues]
# => #<Sawyer::Relation: issues: get https://api.github.com/repos/pengwynn/pingwynn/issues{/number}>
# Get a page of issues
-repo.rels[:issues].get.data
+rel.get.data
# Get issue #2
-repo.rels[:issues].get(:uri => {:number => 2}).data
+rel.get(:uri => {:number => 2}).data
```
### The Full Hypermedia Experience™
@@ -352,6 +362,27 @@ construction currently used throughout the client.
## Upgrading guide
+Version 3.0 includes a couple breaking changes when upgrading from v2.x.x:
+
+The [default media type][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:
+
+```ruby
+Octokit.default_media_type = "application/vnd.github.beta+json"
+```
+or per-request
+
+```ruby
+Octokit.emails(:accept => "application/vnd.github.beta+json")
+```
+
+The long-deprecated `Octokit::Client#create_download` method has been removed.
+
+[default-media-type]: https://developer.github.com/changes/2014-01-07-upcoming-change-to-default-media-type/
+
+### 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:
@@ -378,8 +409,9 @@ extended via middleware.
### Debugging
-Often, it helps to know what Octokit is doing under the hood. Faraday makes it
-easy to peek into the underlying HTTP traffic:
+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:
```ruby
stack = Faraday::RackBuilder.new do |builder|
@@ -440,7 +472,7 @@ resource. See the [project README][cache] for advanced usage.
## Hacking on Octokit.rb
If you want to hack on Octokit locally, we try to make [bootstrapping the
-project][bootstrapping] as painless as possible. Just clone and run:
+project][bootstrapping] as painless as possible. To start hacking, clone and run:
script/bootstrap
@@ -455,12 +487,29 @@ console`, etc. ensures your dependencies are up-to-date.
### Running and writing new tests
Octokit uses [VCR][] for recording and playing back API fixtures during test
-runs. These fixtures are part of the Git project in the `spec/cassettes`
-folder. For the most part, tests use an authenticated client, using a token
-stored in `ENV['OCTOKIT_TEST_GITHUB_TOKEN']`. If you're not recording new
-cassettes, you don't need to have this set. If you do need to record new
-cassettes, this token can be any GitHub API token because the test suite strips
-the actual token from the cassette output before storing to disk.
+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 authenticating method's used accross 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](https://github.com/blog/1509-personal-api-tokens) 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.
Since we periodically refresh our cassettes, please keep some points in mind
when writing new specs.
@@ -491,7 +540,7 @@ implementations:
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, however support will only be provided for the versions listed
+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
@@ -514,10 +563,10 @@ 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][pvc] with two digits of precision. For example:
- spec.add_dependency 'octokit', '~> 2.0'
+ spec.add_dependency 'octokit', '~> 3.0'
[semver]: http://semver.org/
-[pvc]: http://docs.rubygems.org/read/chapter/16#page74
+[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
## License
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
deleted file mode 100644
index 74bfdd8..0000000
Binary files a/checksums.yaml.gz and /dev/null differ
diff --git a/lib/octokit/authentication.rb b/lib/octokit/authentication.rb
index 9522e31..c3eaa9c 100644
--- a/lib/octokit/authentication.rb
+++ b/lib/octokit/authentication.rb
@@ -62,6 +62,7 @@ module Octokit
# creds will be nil if there is no netrc for this end point
octokit_warn "Error loading credentials from netrc file for #{api_endpoint}"
else
+ creds = creds.to_a
self.login = creds.shift
self.password = creds.shift
end
diff --git a/lib/octokit/client.rb b/lib/octokit/client.rb
index 32559fe..c8ca3f9 100644
--- a/lib/octokit/client.rb
+++ b/lib/octokit/client.rb
@@ -6,6 +6,8 @@ require 'octokit/authentication'
require 'octokit/gist'
require 'octokit/rate_limit'
require 'octokit/repository'
+require 'octokit/user'
+require 'octokit/organization'
require 'octokit/client/authorizations'
require 'octokit/client/commits'
require 'octokit/client/commit_comments'
@@ -218,6 +220,7 @@ module Octokit
def agent
@agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http|
http.headers[:accept] = default_media_type
+ http.headers[:content_type] = "application/json"
http.headers[:user_agent] = user_agent
if basic_authenticated?
http.basic_auth(@login, @password)
@@ -308,6 +311,16 @@ module Octokit
@client_secret = value
end
+ # Wrapper around Kernel#warn to print warnings unless
+ # OCTOKIT_SILENT is set to true.
+ #
+ # @return [nil]
+ def octokit_warn(*message)
+ unless ENV['OCTOKIT_SILENT']
+ warn message
+ end
+ end
+
private
def reset_agent
@@ -364,15 +377,5 @@ module Octokit
opts
end
-
- # Wrapper around Kernel#warn to print warnings unless
- # OCTOKIT_SILENT is set to true.
- #
- # @return [nil]
- def octokit_warn(*message)
- unless ENV['OCTOKIT_SILENT']
- warn message
- end
- end
end
end
diff --git a/lib/octokit/client/commit_comments.rb b/lib/octokit/client/commit_comments.rb
index 5f9e5ef..bdcdec8 100644
--- a/lib/octokit/client/commit_comments.rb
+++ b/lib/octokit/client/commit_comments.rb
@@ -8,36 +8,36 @@ module Octokit
# List all commit comments
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Array] List of commit comments
# @see https://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository
def list_commit_comments(repo, options = {})
- get "repos/#{Repository.new(repo)}/comments", options
+ get "#{Repository.path repo}/comments", options
end
# List comments for a single commit
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param sha [String] The SHA of the commit whose comments will be fetched
# @return [Array] List of commit comments
# @see https://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit
def commit_comments(repo, sha, options = {})
- get "repos/#{Repository.new(repo)}/commits/#{sha}/comments", options
+ get "#{Repository.path repo}/commits/#{sha}/comments", options
end
# Get a single commit comment
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param id [String] The ID of the comment to fetch
# @return [Sawyer::Resource] Commit comment
# @see https://developer.github.com/v3/repos/comments/#get-a-single-commit-comment
def commit_comment(repo, id, options = {})
- get "repos/#{Repository.new(repo)}/comments/#{id}", options
+ get "#{Repository.path repo}/comments/#{id}", options
end
# Create a commit comment
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param sha [String] Sha of the commit to comment on
# @param body [String] Message
# @param path [String] Relative path of file to comment on
@@ -60,12 +60,12 @@ module Octokit
:line => line,
:position => position
}
- post "repos/#{Repository.new(repo)}/commits/#{sha}/comments", options.merge(params)
+ post "#{Repository.path repo}/commits/#{sha}/comments", options.merge(params)
end
# Update a commit comment
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param id [String] The ID of the comment to update
# @param body [String] Message
# @return [Sawyer::Resource] Updated commit comment
@@ -78,17 +78,17 @@ module Octokit
params = {
:body => body
}
- patch "repos/#{Repository.new(repo)}/comments/#{id}", options.merge(params)
+ patch "#{Repository.path repo}/comments/#{id}", options.merge(params)
end
# Delete a commit comment
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param id [String] The ID of the comment to delete
# @return [Boolean] Success
# @see https://developer.github.com/v3/repos/comments/#delete-a-commit-comment
def delete_commit_comment(repo, id, options = {})
- boolean_from_response :delete, "repos/#{Repository.new(repo)}/comments/#{id}", options
+ boolean_from_response :delete, "#{Repository.path repo}/comments/#{id}", options
end
end
end
diff --git a/lib/octokit/client/commits.rb b/lib/octokit/client/commits.rb
index d17e40c..997f410 100644
--- a/lib/octokit/client/commits.rb
+++ b/lib/octokit/client/commits.rb
@@ -12,11 +12,11 @@ module Octokit
#
# @overload commits(repo, sha_or_branch, options = {})
# @deprecated
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param sha_or_branch [String] A commit SHA or branch name
# @param options [String] :sha Commit SHA or branch name from which to start the list
# @overload commits(repo, options = {})
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param options [String] :sha Commit SHA or branch name from which to start the list
# @return [Array<Sawyer::Resource>] An array of hashes representing commits
# @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
@@ -26,19 +26,19 @@ module Octokit
if sha_or_branch
arguments.options[:sha] = sha_or_branch
end
- paginate "repos/#{Repository.new(arguments.repo)}/commits", arguments.options
+ paginate "#{Repository.new(arguments.repo).path}/commits", arguments.options
end
alias :list_commits :commits
# Get commits after a specified date
#
# @overload commits_since(repo, date, options = {})
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param date [String] Date on which we want to compare
# @param options [String] :sha Commit SHA or branch name from which to start the list
# @overload commits_since(repo, date, sha_or_branch, options = {})
# @deprecated
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param date [String] Date on which we want to compare
# @param sha_or_branch [String] A commit SHA or branch name
# @param options [String] :sha Commit SHA or branch name from which to start the list
@@ -61,11 +61,11 @@ module Octokit
# Get commits before a specified date
#
# @overload commits_before(repo, date, options = {})
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param date [String] Date on which we want to compare
# @overload commits_before(repo, date, sha_or_branch, options = {})
# @deprecated
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param date [String] Date on which we want to compare
# @param sha_or_branch [String] Commit SHA or branch name from which to start the list
# @return [Array<Sawyer::Resource>] An array of hashes representing commits
@@ -87,11 +87,11 @@ module Octokit
# Get commits on a specified date
#
# @overload commits_on(repo, date, options = {})
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param date [String] Date on which we want to compare
# @overload commits_on(repo, date, sha_or_branch, options = {})
# @deprecated
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param date [String] Date on which we want to compare
# @param sha_or_branch [String] Commit SHA or branch name from which to start the list
# @return [Array<Sawyer::Resource>] An array of hashes representing commits
@@ -114,12 +114,12 @@ module Octokit
# Get commits made between two nominated dates
#
# @overload commits_between(repo, start_date, end_date, options = {})
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param start_date [String] Start Date on which we want to compare
# @param end_date [String] End Date on which we want to compare
# @overload commits_between(repo, start_date, end_date, sha_or_branch, options = {})
# @deprecated
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param start_date [String] Start Date on which we want to compare
# @param end_date [String] End Date on which we want to compare
# @param sha_or_branch [String] Commit SHA or branch name from which to start the list
@@ -144,22 +144,22 @@ module Octokit
# Get a single commit
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param sha [String] The SHA of the commit to fetch
# @return [Sawyer::Resource] A hash representing the commit
# @see https://developer.github.com/v3/repos/commits/#get-a-single-commit
def commit(repo, sha, options = {})
- get "repos/#{Repository.new(repo)}/commits/#{sha}", options
+ get "#{Repository.path repo}/commits/#{sha}", options
end
# Get a detailed git commit
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param sha [String] The SHA of the commit to fetch
# @return [Sawyer::Resource] A hash representing the commit
# @see https://developer.github.com/v3/git/commits/#get-a-commit
def git_commit(repo, sha, options = {})
- get "repos/#{Repository.new(repo)}/git/commits/#{sha}", options
+ get "#{Repository.path repo}/git/commits/#{sha}", options
end
# Create a commit
@@ -169,7 +169,7 @@ module Octokit
# inferred from the authenticated user. See <a href="http://developer.github.com/v3/git/commits/">GitHub's documentation</a>
# for details about how to format committer identities.
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param message [String] The commit message
# @param tree [String] The SHA of the tree object the new commit will point to
# @param parents [String, Array] One SHA (for a normal commit) or an array of SHAs (for a merge) of the new commit's parent commits. If ommitted or empty, a root commit will be created
@@ -184,23 +184,23 @@ module Octokit
def create_commit(repo, message, tree, parents=nil, options = {})
params = { :message => message, :tree => tree }
params[:parents] = [parents].flatten if parents
- post "repos/#{Repository.new(repo)}/git/commits", options.merge(params)
+ post "#{Repository.path repo}/git/commits", options.merge(params)
end
# Compare two commits
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param start [String] The sha of the starting commit
# @param endd [String] The sha of the ending commit
# @return [Sawyer::Resource] A hash representing the comparison
# @see https://developer.github.com/v3/repos/commits/#compare-two-commits
def compare(repo, start, endd, options = {})
- get "repos/#{Repository.new(repo)}/compare/#{start}...#{endd}", options
+ get "#{Repository.path repo}/compare/#{start}...#{endd}", options
end
# Merge a branch or sha
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param base [String] The name of the base branch to merge into
# @param head [String] The branch or SHA1 to merge
# @option options [String] :commit_message The commit message for the merge
@@ -211,7 +211,7 @@ module Octokit
:base => base,
:head => head
}.merge(options)
- post "repos/#{Repository.new(repo)}/merges", params
+ post "#{Repository.path repo}/merges", params
end
protected
diff --git a/lib/octokit/client/contents.rb b/lib/octokit/client/contents.rb
index 86fbec7..d325e5e 100644
--- a/lib/octokit/client/contents.rb
+++ b/lib/octokit/client/contents.rb
@@ -10,19 +10,19 @@ module Octokit
# Receive the default Readme for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @option options [String] :ref name of the Commit/Branch/Tag. Defaults to “master”.
# @return [Sawyer::Resource] The detail of the readme
# @see https://developer.github.com/v3/repos/contents/#get-the-readme
# @example Get the readme file for a repo
# Octokit.readme("octokit/octokit.rb")
def readme(repo, options={})
- get "repos/#{Repository.new(repo)}/readme", options
+ get "#{Repository.path repo}/readme", options
end
# Receive a listing of a repository folder or the contents of a file
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @option options [String] :path A folder or file path
# @option options [String] :ref name of the Commit/Branch/Tag. Defaults to “master”.
# @return [Sawyer::Resource] The contents of a file or list of the files in the folder
@@ -31,7 +31,7 @@ module Octokit
# Octokit.contents("octokit/octokit.rb", :path => 'lib/octokit.rb')
def contents(repo, options={})
repo_path = options.delete :path
- url = "repos/#{Repository.new(repo)}/contents/#{repo_path}"
+ url = "#{Repository.path repo}/contents/#{repo_path}"
get url, options
end
alias :content :contents
@@ -39,7 +39,7 @@ module Octokit
# Add content to a repository
#
# @overload create_contents(repo, path, message, content = nil, options = {})
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param path [String] A path for the new content
# @param message [String] A commit message for adding the content
# @param optional content [String] The content for the file
@@ -67,7 +67,7 @@ module Octokit
content = file.read
file.close
end
- when File
+ when File, Tempfile
content = file.read
file.close
end
@@ -77,7 +77,7 @@ module Octokit
Base64.strict_encode64(content) :
Base64.encode64(content).delete("\n") # Ruby 1.9.2
options[:message] = message
- url = "repos/#{Repository.new(repo)}/contents/#{path}"
+ url = "#{Repository.path repo}/contents/#{path}"
put url, options
end
alias :create_content :create_contents
@@ -87,7 +87,7 @@ module Octokit
# Update content in a repository
#
# @overload update_contents(repo, path, message, sha, content = nil, options = {})
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param path [String] A path for the content to update
# @param message [String] A commit message for updating the content
# @param sha [String] The _blob sha_ of the content to update
@@ -117,7 +117,7 @@ module Octokit
# Delete content in a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param path [String] A path for the content to delete
# @param message [String] A commit message for deleting the content
# @param sha [String] The _blob sha_ of the content to delete
@@ -133,7 +133,7 @@ module Octokit
def delete_contents(repo, path, message, sha, options = {})
options[:message] = message
options[:sha] = sha
- url = "repos/#{Repository.new(repo)}/contents/#{path}"
+ url = "#{Repository.path repo}/contents/#{path}"
delete url, options
end
alias :delete_content :delete_contents
@@ -142,7 +142,7 @@ module Octokit
# This method will provide a URL to download a tarball or zipball archive for a repository.
#
- # @param repo [String, Repository, Hash] A GitHub repository.
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository.
# @option options format [String] Either tarball (default) or zipball.
# @option options [String] :ref Optional valid Git reference, defaults to master.
# @return [String] Location of the download
@@ -152,7 +152,7 @@ module Octokit
def archive_link(repo, options={})
repo_ref = options.delete :ref
format = (options.delete :format) || 'tarball'
- url = "repos/#{Repository.new(repo)}/#{format}/#{repo_ref}"
+ url = "#{Repository.path repo}/#{format}/#{repo_ref}"
request :head, url, options
last_response.headers['Location']
diff --git a/lib/octokit/client/deployments.rb b/lib/octokit/client/deployments.rb
index e5bd9c4..51d943a 100644
--- a/lib/octokit/client/deployments.rb
+++ b/lib/octokit/client/deployments.rb
@@ -6,33 +6,31 @@ module Octokit
# @see https://developer.github.com/v3/repos/commits/deployments/
module Deployments
- DEPLOYMENTS_PREVIEW_MEDIA_TYPE = "application/vnd.github.cannonball-preview+json".freeze
-
# List all deployments for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @return [Array<Sawyer::Resource>] A list of deployments
# @see https://developer.github.com/v3/repos/deployments/#list-deployments
def deployments(repo, options = {})
- options = ensure_deployments_api_media_type(options)
- get("repos/#{Repository.new(repo)}/deployments", options)
+ get("#{Repository.path repo}/deployments", options)
end
alias :list_deployments :deployments
# Create a deployment for a ref
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param ref [String] The ref to deploy
+ # @option options [String] :task Used by the deployment system to allow different execution paths. Defaults to "deploy".
# @option options [String] :payload Meta info about the deployment
- # @option options [String] :force Optional parameter to bypass any ahead/behind checks or commit status checks. Default: false
- # @option options [String] :auto_merge Optional parameter to merge the default branch into the requested deployment branch if necessary. Default: false
+ # @option options [Boolean] :auto_merge Optional parameter to merge the default branch into the requested deployment branch if necessary. Default: true
+ # @option options [Array<String>] :required_contexts Optional array of status contexts verified against commit status checks.
+ # @option options [String] :environment Optional name for the target deployment environment (e.g., production, staging, qa). Default: "production"
# @option options [String] :description Optional short description.
# @return [Sawyer::Resource] A deployment
# @see https://developer.github.com/v3/repos/deployments/#create-a-deployment
def create_deployment(repo, ref, options = {})
- options = ensure_deployments_api_media_type(options)
options[:ref] = ref
- post("repos/#{Repository.new(repo)}/deployments", options)
+ post("#{Repository.path repo}/deployments", options)
end
# List all statuses for a Deployment
@@ -41,7 +39,6 @@ module Octokit
# @return [Array<Sawyer::Resource>] A list of deployment statuses
# @see https://developer.github.com/v3/repos/deployments/#list-deployment-statuses
def deployment_statuses(deployment_url, options = {})
- options = ensure_deployments_api_media_type(options)
deployment = get(deployment_url, :accept => options[:accept])
get(deployment.rels[:statuses].href, options)
end
@@ -54,30 +51,10 @@ module Octokit
# @return [Sawyer::Resource] A deployment status
# @see https://developer.github.com/v3/repos/deployments/#create-a-deployment-status
def create_deployment_status(deployment_url, state, options = {})
- options = ensure_deployments_api_media_type(options)
deployment = get(deployment_url, :accept => options[:accept])
options[:state] = state.to_s.downcase
post(deployment.rels[:statuses].href, options)
end
-
- private
-
- def ensure_deployments_api_media_type(options = {})
- if options[:accept].nil?
- options[:accept] = DEPLOYMENTS_PREVIEW_MEDIA_TYPE
- warn_deployments_preview
- end
-
- options
- end
-
- def warn_deployments_preview
- octokit_warn <<-EOS
-WARNING: The preview version of the Deployments API is not yet suitable for production use.
-You can avoid this message by supplying an appropriate media type in the 'Accept' request
-header. See the blog post for details: http://git.io/o2XZRA
-EOS
- end
end
end
end
diff --git a/lib/octokit/client/downloads.rb b/lib/octokit/client/downloads.rb
index aa85dbd..5a81c0d 100644
--- a/lib/octokit/client/downloads.rb
+++ b/lib/octokit/client/downloads.rb
@@ -8,20 +8,20 @@ module Octokit
# List available downloads for a repository
#
- # @param repo [String, Repository, Hash] A Github Repository
+ # @param repo [Integer, String, Repository, Hash] A Github Repository
# @return [Array] A list of available downloads
# @deprecated As of December 11th, 2012: https://github.com/blog/1302-goodbye-uploads
# @see https://developer.github.com/v3/repos/downloads/#list-downloads-for-a-repository
# @example List all downloads for Github/Hubot
# Octokit.downloads("github/hubot")
def downloads(repo, options={})
- paginate "repos/#{Repository.new(repo)}/downloads", options
+ paginate "#{Repository.path repo}/downloads", options
end
alias :list_downloads :downloads
# Get single download for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param id [Integer] ID of the download
# @return [Sawyer::Resource] A single download from the repository
# @deprecated As of December 11th, 2012: https://github.com/blog/1302-goodbye-uploads
@@ -29,12 +29,12 @@ module Octokit
# @example Get the "Robawt" download from Github/Hubot
# Octokit.download("github/hubot")
def download(repo, id, options={})
- get "repos/#{Repository.new(repo)}/downloads/#{id}", options
+ get "#{Repository.path repo}/downloads/#{id}", options
end
# Delete a single download for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param id [Integer] ID of the download
# @deprecated As of December 11th, 2012: https://github.com/blog/1302-goodbye-uploads
# @see https://developer.github.com/v3/repos/downloads/#delete-a-download
@@ -42,7 +42,7 @@ module Octokit
# @example Get the "Robawt" download from Github/Hubot
# Octokit.delete_download("github/hubot", 1234)
def delete_download(repo, id, options = {})
- boolean_from_response :delete, "repos/#{Repository.new(repo)}/downloads/#{id}", options
+ boolean_from_response :delete, "#{Repository.path repo}/downloads/#{id}", options
end
end
diff --git a/lib/octokit/client/events.rb b/lib/octokit/client/events.rb
index 2dc854e..9b277e3 100644
--- a/lib/octokit/client/events.rb
+++ b/lib/octokit/client/events.rb
@@ -19,54 +19,57 @@ module Octokit
# List all user events
#
+ # @param user [Integer, String] GitHub user login or id.
# @return [Array<Sawyer::Resource>] A list of all user events
# @see https://developer.github.com/v3/activity/events/#list-events-performed-by-a-user
# @example List all user events
# Octokit.user_events("sferik")
def user_events(user, options = {})
- paginate "users/#{user}/events", options
+ paginate "#{User.path user}/events", options
end
# List public user events
#
- # @param user [String] GitHub username
+ # @param user [Integer, String] GitHub user login or id
# @return [Array<Sawyer::Resource>] A list of public user events
# @see https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user
# @example List public user events
# Octokit.user_events("sferik")
def user_public_events(user, options = {})
- paginate "users/#{user}/events/public", options
+ paginate "#{User.path user}/events/public", options
end
# List events that a user has received
#
+ # @param user [Integer, String] GitHub user login or id
# @return [Array<Sawyer::Resource>] A list of all user received events
# @see https://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received
# @example List all user received events
# Octokit.received_events("sferik")
def received_events(user, options = {})
- paginate "users/#{user}/received_events", options
+ paginate "#{User.path user}/received_events", options
end
# List public events a user has received
#
+ # @param user [Integer, String] GitHub user login or id
# @return [Array<Sawyer::Resource>] A list of public user received events
# @see https://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received
# @example List public user received events
# Octokit.received_public_events("sferik")
def received_public_events(user, options = {})
- paginate "users/#{user}/received_events/public", options
+ paginate "#{User.path user}/received_events/public", options
end
# List events for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @return [Array<Sawyer::Resource>] A list of events for a repository
# @see https://developer.github.com/v3/activity/events/#list-repository-events
# @example List events for a repository
# Octokit.repository_events("sferik/rails_admin")
def repository_events(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/events", options
+ paginate "#{Repository.path repo}/events", options
end
# List public events for a repository's network
@@ -95,18 +98,18 @@ module Octokit
# List an organization's public events
#
- # @param org [String] Organization GitHub username
+ # @param org [String, Integer] Organization GitHub login or id.
# @return [Array<Sawyer::Resource>] List of public events from a GitHub organization
# @see https://developer.github.com/v3/activity/events/#list-public-events-for-an-organization
# @example List public events for GitHub
# Octokit.organization_public_events("GitHub")
def organization_public_events(org, options = {})
- paginate "orgs/#{org}/events", options
+ paginate "#{Organization.path org}/events", options
end
# Get all Issue Events for a given Repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
#
# @return [Array<Sawyer::Resource>] Array of all Issue Events for this Repository
# @see https://developer.github.com/v3/issues/events/#list-events-for-a-repository
@@ -114,13 +117,13 @@ module Octokit
# @example Get all Issue Events for Octokit
# Octokit.repository_issue_events("octokit/octokit.rb")
def repository_issue_events(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/issues/events", options
+ paginate "#{Repository.path repo}/issues/events", options
end
alias :repo_issue_events :repository_issue_events
# List events for an Issue
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Integer] Issue number
#
# @return [Array<Sawyer::Resource>] Array of events for that issue
@@ -128,12 +131,12 @@ module Octokit
# @example List all issues events for issue #38 on octokit/octokit.rb
# Octokit.issue_events("octokit/octokit.rb", 38)
def issue_events(repo, number, options = {})
- paginate "repos/#{Repository.new(repo)}/issues/#{number}/events", options
+ paginate "#{Repository.path repo}/issues/#{number}/events", options
end
# Get information on a single Issue Event
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Integer] Event number
#
# @return [Sawyer::Resource] A single Event for an Issue
@@ -141,7 +144,7 @@ module Octokit
# @example Get Event information for ID 3094334 (a pull request was closed)
# Octokit.issue_event("octokit/octokit.rb", 3094334)
def issue_event(repo, number, options = {})
- paginate "repos/#{Repository.new(repo)}/issues/events/#{number}", options
+ paginate "#{Repository.path repo}/issues/events/#{number}", options
end
end
end
diff --git a/lib/octokit/client/gists.rb b/lib/octokit/client/gists.rb
index fc23730..3499cd4 100644
--- a/lib/octokit/client/gists.rb
+++ b/lib/octokit/client/gists.rb
@@ -8,18 +8,18 @@ module Octokit
# List gists for a user or all public gists
#
- # @param username [String] An optional user to filter listing
+ # @param user [String] An optional user to filter listing
# @return [Array<Sawyer::Resource>] A list of gists
# @example Fetch all gists for defunkt
# Octokit.gists('defunkt')
# @example Fetch all public gists
# Octokit.gists
# @see https://developer.github.com/v3/gists/#list-gists
- def gists(username=nil, options = {})
- if username.nil?
+ def gists(user=nil, options = {})
+ if user.nil?
paginate 'gists', options
else
- paginate "users/#{username}/gists", options
+ paginate "#{User.path user}/gists", options
end
end
alias :list_gists :gists
diff --git a/lib/octokit/client/hooks.rb b/lib/octokit/client/hooks.rb
index 7b3e523..c7c39c1 100644
--- a/lib/octokit/client/hooks.rb
+++ b/lib/octokit/client/hooks.rb
@@ -4,6 +4,8 @@ module Octokit
# Methods for the Hooks API
module Hooks
+ ORG_HOOKS_PREVIEW_MEDIA_TYPE = "application/vnd.github.sersi-preview+json".freeze
+
# List all Service Hooks supported by GitHub
#
# @return [Sawyer::Resource] A list of all hooks on GitHub
@@ -13,6 +15,286 @@ module Octokit
def available_hooks(options = {})
get "hooks", options
end
+
+ # List repo hooks
+ #
+ # Requires authenticated client.
+ #
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
+ # @return [Array<Sawyer::Resource>] Array of hashes representing hooks.
+ # @see https://developer.github.com/v3/repos/hooks/#list-hooks
+ # @example
+ # @client.hooks('octokit/octokit.rb')
+ def hooks(repo, options = {})
+ paginate "#{Repository.path repo}/hooks", options
+ end
+
+ # Get single hook
+ #
+ # Requires authenticated client.
+ #
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
+ # @param id [Integer] Id of the hook to get.
+ # @return [Sawyer::Resource] Hash representing hook.
+ # @see https://developer.github.com/v3/repos/hooks/#get-single-hook
+ # @example
+ # @client.hook('octokit/octokit.rb', 100000)
+ def hook(repo, id, options = {})
+ get "#{Repository.path repo}/hooks/#{id}", options
+ end
+
+ # Create a hook
+ #
+ # Requires authenticated client.
+ #
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
+ # @param name [String] The name of the service that is being called. See
+ # {https://api.github.com/hooks Hooks} for the possible names.
+ # @param config [Hash] A Hash containing key/value pairs to provide
+ # settings for this hook. These settings vary between the services and
+ # are defined in the {https://github.com/github/github-services github-services} repo.
+ # @option options [Array<String>] :events ('["push"]') Determines what
+ # events the hook is triggered for.
+ # @option options [Boolean] :active Determines whether the hook is
+ # actually triggered on pushes.
+ # @return [Sawyer::Resource] Hook info for the new hook
+ # @see https://api.github.com/hooks
+ # @see https://github.com/github/github-services
+ # @see https://developer.github.com/v3/repos/hooks/#create-a-hook
+ # @example
+ # @client.create_hook(
+ # 'octokit/octokit.rb',
+ # 'web',
+ # {
+ # :url => 'http://something.com/webhook',
+ # :content_type => 'json'
+ # },
+ # {
+ # :events => ['push', 'pull_request'],
+ # :active => true
+ # }
+ # )
+ def create_hook(repo, name, config, options = {})
+ options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
+ post "#{Repository.path repo}/hooks", options
+ end
+
+ # Edit a hook
+ #
+ # Requires authenticated client.
+ #
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
+ # @param id [Integer] Id of the hook being updated.
+ # @param name [String] The name of the service that is being called. See
+ # {https://api.github.com/hooks Hooks} for the possible names.
+ # @param config [Hash] A Hash containing key/value pairs to provide
+ # settings for this hook. These settings vary between the services and
+ # are defined in the {https://github.com/github/github-services github-services} repo.
+ # @option options [Array<String>] :events ('["push"]') Determines what
+ # events the hook is triggered for.
+ # @option options [Array<String>] :add_events Determines a list of events
+ # to be added to the list of events that the Hook triggers for.
+ # @option options [Array<String>] :remove_events Determines a list of events
+ # to be removed from the list of events that the Hook triggers for.
+ # @option options [Boolean] :active Determines whether the hook is
+ # actually triggered on pushes.
+ # @return [Sawyer::Resource] Hook info for the updated hook
+ # @see https://api.github.com/hooks
+ # @see https://github.com/github/github-services
+ # @see https://developer.github.com/v3/repos/hooks/#edit-a-hook
+ # @example
+ # @client.edit_hook(
+ # 'octokit/octokit.rb',
+ # 100000,
+ # 'web',
+ # {
+ # :url => 'http://something.com/webhook',
+ # :content_type => 'json'
+ # },
+ # {
+ # :add_events => ['status'],
+ # :remove_events => ['pull_request'],
+ # :active => true
+ # }
+ # )
+ def edit_hook(repo, id, name, config, options = {})
+ options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
+ patch "#{Repository.path repo}/hooks/#{id}", options
+ end
+
+ # Delete hook
+ #
+ # Requires authenticated client.
+ #
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
+ # @param id [Integer] Id of the hook to remove.
+ # @return [Boolean] True if hook removed, false otherwise.
+ # @see https://developer.github.com/v3/repos/hooks/#delete-a-hook
+ # @example
+ # @client.remove_hook('octokit/octokit.rb', 1000000)
+ def remove_hook(repo, id, options = {})
+ boolean_from_response :delete, "#{Repository.path repo}/hooks/#{id}", options
+ end
+
+ # Test hook
+ #
+ # Requires authenticated client.
+ #
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
+ # @param id [Integer] Id of the hook to test.
+ # @return [Boolean] Success
+ # @see https://developer.github.com/v3/repos/hooks/#test-a-push-hook
+ # @example
+ # @client.test_hook('octokit/octokit.rb', 1000000)
+ def test_hook(repo, id, options = {})
+ boolean_from_response :post, "#{Repository.path repo}/hooks/#{id}/tests", options
+ end
+
+ # List org hooks
+ #
+ # Requires client authenticated as admin for the org.
+ #
+ # @param org [String] A GitHub organization login.
+ # @return [Array<Sawyer::Resource>] Array of hashes representing hooks.
+ # @see https://developer.github.com/v3/orgs/hooks/#list-hooks
+ # @example
+ # @client.org_hooks('octokit')
+ def org_hooks(org, options = {})
+ options = ensure_org_hooks_api_media_type(options)
+ paginate "orgs/#{org}/hooks", options
+ end
+ alias :list_org_hooks :org_hooks
+
+ # Get an org hook
+ #
+ # Requires client authenticated as admin for the org.
+ #
+ # @param org [String] A GitHub organization login.
+ # @param id [Integer] Id of the hook to get.
+ # @return [Sawyer::Resource] Hash representing hook.
+ # @see https://developer.github.com/v3/orgs/hooks/#get-single-hook
+ # @example
+ # @client.org_hook('octokit', 123)
+ def org_hook(org, id, options = {})
+ options = ensure_org_hooks_api_media_type(options)
+ get "orgs/#{org}/hooks/#{id}", options
+ end
+
+ # Create an org hook
+ #
+ # Requires client authenticated as admin for the org.
+ #
+ # @param org [String] A GitHub organization login.
+ # @param config [Hash] A Hash containing key/value pairs to provide
+ # settings for this hook.
+ # @option options [Array<String>] :events ('["push"]') Determines what
+ # events the hook is triggered for.
+ # @option options [Boolean] :active Determines whether the hook is
+ # actually triggered on pushes.
+ # @return [Sawyer::Resource] Hook info for the new hook
+ # @see https://api.github.com/hooks
+ # @see https://developer.github.com/v3/orgs/hooks/#create-a-hook
+ # @example
+ # @client.create_org_hook(
+ # 'octokit',
+ # {
+ # :url => 'http://something.com/webhook',
+ # :content_type => 'json'
+ # },
+ # {
+ # :events => ['push', 'pull_request'],
+ # :active => true
+ # }
+ # )
+ def create_org_hook(org, config, options = {})
+ options = ensure_org_hooks_api_media_type(options)
+ options = { :name => "web", :config => config }.merge(options)
+ post "orgs/#{org}/hooks", options
+ end
+
+ # Update an org hook
+ #
+ # Requires client authenticated as admin for the org.
+ #
+ # @param org [String] A GitHub organization login.
+ # @param id [Integer] Id of the hook to update.
+ # @param config [Hash] A Hash containing key/value pairs to provide
+ # settings for this hook.
+ # @option options [Array<String>] :events ('["push"]') Determines what
+ # events the hook is triggered for.
+ # @option options [Boolean] :active Determines whether the hook is
+ # actually triggered on pushes.
+ # @return [Sawyer::Resource] Hook info for the new hook
+ # @see https://api.github.com/hooks
+ # @see https://developer.github.com/v3/orgs/hooks/#edit-a-hook
+ # @example
+ # @client.edit_org_hook(
+ # 'octokit',
+ # 123,
+ # {
+ # :url => 'http://something.com/webhook',
+ # :content_type => 'json'
+ # },
+ # {
+ # :events => ['push', 'pull_request'],
+ # :active => true
+ # }
+ # )
+ def edit_org_hook(org, id, config, options = {})
+ options = ensure_org_hooks_api_media_type(options)
+ options = { :config => config }.merge(options)
+ patch "orgs/#{org}/hooks/#{id}", options
+ end
+ alias :update_org_hook :edit_org_hook
+
+ # Ping org hook
+ #
+ # Requires client authenticated as admin for the org.
+ #
+ # @param org [String] A GitHub organization login.
+ # @param id [Integer] Id of the hook to update.
+ # @return [Boolean] Success
+ # @see https://developer.github.com/v3/orgs/hooks/#ping-a-hook
+ # @example
+ # @client.ping_org_hook('octokit', 1000000)
+ def ping_org_hook(org, id, options = {})
+ options = ensure_org_hooks_api_media_type(options)
+ boolean_from_response :post, "orgs/#{org}/hooks/#{id}/pings", options
+ end
+
+ # Remove org hook
+ #
+ # Requires client authenticated as admin for the org.
+ #
+ # @param org [String] A GitHub organization login.
+ # @param id [Integer] Id of the hook to update.
+ # @return [Boolean] True if hook removed, false otherwise.
+ # @see https://developer.github.com/v3/orgs/hooks/#delete-a-hook
+ # @example
+ # @client.remove_org_hook('octokit', 1000000)
+ def remove_org_hook(org, id, options = {})
+ options = ensure_org_hooks_api_media_type(options)
+ boolean_from_response :delete, "orgs/#{org}/hooks/#{id}", options
+ end
+
+ private
+
+ def ensure_org_hooks_api_media_type(options = {})
+ if options[:accept].nil?
+ options[:accept] = ORG_HOOKS_PREVIEW_MEDIA_TYPE
+ warn_org_hooks_preview
+ end
+
+ options
+ end
+
+ def warn_org_hooks_preview
+ octokit_warn <<-EOS
+WARNING: The preview version of the Org Hooks API is not yet suitable for production use.
+You can avoid this message by supplying an appropriate media type in the 'Accept' request
+header. See the blog post for details: http://git.io/<LINK>
+EOS
+ end
end
end
end
diff --git a/lib/octokit/client/issues.rb b/lib/octokit/client/issues.rb
index 33d38bd..37cbe60 100644
--- a/lib/octokit/client/issues.rb
+++ b/lib/octokit/client/issues.rb
@@ -8,7 +8,7 @@ module Octokit
# List issues for the authenticated user or repository
#
- # @param repository [String, Repository, Hash] A GitHub repository.
+ # @param repository [Integer, String, Repository, Hash] A GitHub repository.
# @param options [Sawyer::Resource] A customizable set of options.
# @option options [Integer] :milestone Milestone number.
# @option options [String] :state (open) State: <tt>open</tt> or <tt>closed</tt>.
@@ -24,15 +24,11 @@ module Octokit
# @see https://developer.github.com/v3/issues/#list-issues
# @example List issues for a repository
# Octokit.list_issues("sferik/rails_admin")
- # @example List issues for the authenticted user across repositories
+ # @example List issues for the authenticated user across repositories
# @client = Octokit::Client.new(:login => 'foo', :password => 'bar')
# @client.list_issues
def list_issues(repository = nil, options = {})
- path = ''
- path = "repos/#{Repository.new(repository)}" if repository
- path += "/issues"
-
- paginate path, options
+ paginate "#{Repository.new(repository).path}/issues", options
end
alias :issues :list_issues
@@ -49,7 +45,7 @@ module Octokit
# format: YYYY-MM-DDTHH:MM:SSZ
# @return [Array<Sawyer::Resource>] A list of issues for a repository.
# @see https://developer.github.com/v3/issues/#list-issues
- # @example List issues for the authenticted user across owned and member repositories
+ # @example List issues for the authenticated user across owned and member repositories
# @client = Octokit::Client.new(:login => 'foo', :password => 'bar')
# @client.user_issues
def user_issues(options = {})
@@ -58,7 +54,7 @@ module Octokit
# List all issues for a given organization for the authenticated user
#
- # @param org [String] Organization GitHub username.
+ # @param org [String, Integer] Organization GitHub login or id.
# @param options [Sawyer::Resource] A customizable set of options.
# @option options [String] :filter (assigned) State: <tt>assigned</tt>, <tt>created</tt>, <tt>mentioned</tt>, <tt>subscribed</tt> or <tt>closed</tt>.
# @option options [String] :state (open) State: <tt>open</tt> or <tt>closed</tt>.
@@ -74,12 +70,12 @@ module Octokit
# @client = Octokit::Client.new(:login => 'foo', :password => 'bar')
# @client.org_issues("octokit")
def org_issues(org, options = {})
- paginate "orgs/#{org}/issues", options
+ paginate "#{Organization.path org}/issues", options
end
# Create an issue for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param title [String] A descriptive title
# @param body [String] A concise description
# @param options [Hash] A customizable set of options.
@@ -96,26 +92,28 @@ module Octokit
options[:labels].split(",").map(&:strip)
when Array
options[:labels]
+ else
+ []
end
- post "repos/#{Repository.new(repo)}/issues", options.merge({:title => title, :body => body})
+ post "#{Repository.path repo}/issues", options.merge({:title => title, :body => body})
end
alias :open_issue :create_issue
# Get a single issue from a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Integer] Number ID of the issue
# @return [Sawyer::Resource] The issue you requested, if it exists
# @see https://developer.github.com/v3/issues/#get-a-single-issue
# @example Get issue #25 from octokit/octokit.rb
# Octokit.issue("octokit/octokit.rb", "25")
def issue(repo, number, options = {})
- get "repos/#{Repository.new(repo)}/issues/#{number}", options
+ get "#{Repository.path repo}/issues/#{number}", options
end
# Close an issue
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Integer] Number ID of the issue
# @param options [Hash] A customizable set of options.
# @option options [String] :assignee User login.
@@ -126,12 +124,12 @@ module Octokit
# @example Close Issue #25 from octokit/octokit.rb
# Octokit.close_issue("octokit/octokit.rb", "25")
def close_issue(repo, number, options = {})
- patch "repos/#{Repository.new(repo)}/issues/#{number}", options.merge({:state => "closed"})
+ patch "#{Repository.path repo}/issues/#{number}", options.merge({:state => "closed"})
end
# Reopen an issue
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Integer] Number ID of the issue
# @param options [Hash] A customizable set of options.
# @option options [String] :assignee User login.
@@ -142,33 +140,57 @@ module Octokit
# @example Reopen Issue #25 from octokit/octokit.rb
# Octokit.reopen_issue("octokit/octokit.rb", "25")
def reopen_issue(repo, number, options = {})
- patch "repos/#{Repository.new(repo)}/issues/#{number}", options.merge({:state => "open"})
+ patch "#{Repository.path repo}/issues/#{number}", options.merge({:state => "open"})
end
# Update an issue
#
- # @param repo [String, Repository, Hash] A GitHub repository
- # @param number [Integer] Number ID of the issue
- # @param title [String] Updated title for the issue
- # @param body [String] Updated body of the issue
- # @param options [Hash] A customizable set of options.
- # @option options [String] :assignee User login.
- # @option options [Integer] :milestone Milestone number.
- # @option options [String] :labels List of comma separated Label names. Example: <tt>bug,ui, at high</tt>.
- # @option options [String] :state State of the issue. <tt>open</tt> or <tt>closed</tt>
+ # @overload update_issue(repo, number, title, body, options)
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
+ # @param number [Integer] Number ID of the issue
+ # @param title [String] Updated title for the issue
+ # @param body [String] Updated body of the issue
+ # @param options [Hash] A customizable set of options.
+ # @option options [String] :assignee User login.
+ # @option options [Integer] :milestone Milestone number.
+ # @option options [String] :labels List of comma separated Label names. Example: <tt>bug,ui, at high</tt>.
+ # @option options [String] :state State of the issue. <tt>open</tt> or <tt>closed</tt>
+ #
+ # @overload update_issue(repo, number, options)
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
+ # @param number [Integer] Number ID of the issue
+ # @param options [Hash] A customizable set of options.
+ # @option options [String] :title Updated title for the issue
+ # @option options [String] :body Updated body of the issue
+ # @option options [String] :assignee User login.
+ # @option options [Integer] :milestone Milestone number.
+ # @option options [String] :labels List of comma separated Label names. Example: <tt>bug,ui, at high</tt>.
+ # @option options [String] :state State of the issue. <tt>open</tt> or <tt>closed</tt>
# @return [Sawyer::Resource] The updated Issue
# @see https://developer.github.com/v3/issues/#edit-an-issue
+ #
# @example Change the title of Issue #25
- # Octokit.update_issue("octokit/octokit.rb", "25", "A new title", "the same body"")
- def update_issue(repo, number, title, body, options = {})
- patch "repos/#{Repository.new(repo)}/issues/#{number}", options.merge({:title => title, :body => body})
+ # Octokit.update_issue("octokit/octokit.rb", "25", "A new title", "the same body")
+ #
+ # @example Change only the assignee of Issue #25
+ # Octokit.update_issue("octokit/octokit.rb", "25", :assignee => "pengwynn")
+ def update_issue(repo, number, *args)
+ arguments = Arguments.new(args)
+ opts = arguments.options
+
+ if arguments.length > 0
+ opts[:title] = arguments.shift
+ opts[:body] = arguments.shift
+ end
+
+ patch "#{Repository.path repo}/issues/#{number}", opts
end
# Get all comments attached to issues for the repository
#
# By default, Issue Comments are ordered by ascending ID.
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param options [Hash] Optional parameters
# @option options [String] :sort created or updated
# @option options [String] :direction asc or desc. Ignored without sort
@@ -190,36 +212,36 @@ module Octokit
# :since => '2010-05-04T23:45:02Z'
# })
def issues_comments(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/issues/comments", options
+ paginate "#{Repository.path repo}/issues/comments", options
end
# Get all comments attached to an issue
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Integer] Number ID of the issue
# @return [Array<Sawyer::Resource>] Array of comments that belong to an issue
# @see https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
# @example Get comments for issue #25 from octokit/octokit.rb
# Octokit.issue_comments("octokit/octokit.rb", "25")
def issue_comments(repo, number, options = {})
- paginate "repos/#{Repository.new(repo)}/issues/#{number}/comments", options
+ paginate "#{Repository.path repo}/issues/#{number}/comments", options
end
# Get a single comment attached to an issue
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Integer] Number ID of the comment
# @return [Sawyer::Resource] The specific comment in question
# @see https://developer.github.com/v3/issues/comments/#get-a-single-comment
# @example Get comment #1194549 from an issue on octokit/octokit.rb
# Octokit.issue_comments("octokit/octokit.rb", 1194549)
def issue_comment(repo, number, options = {})
- paginate "repos/#{Repository.new(repo)}/issues/comments/#{number}", options
+ paginate "#{Repository.path repo}/issues/comments/#{number}", options
end
# Add a comment to an issue
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Integer] Issue number
# @param comment [String] Comment to be added
# @return [Sawyer::Resource] Comment
@@ -227,12 +249,12 @@ module Octokit
# @example Add the comment "Almost to v1" to Issue #23 on octokit/octokit.rb
# Octokit.add_comment("octokit/octokit.rb", 23, "Almost to v1")
def add_comment(repo, number, comment, options = {})
- post "repos/#{Repository.new(repo)}/issues/#{number}/comments", options.merge({:body => comment})
+ post "#{Repository.path repo}/issues/#{number}/comments", options.merge({:body => comment})
end
# Update a single comment on an issue
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Integer] Comment number
# @param comment [String] Body of the comment which will replace the existing body.
# @return [Sawyer::Resource] Comment
@@ -240,19 +262,19 @@ module Octokit
# @example Update the comment #1194549 with body "I've started this on my 25-issue-comments-v3 fork" on an issue on octokit/octokit.rb
# Octokit.update_comment("octokit/octokit.rb", 1194549, "Almost to v1, added this on my fork")
def update_comment(repo, number, comment, options = {})
- patch "repos/#{Repository.new(repo)}/issues/comments/#{number}", options.merge({:body => comment})
+ patch "#{Repository.path repo}/issues/comments/#{number}", options.merge({:body => comment})
end
# Delete a single comment
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Integer] Comment number
# @return [Boolean] Success
# @see https://developer.github.com/v3/issues/comments/#delete-a-comment
# @example Delete the comment #1194549 on an issue on octokit/octokit.rb
# Octokit.delete_comment("octokit/octokit.rb", 1194549)
def delete_comment(repo, number, options = {})
- boolean_from_response :delete, "repos/#{Repository.new(repo)}/issues/comments/#{number}", options
+ boolean_from_response :delete, "#{Repository.path repo}/issues/comments/#{number}", options
end
end
end
diff --git a/lib/octokit/client/labels.rb b/lib/octokit/client/labels.rb
index 74c1a9c..f221fa9 100644
--- a/lib/octokit/client/labels.rb
+++ b/lib/octokit/client/labels.rb
@@ -10,30 +10,30 @@ module Octokit
# List available labels for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @return [Array<Sawyer::Resource>] A list of the labels across the repository
# @see https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
# @example List labels for octokit/octokit.rb
# Octokit.labels("octokit/octokit.rb")
def labels(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/labels", options
+ paginate "#{Repository.path repo}/labels", options
end
# Get single label for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param name [String] Name of the label
# @return [Sawyer::Resource] A single label from the repository
# @see https://developer.github.com/v3/issues/labels/#get-a-single-label
# @example Get the "V3 Addition" label from octokit/octokit.rb
# Octokit.labels("octokit/octokit.rb", "V3 Addition")
def label(repo, name, options = {})
- get "repos/#{Repository.new(repo)}/labels/#{CGI.escape(name)}", options
+ get "#{Repository.path repo}/labels/#{CGI.escape(name)}", options
end
# Add a label to a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param label [String] A new label
# @param color [String] A color, in hex, without the leading #
# @return [Sawyer::Resource] The new label
@@ -41,12 +41,12 @@ module Octokit
# @example Add a new label "Version 1.0" with color "#cccccc"
# Octokit.add_label("octokit/octokit.rb", "Version 1.0", "cccccc")
def add_label(repo, label, color="ffffff", options = {})
- post "repos/#{Repository.new(repo)}/labels", options.merge({:name => label, :color => color})
+ post "#{Repository.path repo}/labels", options.merge({:name => label, :color => color})
end
# Update a label
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param label [String] The name of the label which will be updated
# @param options [Hash] A customizable set of options.
# @option options [String] :name An updated label name
@@ -56,28 +56,28 @@ module Octokit
# @example Update the label "Version 1.0" with new color "#cceeaa"
# Octokit.update_label("octokit/octokit.rb", "Version 1.0", {:color => "cceeaa"})
def update_label(repo, label, options = {})
- patch "repos/#{Repository.new(repo)}/labels/#{CGI.escape(label)}", options
+ patch "#{Repository.path repo}/labels/#{CGI.escape(label)}", options
end
# Delete a label from a repository.
#
# This deletes the label from the repository, and removes it from all issues.
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param label [String] String name of the label
# @return [Boolean] Success
# @see https://developer.github.com/v3/issues/labels/#delete-a-label
# @example Delete the label "Version 1.0" from the repository.
# Octokit.delete_label!("octokit/octokit.rb", "Version 1.0")
def delete_label!(repo, label, options = {})
- boolean_from_response :delete, "repos/#{Repository.new(repo)}/labels/#{CGI.escape(label)}", options
+ boolean_from_response :delete, "#{Repository.path repo}/labels/#{CGI.escape(label)}", options
end
# Remove a label from an Issue
#
# This removes the label from the Issue
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Fixnum] Number ID of the issue
# @param label [String] String name of the label
# @return [Array<Sawyer::Resource>] A list of the labels currently on the issue
@@ -85,38 +85,38 @@ module Octokit
# @example Remove the label "Version 1.0" from the repository.
# Octokit.remove_label("octokit/octokit.rb", 23, "Version 1.0")
def remove_label(repo, number, label, options = {})
- delete "repos/#{Repository.new(repo)}/issues/#{number}/labels/#{CGI.escape(label)}", options
+ delete "#{Repository.path repo}/issues/#{number}/labels/#{CGI.escape(label)}", options
end
# Remove all label from an Issue
#
# This removes the label from the Issue
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Fixnum] Number ID of the issue
# @return [Boolean] Success of operation
# @see https://developer.github.com/v3/issues/labels/#remove-all-labels-from-an-issue
# @example Remove all labels from Issue #23
# Octokit.remove_all_labels("octokit/octokit.rb", 23)
def remove_all_labels(repo, number, options = {})
- boolean_from_response :delete, "repos/#{Repository.new(repo)}/issues/#{number}/labels", options
+ boolean_from_response :delete, "#{Repository.path repo}/issues/#{number}/labels", options
end
# List labels for a given issue
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Fixnum] Number ID of the issue
# @return [Array<Sawyer::Resource>] A list of the labels currently on the issue
# @see https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue
# @example List labels for octokit/octokit.rb, issue # 1
# Octokit.labels_for_issue("octokit/octokit.rb", 1)
def labels_for_issue(repo, number, options = {})
- paginate "repos/#{Repository.new(repo)}/issues/#{number}/labels", options
+ paginate "#{Repository.path repo}/issues/#{number}/labels", options
end
# Add label(s) to an Issue
#
- # @param repo [String, Repository, Hash] A Github repository
+ # @param repo [Integer, String, Repository, Hash] A Github repository
# @param number [Fixnum] Number ID of the issue
# @param labels [Array] An array of labels to apply to this Issue
# @return [Array<Sawyer::Resource>] A list of the labels currently on the issue
@@ -124,12 +124,12 @@ module Octokit
# @example Add two labels for octokit/octokit.rb
# Octokit.add_labels_to_an_issue("octokit/octokit.rb", 10, ['V3 Transition', 'Improvement'])
def add_labels_to_an_issue(repo, number, labels)
- post "repos/#{Repository.new(repo)}/issues/#{number}/labels", labels
+ post "#{Repository.path repo}/issues/#{number}/labels", labels
end
# Replace all labels on an Issue
#
- # @param repo [String, Repository, Hash] A Github repository
+ # @param repo [Integer, String, Repository, Hash] A Github repository
# @param number [Fixnum] Number ID of the issue
# @param labels [Array] An array of labels to use as replacement
# @return [Array<Sawyer::Resource>] A list of the labels currently on the issue
@@ -137,19 +137,19 @@ module Octokit
# @example Replace labels for octokit/octokit.rb Issue #10
# Octokit.replace_all_labels("octokit/octokit.rb", 10, ['V3 Transition', 'Improvement'])
def replace_all_labels(repo, number, labels, options = {})
- put "repos/#{Repository.new(repo)}/issues/#{number}/labels", labels
+ put "#{Repository.path repo}/issues/#{number}/labels", labels
end
# Get labels for every issue in a milestone
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param number [Fixnum] Number ID of the milestone
# @return [Array<Sawyer::Resource>] A list of the labels across the milestone
# @see http://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone
# @example List all labels for milestone #2 on octokit/octokit.rb
# Octokit.labels_for_milestone("octokit/octokit.rb", 2)
def labels_for_milestone(repo, number, options = {})
- paginate "repos/#{Repository.new(repo)}/milestones/#{number}/labels", options
+ paginate "#{Repository.path repo}/milestones/#{number}/labels", options
end
end
end
diff --git a/lib/octokit/client/notifications.rb b/lib/octokit/client/notifications.rb
index 67c6c1e..84c41ad 100644
--- a/lib/octokit/client/notifications.rb
+++ b/lib/octokit/client/notifications.rb
@@ -29,7 +29,7 @@ module Octokit
# List your notifications in a repository
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param options [Hash] Optional parameters
# @option options [Boolean] :all 'true' to show notifications marked as
# read.
@@ -46,7 +46,7 @@ module Octokit
# @example Get your notifications for octokit/octokit.rb since a time.
# @client.repository_notifications({since: '2012-10-09T23:39:01Z'})
def repository_notifications(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/notifications", options
+ paginate "#{Repository.path repo}/notifications", options
end
alias :repo_notifications :repository_notifications
@@ -73,7 +73,7 @@ module Octokit
# Mark notifications from a specific repository as read
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param options [Hash] Optional parameters
# @option options [Boolean] :unread Changes the unread status of the
# threads.
@@ -87,7 +87,7 @@ module Octokit
# @example
# @client.mark_notifications_as_read("octokit/octokit.rb")
def mark_repository_notifications_as_read(repo, options = {})
- request :put, "repos/#{Repository.new(repo)}/notifications", options
+ request :put, "#{Repository.path repo}/notifications", options
last_response.status == 205
end
diff --git a/lib/octokit/client/objects.rb b/lib/octokit/client/objects.rb
index 8166f2f..bbb449e 100644
--- a/lib/octokit/client/objects.rb
+++ b/lib/octokit/client/objects.rb
@@ -10,7 +10,7 @@ module Octokit
#
# Pass <tt>:recursive => true</tt> in <tt>options</tt> to fetch information about all of the tree's objects, including those in subdirectories.
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param tree_sha [String] The SHA of the tree to fetch
# @return [Sawyer::Resource] A hash representing the fetched tree
# @see https://developer.github.com/v3/git/trees/#get-a-tree
@@ -22,14 +22,14 @@ module Octokit
# tree = Octokit.tree("octocat/Hello-World", "fc6274d15fa3ae2ab983129fb037999f264ba9a7", :recursive => true)
# tree.tree.first.path # => "subdir/file.txt"
def tree(repo, tree_sha, options = {})
- get "repos/#{Repository.new(repo)}/git/trees/#{tree_sha}", options
+ get "#{Repository.path repo}/git/trees/#{tree_sha}", options
end
# Create a tree
#
# Pass <tt>:base_tree => "827efc6..."</tt> in <tt>options</tt> to update an existing tree with new data.
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param tree [Array] An array of hashes representing a tree structure
# @return [Sawyer::Resource] A hash representing the new tree
# @see https://developer.github.com/v3/git/trees/#create-a-tree
@@ -39,12 +39,12 @@ module Octokit
# tree.tree.first.path # => "file.rb"
def create_tree(repo, tree, options = {})
parameters = { :tree => tree }
- post "repos/#{Repository.new(repo)}/git/trees", options.merge(parameters)
+ post "#{Repository.path repo}/git/trees", options.merge(parameters)
end
# Get a single blob, fetching its content and encoding
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param blob_sha [String] The SHA of the blob to fetch
# @return [Sawyer::Resource] A hash representing the fetched blob
# @see https://developer.github.com/v3/git/blobs/#get-a-blob
@@ -59,12 +59,12 @@ module Octokit
# blob.content # => "Rm9vIGJhciBiYXo="
# Base64.decode64(blob.content) # => "Foo bar baz"
def blob(repo, blob_sha, options = {})
- get "repos/#{Repository.new(repo)}/git/blobs/#{blob_sha}", options
+ get "#{Repository.path repo}/git/blobs/#{blob_sha}", options
end
# Create a blob
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param content [String] Content of the blob
# @param encoding [String] The content's encoding. <tt>utf-8</tt> and <tt>base64</tt> are accepted. If your data cannot be losslessly sent as a UTF-8 string, you can base64 encode it
# @return [String] The new blob's SHA, e.g. <tt>827efc6d56897b048c772eb4087f854f46256132</tt>
@@ -79,28 +79,28 @@ module Octokit
:content => content,
:encoding => encoding
}
- blob = post "repos/#{Repository.new(repo)}/git/blobs", options.merge(parameters)
+ blob = post "#{Repository.path repo}/git/blobs", options.merge(parameters)
blob.sha
end
# Get a tag
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param tag_sha [String] The SHA of the tag to fetch.
# @return [Sawyer::Resource] Hash representing the tag.
# @see https://developer.github.com/v3/git/tags/#get-a-tag
# @example Fetch a tag
# Octokit.tag('octokit/octokit.rb', '23aad20633f4d2981b1c7209a800db3014774e96')
def tag(repo, tag_sha, options = {})
- get "repos/#{Repository.new(repo)}/git/tags/#{tag_sha}", options
+ get "#{Repository.path repo}/git/tags/#{tag_sha}", options
end
# Create a tag
#
# Requires authenticated client.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param tag [String] Tag string.
# @param message [String] Tag message.
# @param object_sha [String] SHA of the git object this is tagging.
@@ -134,7 +134,7 @@ module Octokit
:date => tagger_date
}
)
- post "repos/#{Repository.new(repo)}/git/tags", options
+ post "#{Repository.path repo}/git/tags", options
end
end
end
diff --git a/lib/octokit/client/organizations.rb b/lib/octokit/client/organizations.rb
index 3799b89..69bb6a0 100644
--- a/lib/octokit/client/organizations.rb
+++ b/lib/octokit/client/organizations.rb
@@ -8,7 +8,7 @@ module Octokit
# Get an organization
#
- # @param org [String] Organization GitHub username.
+ # @param org [String, Integer] Organization GitHub login or id.
# @return [Sawyer::Resource] Hash representing GitHub organization.
# @see https://developer.github.com/v3/orgs/#get-an-organization
# @example
@@ -16,7 +16,7 @@ module Octokit
# @example
# Octokit.org('github')
def organization(org, options = {})
- get "orgs/#{org}", options
+ get Organization.path(org), options
end
alias :org :organization
@@ -24,7 +24,7 @@ module Octokit
#
# Requires authenticated client with proper organization permissions.
#
- # @param org [String] Organization GitHub username.
+ # @param org [String, Integer] Organization GitHub login or id.
# @param values [Hash] The updated organization attributes.
# @option values [String] :billing_email Billing email address. This address is not publicized.
# @option values [String] :company Company name.
@@ -44,7 +44,7 @@ module Octokit
# @example
# @client.update_org('github', {:company => 'Unicorns, Inc.'})
def update_organization(org, values, options = {})
- patch "orgs/#{org}", options.merge({:organization => values})
+ patch Organization.path(org), options.merge({:organization => values})
end
alias :update_org :update_organization
@@ -59,7 +59,8 @@ module Octokit
# Calling this method on a `@client` will return that users organizations.
# Private organizations are included only if the `@client` is authenticated.
#
- # @param user [String] Username of the user to get list of organizations.
+ # @param user [Integer, String] GitHub user login or id of the user to get
+ # list of organizations.
# @return [Array<Sawyer::Resource>] Array of hashes representing organizations.
# @see https://developer.github.com/v3/orgs/#list-user-organizations
# @example
@@ -75,11 +76,7 @@ module Octokit
# @example
# @client.organizations
def organizations(user=nil, options = {})
- if user
- get "users/#{user}/orgs", options
- else
- get "user/orgs", options
- end
+ get "#{User.path user}/orgs", options
end
alias :list_organizations :organizations
alias :list_orgs :organizations
@@ -90,7 +87,8 @@ module Octokit
# Public repositories are available without authentication. Private repos
# require authenticated organization member.
#
- # @param org [String] Organization handle for which to list repos
+ # @param org [String, Integer] Organization GitHub login or id for which
+ # to list repos.
# @option options [String] :type ('all') Filter by repository type.
# `all`, `public`, `member`, `sources`, `forks`, or `private`.
#
@@ -105,7 +103,7 @@ module Octokit
# @example
# @client.org_repos('github', {:type => 'private'})
def organization_repositories(org, options = {})
- paginate "orgs/#{org}/repos", options
+ paginate "#{Organization.path org}/repos", options
end
alias :org_repositories :organization_repositories
alias :org_repos :organization_repositories
@@ -116,7 +114,7 @@ module Octokit
# authenticated client that is a member of the GitHub organization
# is required to get private members.
#
- # @param org [String] Organization GitHub username.
+ # @param org [String, Integer] Organization GitHub login or id.
# @return [Array<Sawyer::Resource>] Array of hashes representing users.
# @see https://developer.github.com/v3/orgs/members/#members-list
# @example
@@ -125,7 +123,7 @@ module Octokit
# Octokit.org_members('github')
def organization_members(org, options = {})
path = "public_" if options.delete(:public)
- paginate "orgs/#{org}/#{path}members", options
+ paginate "#{Organization.path org}/#{path}members", options
end
alias :org_members :organization_members
@@ -151,7 +149,7 @@ module Octokit
# you are a member. If you are not in the organization you are checking,
# use .organization_public_member? instead.
#
- # @param org [String] Organization GitHub username.
+ # @param org [String, Integer] Organization GitHub login or id.
# @param user [String] GitHub username of the user to check.
#
# @return [Boolean] Is a member?
@@ -162,7 +160,7 @@ module Octokit
# @client.organization_member?('your_organization', 'pengwynn')
# => false
def organization_member?(org, user, options = {})
- result = boolean_from_response(:get, "orgs/#{org}/members/#{user}", options)
+ result = boolean_from_response(:get, "#{Organization.path org}/members/#{user}", options)
if !result && last_response && last_response.status == 302
boolean_from_response :get, last_response.headers['Location']
else
@@ -176,7 +174,7 @@ module Octokit
# If you are checking for membership of a user of an organization that
# you are in, use .organization_member? instead.
#
- # @param org [String] Organization GitHub username.
+ # @param org [String, Integer] Organization GitHub login or id.
# @param user [String] GitHub username of the user to check.
#
# @return [Boolean] Is a public member?
@@ -187,7 +185,7 @@ module Octokit
# @client.organization_public_member?('github', 'pengwynn')
# => true
def organization_public_member?(org, user, options = {})
- boolean_from_response :get, "orgs/#{org}/public_members/#{user}", options
+ boolean_from_response :get, "#{Organization.path org}/public_members/#{user}", options
end
alias :org_public_member? :organization_public_member?
@@ -195,7 +193,7 @@ module Octokit
#
# Requires authenticated organization member.
#
- # @param org [String] Organization GitHub username.
+ # @param org [String, Integer] Organization GitHub login or id.
# @return [Array<Sawyer::Resource>] Array of hashes representing teams.
# @see https://developer.github.com/v3/orgs/teams/#list-teams
# @example
@@ -203,7 +201,7 @@ module Octokit
# @example
# @client.org_teams('github')
def organization_teams(org, options = {})
- paginate "orgs/#{org}/teams", options
+ paginate "#{Organization.path org}/teams", options
end
alias :org_teams :organization_teams
@@ -211,7 +209,7 @@ module Octokit
#
# Requires authenticated organization owner.
#
- # @param org [String] Organization GitHub username.
+ # @param org [String, Integer] Organization GitHub login or id.
# @option options [String] :name Team name.
# @option options [Array<String>] :repo_names Repositories for the team.
# @option options [String, optional] :permission ('pull') Permissions the
@@ -229,7 +227,7 @@ module Octokit
# :permission => 'push'
# })
def create_team(org, options = {})
- post "orgs/#{org}/teams", options
+ post "#{Organization.path org}/teams", options
end
# Get team
@@ -304,6 +302,16 @@ module Octokit
# @see https://developer.github.com/v3/orgs/teams/#add-team-member
# @example
# @client.add_team_member(100000, 'pengwynn')
+ #
+ # @example
+ # # Opt-in to future behavior for this endpoint. Adds the member to the
+ # # team if they're already an org member. If not, the method will return
+ # # 422 and indicate the user should call the new Team Membership endpoint.
+ # @client.add_team_member \
+ # 100000,
+ # 'pengwynn',
+ # :accept => "application/vnd.github.the-wasp-preview+json"
+ # @see https://developer.github.com/changes/2014-08-05-team-memberships-api/
def add_team_member(team_id, user, options = {})
# There's a bug in this API call. The docs say to leave the body blank,
# but it fails if the body is both blank and the content-length header
@@ -422,7 +430,7 @@ module Octokit
#
# Requires authenticated organization owner or member with team `admin` access.
#
- # @param org [String] Organization GitHub username.
+ # @param org [String, Integer] Organization GitHub login or id.
# @param user [String] GitHub username of user to remove.
# @return [Boolean] True if removal is successful, false otherwise.
# @see https://developer.github.com/v3/orgs/members/#remove-a-member
@@ -433,7 +441,7 @@ module Octokit
def remove_organization_member(org, user, options = {})
# this is a synonym for: for team in org.teams: remove_team_member(team.id, user)
# provided in the GH API v3
- boolean_from_response :delete, "orgs/#{org}/members/#{user}", options
+ boolean_from_response :delete, "#{Organization.path org}/members/#{user}", options
end
alias :remove_org_member :remove_organization_member
@@ -441,21 +449,21 @@ module Octokit
#
# Requires authenticated organization owner.
#
- # @param org [String] Organization GitHub username.
+ # @param org [String, Integer] Organization GitHub login or id.
# @param user [String] GitHub username of user to publicize.
# @return [Boolean] True if publicization successful, false otherwise.
# @see https://developer.github.com/v3/orgs/members/#publicize-a-users-membership
# @example
# @client.publicize_membership('github', 'pengwynn')
def publicize_membership(org, user, options = {})
- boolean_from_response :put, "orgs/#{org}/public_members/#{user}", options
+ boolean_from_response :put, "#{Organization.path org}/public_members/#{user}", options
end
# Conceal a user's membership of an organization.
#
# Requires authenticated organization owner.
#
- # @param org [String] Organization GitHub username.
+ # @param org [String, Integer] Organization GitHub login or id.
# @param user [String] GitHub username of user to unpublicize.
# @return [Boolean] True of unpublicization successful, false otherwise.
# @see https://developer.github.com/v3/orgs/members/#conceal-a-users-membership
@@ -464,7 +472,7 @@ module Octokit
# @example
# @client.conceal_membership('github', 'pengwynn')
def unpublicize_membership(org, user, options = {})
- boolean_from_response :delete, "orgs/#{org}/public_members/#{user}", options
+ boolean_from_response :delete, "#{Organization.path org}/public_members/#{user}", options
end
alias :conceal_membership :unpublicize_membership
@@ -475,6 +483,78 @@ module Octokit
def user_teams(options = {})
paginate "/user/teams", options
end
+
+ # Check if a user has a team membership.
+ #
+ # @param team_id [Integer] Team id.
+ # @param user [String] GitHub username of the user to check.
+ #
+ # @return [Sawyer::Resource] Hash of team membership info
+ #
+ # @see https://developer.github.com/v3/orgs/teams/#get-team-membership
+ #
+ # @example Check if a user has a membership for a team
+ # @client.team_membership(1234, 'pengwynn')
+ def team_membership(team_id, user, options = {})
+ get "teams/#{team_id}/memberships/#{user}", options
+ end
+
+ # Add or invite a user to a team
+ #
+ # @param team_id [Integer] Team id.
+ # @param user [String] GitHub username of the user to invite.
+ #
+ # @return [Sawyer::Resource] Hash of team membership info
+ #
+ # @see https://developer.github.com/v3/orgs/teams/#add-team-membership
+ #
+ # @example Check if a user has a membership for a team
+ # @client.add_team_membership(1234, 'pengwynn')
+ def add_team_membership(team_id, user, options = {})
+ put "teams/#{team_id}/memberships/#{user}", options
+ end
+
+ # Remove team membership
+ #
+ # @param team_id [Integer] Team id.
+ # @param user [String] GitHub username of the user to boot.
+ # @return [Boolean] True if user removed, false otherwise.
+ # @see https://developer.github.com/v3/orgs/teams/#remove-team-membership
+ # @example
+ # @client.remove_team_membership(100000, 'pengwynn')
+ def remove_team_membership(team_id, user, options = {})
+ boolean_from_response :delete, "teams/#{team_id}/memberships/#{user}", options
+ end
+
+ # List all organizations memberships for the authenticated user
+ #
+ # @return [Array<Sawyer::Resource>] Array of organizations memberships.
+ # @see https://developer.github.com/v3/orgs/members/#list-your-organization-memberships
+ def organization_memberships(options = {})
+ paginate "user/memberships/orgs", options
+ end
+ alias :org_memberships :organization_memberships
+
+ # Get an organization membership for the authenticated user
+ #
+ # @param org [String] Organization GitHub login.
+ # @return [Sawyer::Resource] Hash representing the organization membership.
+ # @see https://developer.github.com/v3/orgs/members/#get-your-organization-membership
+ def organization_membership(org, options = {})
+ get "user/memberships/orgs/#{org}", options
+ end
+ alias :org_membership :organization_membership
+
+ # Edit an organization membership for the authenticated user
+ #
+ # @param org [String] Organization GitHub login.
+ # @option options [String] :state The state that the membership should be in.
+ # @return [Sawyer::Resource] Hash representing the updated organization membership.
+ # @see https://developer.github.com/v3/orgs/members/#edit-your-organization-membership
+ def update_organization_membership(org, options = {})
+ patch "user/memberships/orgs/#{org}", options
+ end
+ alias :update_org_membership :update_organization_membership
end
end
end
diff --git a/lib/octokit/client/pages.rb b/lib/octokit/client/pages.rb
index e75787b..7f49827 100644
--- a/lib/octokit/client/pages.rb
+++ b/lib/octokit/client/pages.rb
@@ -8,30 +8,30 @@ module Octokit
# List Pages information for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @return Sawyer::Resource A GitHub Pages resource
# @see https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site
def pages(repo, options = {})
- get "repos/#{Repository.new(repo)}/pages", options
+ get "#{Repository.path repo}/pages", options
end
# List Pages builds for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @return [Array<Sawyer::Resource>] A list of build history for a repository.
# @see https://developer.github.com/v3/repos/pages/#list-pages-builds
def pages_builds(repo, options = {})
- get "repos/#{Repository.new(repo)}/pages/builds", options
+ get "#{Repository.path repo}/pages/builds", options
end
alias :list_pages_builds :pages_builds
# List the latest Pages build information for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @return Sawyer::Resource A GitHub Pages resource about a build
# @see https://developer.github.com/v3/repos/pages/#list-latest-pages-build
def latest_pages_build(repo, options = {})
- get "repos/#{Repository.new(repo)}/pages/builds/latest", options
+ get "#{Repository.path repo}/pages/builds/latest", options
end
end
end
diff --git a/lib/octokit/client/pull_requests.rb b/lib/octokit/client/pull_requests.rb
index 73358b0..9adc8e1 100644
--- a/lib/octokit/client/pull_requests.rb
+++ b/lib/octokit/client/pull_requests.rb
@@ -9,12 +9,12 @@ module Octokit
# List pull requests for a repository
#
# @overload pull_requests(repo, options)
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param options [Hash] Method options
# @option options [String] :state `open` or `closed`.
# @overload pull_requests(repo, state, options)
# @deprecated
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param state [String] `open` or `closed`.
# @param options [Hash] Method options
# @return [Array<Sawyer::Resource>] Array of pulls
@@ -29,25 +29,25 @@ module Octokit
octokit_warn "DEPRECATED: Client#pull_requests: Passing state as positional argument is deprecated. Please use :state => '#{state}'"
opts[:state] = state if state
end
- paginate "repos/#{Repository.new(repo)}/pulls", opts
+ paginate "#{Repository.path repo}/pulls", opts
end
alias :pulls :pull_requests
# Get a pull request
#
# @see https://developer.github.com/v3/pulls/#get-a-single-pull-request
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param number [Integer] Number of the pull request to fetch
# @return [Sawyer::Resource] Pull request info
def pull_request(repo, number, options = {})
- get "repos/#{Repository.new(repo)}/pulls/#{number}", options
+ get "#{Repository.path repo}/pulls/#{number}", options
end
alias :pull :pull_request
# Create a pull request
#
# @see https://developer.github.com/v3/pulls/#create-a-pull-request
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param base [String] The branch (or git ref) you want your changes
# pulled into. This should be an existing branch on the current
# repository. You cannot submit a pull request to one repo that requests
@@ -56,6 +56,9 @@ module Octokit
# @param title [String] Title for the pull request
# @param body [String] The body for the pull request. Supports GFM.
# @return [Sawyer::Resource] The newly created pull request
+ # @example
+ # @client.create_pull_request("octokit/octokit.rb", "master", "feature-branch",
+ # "Pull Request title", "Pull Request body")
def create_pull_request(repo, base, head, title, body, options = {})
pull = {
:base => base,
@@ -63,13 +66,13 @@ module Octokit
:title => title,
:body => body,
}
- post "repos/#{Repository.new(repo)}/pulls", options.merge(pull)
+ post "#{Repository.path repo}/pulls", options.merge(pull)
end
# Create a pull request from existing issue
#
# @see https://developer.github.com/v3/pulls/#alternative-input
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param base [String] The branch (or git ref) you want your changes
# pulled into. This should be an existing branch on the current
# repository. You cannot submit a pull request to one repo that requests
@@ -83,19 +86,19 @@ module Octokit
:head => head,
:issue => issue
}
- post "repos/#{Repository.new(repo)}/pulls", options.merge(pull)
+ post "#{Repository.path repo}/pulls", options.merge(pull)
end
# Update a pull request
# @overload update_pull_request(repo, id, title=nil, body=nil, state=nil, options = {})
# @deprecated
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param number [Integer] Number of pull request to update.
# @param title [String] Title for the pull request.
# @param body [String] Body content for pull request. Supports GFM.
# @param state [String] State of the pull request. `open` or `closed`.
# @overload update_pull_request(repo, id, options = {})
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param number [Integer] Number of pull request to update.
# @option options [String] :title Title for the pull request.
# @option options [String] :body Body for the pull request.
@@ -112,12 +115,12 @@ module Octokit
arguments = Octokit::Arguments.new(args)
repo = arguments.shift
number = arguments.shift
- patch "repos/#{Repository.new(repo)}/pulls/#{number}", arguments.options
+ patch "#{Repository.path repo}/pulls/#{number}", arguments.options
end
# Close a pull request
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param number [Integer] Number of pull request to update.
# @return [Sawyer::Resource] Hash representing updated pull request.
# @see https://developer.github.com/v3/pulls/#update-a-pull-request
@@ -131,11 +134,11 @@ module Octokit
# List commits on a pull request
#
# @see https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param number [Integer] Number of pull request
# @return [Array<Sawyer::Resource>] List of commits
def pull_request_commits(repo, number, options = {})
- paginate "repos/#{Repository.new(repo)}/pulls/#{number}/commits", options
+ paginate "#{Repository.path repo}/pulls/#{number}/commits", options
end
alias :pull_commits :pull_request_commits
@@ -143,7 +146,7 @@ module Octokit
#
# By default, Review Comments are ordered by ascending ID.
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param options [Hash] Optional parameters
# @option options [String] :sort created or updated
# @option options [String] :direction asc or desc. Ignored without sort
@@ -165,41 +168,41 @@ module Octokit
# :since => '2010-05-04T23:45:02Z'
# })
def pull_requests_comments(repo, options = {})
- get("repos/#{Repository.new(repo)}/pulls/comments", options)
+ paginate("#{Repository.path repo}/pulls/comments", options)
end
alias :pulls_comments :pull_requests_comments
alias :reviews_comments :pull_requests_comments
# List comments on a pull request
#
- # @see https://developer.github.com/v3/pulls/#list-comments-on-a-pull-request
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @see https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param number [Integer] Number of pull request
# @return [Array<Sawyer::Resource>] List of comments
def pull_request_comments(repo, number, options = {})
# return the comments for a pull request
- get "repos/#{Repository.new(repo)}/pulls/#{number}/comments", options
+ get "#{Repository.path repo}/pulls/#{number}/comments", options
end
alias :pull_comments :pull_request_comments
alias :review_comments :pull_request_comments
# Get a pull request comment
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param comment_id [Integer] Id of comment to get
# @return [Sawyer::Resource] Hash representing the comment
# @see https://developer.github.com/v3/pulls/comments/#get-a-single-comment
# @example
# @client.pull_request_comment("pengwynn/octkit", 1903950)
def pull_request_comment(repo, comment_id, options = {})
- get "repos/#{Repository.new(repo)}/pulls/comments/#{comment_id}", options
+ get "#{Repository.path repo}/pulls/comments/#{comment_id}", options
end
alias :pull_comment :pull_request_comment
alias :review_comment :pull_request_comment
# Create a pull request comment
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param pull_id [Integer] Pull request id
# @param body [String] Comment content
# @param commit_id [String] Sha of the commit to comment on.
@@ -217,14 +220,14 @@ module Octokit
:path => path,
:position => position
})
- post "repos/#{Repository.new(repo)}/pulls/#{pull_id}/comments", options
+ post "#{Repository.path repo}/pulls/#{pull_id}/comments", options
end
alias :create_pull_comment :create_pull_request_comment
alias :create_view_comment :create_pull_request_comment
# Create reply to a pull request comment
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param pull_id [Integer] Pull request id
# @param body [String] Comment contents
# @param comment_id [Integer] Comment id to reply to
@@ -237,14 +240,14 @@ module Octokit
:body => body,
:in_reply_to => comment_id
})
- post "repos/#{Repository.new(repo)}/pulls/#{pull_id}/comments", options
+ post "#{Repository.path repo}/pulls/#{pull_id}/comments", options
end
alias :create_pull_reply :create_pull_request_comment_reply
alias :create_review_reply :create_pull_request_comment_reply
# Update pull request comment
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param comment_id [Integer] Id of the comment to update
# @param body [String] Updated comment content
# @return [Sawyer::Resource] Hash representing the updated comment
@@ -253,21 +256,21 @@ module Octokit
# @client.update_pull_request_comment("octokit/octokit.rb", 1903950, ":shipit:")
def update_pull_request_comment(repo, comment_id, body, options = {})
options.merge! :body => body
- patch("repos/#{Repository.new(repo)}/pulls/comments/#{comment_id}", options)
+ patch("#{Repository.path repo}/pulls/comments/#{comment_id}", options)
end
alias :update_pull_comment :update_pull_request_comment
alias :update_review_comment :update_pull_request_comment
# Delete pull request comment
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param comment_id [Integer] Id of the comment to delete
# @return [Boolean] True if deleted, false otherwise
# @see https://developer.github.com/v3/pulls/comments/#delete-a-comment
# @example
# @client.delete_pull_request_comment("octokit/octokit.rb", 1902707)
def delete_pull_request_comment(repo, comment_id, options = {})
- boolean_from_response(:delete, "repos/#{Repository.new(repo)}/pulls/comments/#{comment_id}", options)
+ boolean_from_response(:delete, "#{Repository.path repo}/pulls/comments/#{comment_id}", options)
end
alias :delete_pull_comment :delete_pull_request_comment
alias :delete_review_comment :delete_pull_request_comment
@@ -275,33 +278,33 @@ module Octokit
# List files on a pull request
#
# @see https://developer.github.com/v3/pulls/#list-pull-requests-files
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param number [Integer] Number of pull request
# @return [Array<Sawyer::Resource>] List of files
def pull_request_files(repo, number, options = {})
- paginate "repos/#{Repository.new(repo)}/pulls/#{number}/files", options
+ paginate "#{Repository.path repo}/pulls/#{number}/files", options
end
alias :pull_files :pull_request_files
# Merge a pull request
#
# @see https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-buttontrade
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param number [Integer] Number of pull request
# @param commit_message [String] Optional commit message for the merge commit
# @return [Array<Sawyer::Resource>] Merge commit info if successful
def merge_pull_request(repo, number, commit_message='', options = {})
- put "repos/#{Repository.new(repo)}/pulls/#{number}/merge", options.merge({:commit_message => commit_message})
+ put "#{Repository.path repo}/pulls/#{number}/merge", options.merge({:commit_message => commit_message})
end
# Check pull request merge status
#
# @see https://developer.github.com/v3/pulls/#get-if-a-pull-request-has-been-merged
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param number [Integer] Number of pull request
# @return [Boolean] True if the pull request has been merged
def pull_merged?(repo, number, options = {})
- boolean_from_response :get, "repos/#{Repository.new(repo)}/pulls/#{number}/merge", options
+ boolean_from_response :get, "#{Repository.path repo}/pulls/#{number}/merge", options
end
alias :pull_request_merged? :pull_merged?
diff --git a/lib/octokit/client/refs.rb b/lib/octokit/client/refs.rb
index f390ac0..ae005e6 100644
--- a/lib/octokit/client/refs.rb
+++ b/lib/octokit/client/refs.rb
@@ -8,14 +8,14 @@ module Octokit
# List all refs for a given user and repo
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param namespace [String] The ref namespace, e.g. <tt>tag</tt> or <tt>heads</tt>
# @return [Array<Sawyer::Resource>] A list of references matching the repo and the namespace
# @see https://developer.github.com/v3/git/refs/#get-all-references
# @example Fetch all refs for sferik/rails_admin
# Octokit.refs("sferik/rails_admin")
def refs(repo, namespace = nil, options = {})
- path = "repos/#{Repository.new(repo)}/git/refs"
+ path = "#{Repository.path repo}/git/refs"
path += "/#{namespace}" unless namespace.nil?
paginate path, options
end
@@ -25,20 +25,20 @@ module Octokit
# Fetch a given reference
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
# @return [Sawyer::Resource] The reference matching the given repo and the ref id
# @see https://developer.github.com/v3/git/refs/#get-a-reference
# @example Fetch tags/v0.0.3 for sferik/rails_admin
# Octokit.ref("sferik/rails_admin","tags/v0.0.3")
def ref(repo, ref, options = {})
- get "repos/#{Repository.new(repo)}/git/refs/#{ref}", options
+ get "#{Repository.path repo}/git/refs/#{ref}", options
end
alias :reference :ref
# Create a reference
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
# @param sha [String] A SHA, e.g. <tt>827efc6d56897b048c772eb4087f854f46256132</tt>
# @return [Array<Sawyer::Resource>] The list of references, already containing the new one
@@ -50,13 +50,13 @@ module Octokit
:ref => "refs/#{ref}",
:sha => sha
}
- post "repos/#{Repository.new(repo)}/git/refs", options.merge(parameters)
+ post "#{Repository.path repo}/git/refs", options.merge(parameters)
end
alias :create_reference :create_ref
# Update a reference
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
# @param sha [String] A SHA, e.g. <tt>827efc6d56897b048c772eb4087f854f46256132</tt>
# @param force [Boolean] A flag indicating one wants to force the update to make sure the update is a fast-forward update.
@@ -69,13 +69,13 @@ module Octokit
:sha => sha,
:force => force
}
- patch "repos/#{Repository.new(repo)}/git/refs/#{ref}", options.merge(parameters)
+ patch "#{Repository.path repo}/git/refs/#{ref}", options.merge(parameters)
end
alias :update_reference :update_ref
# Update a branch
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param branch [String] The ref, e.g. <tt>feature/new-shiny</tt>
# @param sha [String] A SHA, e.g. <tt>827efc6d56897b048c772eb4087f854f46256132</tt>
# @param force [Boolean] A flag indicating one wants to force the update to make sure the update is a fast-forward update.
@@ -89,7 +89,7 @@ module Octokit
# Delete a single branch
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param branch [String] The branch, e.g. <tt>fix-refs</tt>
# @return [Boolean] Success
# @see https://developer.github.com/v3/git/refs/#delete-a-reference
@@ -101,14 +101,14 @@ module Octokit
# Delete a single reference
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
# @return [Boolean] Success
# @see https://developer.github.com/v3/git/refs/#delete-a-reference
# @example Delete tags/v0.0.3 for sferik/rails_admin
# Octokit.delete_ref("sferik/rails_admin","tags/v0.0.3")
def delete_ref(repo, ref, options = {})
- boolean_from_response :delete, "repos/#{Repository.new(repo)}/git/refs/#{ref}", options
+ boolean_from_response :delete, "#{Repository.path repo}/git/refs/#{ref}", options
end
alias :delete_reference :delete_ref
diff --git a/lib/octokit/client/releases.rb b/lib/octokit/client/releases.rb
index f184288..95114ed 100644
--- a/lib/octokit/client/releases.rb
+++ b/lib/octokit/client/releases.rb
@@ -8,17 +8,17 @@ module Octokit
# List releases for a repository
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @return [Array<Sawyer::Resource>] A list of releases
# @see https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository
def releases(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/releases", options
+ paginate "#{Repository.path repo}/releases", options
end
alias :list_releases :releases
# Create a release
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param tag_name [String] Git tag from which to create release
# @option options [String] :target_commitish Specifies the commitish value that determines where the Git tag is created from.
# @option options [String] :name Name for the release
@@ -29,7 +29,7 @@ module Octokit
# @see https://developer.github.com/v3/repos/releases/#create-a-release
def create_release(repo, tag_name, options = {})
opts = options.merge(:tag_name => tag_name)
- post "repos/#{Repository.new(repo)}/releases", opts
+ post "#{Repository.path repo}/releases", opts
end
# Get a release
diff --git a/lib/octokit/client/repositories.rb b/lib/octokit/client/repositories.rb
index 4897413..dbe65ae 100644
--- a/lib/octokit/client/repositories.rb
+++ b/lib/octokit/client/repositories.rb
@@ -9,7 +9,7 @@ module Octokit
# Check if a repository exists
#
# @see https://developer.github.com/v3/repos/#get
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Sawyer::Resource] if a repository exists, false otherwise
def repository?(repo, options = {})
!!repository(repo, options)
@@ -20,10 +20,10 @@ module Octokit
# Get a single repository
#
# @see https://developer.github.com/v3/repos/#get
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Sawyer::Resource] Repository information
def repository(repo, options = {})
- get "repos/#{Repository.new(repo)}", options
+ get Repository.path(repo), options
end
alias :repo :repository
@@ -52,23 +52,20 @@ module Octokit
# List user repositories
#
- # If username is not supplied, repositories for the current
+ # If user is not supplied, repositories for the current
# authenticated user are returned.
#
- # @note If the username provided is a GitHub organization, only the
+ # @note If the user provided is a GitHub organization, only the
# organization's public repositories will be listed. For retrieving
# organization repositories the {Organizations#organization_repositories}
# method should be used instead.
# @see https://developer.github.com/v3/repos/#list-your-repositories
# @see https://developer.github.com/v3/repos/#list-user-repositories
- # @param username [String] Optional username for which to list repos
+ # @param user [Integer, String] Optional GitHub user login or id for which
+ # to list repos.
# @return [Array<Sawyer::Resource>] List of repositories
- def repositories(username=nil, options = {})
- if username.nil?
- paginate 'user/repos', options
- else
- paginate "users/#{username}/repos", options
- end
+ def repositories(user=nil, options = {})
+ paginate "#{User.path user}/repos", options
end
alias :list_repositories :repositories
alias :list_repos :repositories
@@ -129,11 +126,11 @@ module Octokit
# Fork a repository
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Sawyer::Resource] Repository info for the new fork
# @see https://developer.github.com/v3/repos/forks/#create-a-fork
def fork(repo, options = {})
- post "repos/#{Repository.new(repo)}/forks", options
+ post "#{Repository.path repo}/forks", options
end
# Create a repository for a user or organization
@@ -169,16 +166,16 @@ module Octokit
# Note: If OAuth is used, 'delete_repo' scope is required
#
# @see https://developer.github.com/v3/repos/#delete-a-repository
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Boolean] `true` if repository was deleted
def delete_repository(repo, options = {})
- boolean_from_response :delete, "repos/#{Repository.new(repo)}", options
+ boolean_from_response :delete, Repository.path(repo), options
end
alias :delete_repo :delete_repository
# Hide a public repository
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Sawyer::Resource] Updated repository info
def set_private(repo, options = {})
# GitHub Api for setting private updated to use private attr, rather than public
@@ -187,7 +184,7 @@ module Octokit
# Unhide a private repository
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Sawyer::Resource] Updated repository info
def set_public(repo, options = {})
# GitHub Api for setting private updated to use private attr, rather than public
@@ -198,7 +195,7 @@ module Octokit
#
# Requires authenticated client.
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Array<Sawyer::Resource>] Array of hashes representing deploy keys.
# @see https://developer.github.com/v3/repos/keys/#list
# @example
@@ -206,27 +203,27 @@ module Octokit
# @example
# @client.list_deploy_keys('octokit/octokit.rb')
def deploy_keys(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/keys", options
+ paginate "#{Repository.path repo}/keys", options
end
alias :list_deploy_keys :deploy_keys
# Get a single deploy key for a repo
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param id [Integer] Deploy key ID.
# @return [Sawyer::Resource] Deploy key.
# @see https://developer.github.com/v3/repos/keys/#get
# @example
# @client.deploy_key('octokit/octokit.rb', 8675309)
def deploy_key(repo, id, options={})
- get "repos/#{Repository.new(repo)}/keys/#{id}", options
+ get "#{Repository.path repo}/keys/#{id}", options
end
# Add deploy key to a repo
#
# Requires authenticated client.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param title [String] Title reference for the deploy key.
# @param key [String] Public key.
# @return [Sawyer::Resource] Hash representing newly added key.
@@ -234,24 +231,26 @@ module Octokit
# @example
# @client.add_deploy_key('octokit/octokit.rb', 'Staging server', 'ssh-rsa AAA...')
def add_deploy_key(repo, title, key, options = {})
- post "repos/#{Repository.new(repo)}/keys", options.merge(:title => title, :key => key)
+ post "#{Repository.path repo}/keys", options.merge(:title => title, :key => key)
end
# Edit a deploy key
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param id [Integer] Deploy key ID.
# @param options [Hash] Attributes to edit.
# @option title [String] Key title.
# @option key [String] Public key.
# @return [Sawyer::Resource] Updated deploy key.
+ # @deprecated This method is no longer supported in the API
+ # @see https://developer.github.com/changes/2014-02-24-finer-grained-scopes-for-ssh-keys/
# @see https://developer.github.com/v3/repos/keys/#edit
# @example Update the key for a deploy key.
# @client.edit_deploy_key('octokit/octokit.rb', 8675309, :key => 'ssh-rsa BBB...')
# @example
# @client.update_deploy_key('octokit/octokit.rb', 8675309, :title => 'Uber', :key => 'ssh-rsa BBB...'))
def edit_deploy_key(repo, id, options)
- patch "repos/#{Repository.new(repo)}/keys/#{id}", options
+ patch "#{Repository.path repo}/keys/#{id}", options
end
alias :update_deploy_key :edit_deploy_key
@@ -259,21 +258,21 @@ module Octokit
#
# Requires authenticated client.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param id [Integer] Id of the deploy key to remove.
# @return [Boolean] True if key removed, false otherwise.
# @see https://developer.github.com/v3/repos/keys/#delete
# @example
# @client.remove_deploy_key('octokit/octokit.rb', 100000)
def remove_deploy_key(repo, id, options = {})
- boolean_from_response :delete, "repos/#{Repository.new(repo)}/keys/#{id}", options
+ boolean_from_response :delete, "#{Repository.path repo}/keys/#{id}", options
end
# List collaborators
#
# Requires authenticated client for private repos.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Array<Sawyer::Resource>] Array of hashes representing collaborating users.
# @see https://developer.github.com/v3/repos/collaborators/#list
# @example
@@ -283,7 +282,7 @@ module Octokit
# @example
# @client.collabs('octokit/octokit.rb')
def collaborators(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/collaborators", options
+ paginate "#{Repository.path repo}/collaborators", options
end
alias :collabs :collaborators
@@ -291,7 +290,7 @@ module Octokit
#
# Requires authenticated client.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param collaborator [String] Collaborator GitHub username to add.
# @return [Boolean] True if collaborator added, false otherwise.
# @see https://developer.github.com/v3/repos/collaborators/#add-collaborator
@@ -300,7 +299,7 @@ module Octokit
# @example
# @client.add_collab('octokit/octokit.rb', 'holman')
def add_collaborator(repo, collaborator, options = {})
- boolean_from_response :put, "repos/#{Repository.new(repo)}/collaborators/#{collaborator}", options
+ boolean_from_response :put, "#{Repository.path repo}/collaborators/#{collaborator}", options
end
alias :add_collab :add_collaborator
@@ -308,7 +307,7 @@ module Octokit
#
# Requires authenticated client.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param collaborator [String] Collaborator GitHub username to remove.
# @return [Boolean] True if collaborator removed, false otherwise.
# @see https://developer.github.com/v3/repos/collaborators/#remove-collaborator
@@ -317,7 +316,7 @@ module Octokit
# @example
# @client.remove_collab('octokit/octokit.rb', 'holman')
def remove_collaborator(repo, collaborator, options = {})
- boolean_from_response :delete, "repos/#{Repository.new(repo)}/collaborators/#{collaborator}", options
+ boolean_from_response :delete, "#{Repository.path repo}/collaborators/#{collaborator}", options
end
alias :remove_collab :remove_collaborator
@@ -325,21 +324,21 @@ module Octokit
#
# Requires authenticated client.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param collaborator [String] Collaborator GitHub username to check.
# @return [Boolean] True if user is a collaborator, false otherwise.
# @see https://developer.github.com/v3/repos/collaborators/#get
# @example
# @client.collaborator?('octokit/octokit.rb', 'holman')
def collaborator?(repo, collaborator, options={})
- boolean_from_response :get, "repos/#{Repository.new(repo)}/collaborators/#{collaborator}", options
+ boolean_from_response :get, "#{Repository.path repo}/collaborators/#{collaborator}", options
end
# List teams for a repo
#
# Requires authenticated client that is an owner or collaborator of the repo.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Array<Sawyer::Resource>] Array of hashes representing teams.
# @see https://developer.github.com/v3/repos/#list-teams
# @example
@@ -349,7 +348,7 @@ module Octokit
# @example
# @client.teams('octokit/pengwynn')
def repository_teams(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/teams", options
+ paginate "#{Repository.path repo}/teams", options
end
alias :repo_teams :repository_teams
alias :teams :repository_teams
@@ -358,8 +357,8 @@ module Octokit
#
# Requires authenticated client for private repos.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
- # @param anon [Boolean] Set true to include annonymous contributors.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
+ # @param anon [Boolean] Set true to include anonymous contributors.
# @return [Array<Sawyer::Resource>] Array of hashes representing users.
# @see https://developer.github.com/v3/repos/#list-contributors
# @example
@@ -370,7 +369,7 @@ module Octokit
# @client.contribs('octokit/octokit.rb')
def contributors(repo, anon = nil, options = {})
options[:anon] = 1 if anon.to_s[/1|true/]
- paginate "repos/#{Repository.new(repo)}/contributors", options
+ paginate "#{Repository.path repo}/contributors", options
end
alias :contribs :contributors
@@ -378,7 +377,7 @@ module Octokit
#
# Requires authenticated client for private repos.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Array<Sawyer::Resource>] Array of hashes representing users.
# @see https://developer.github.com/v3/activity/starring/#list-stargazers
# @example
@@ -386,7 +385,7 @@ module Octokit
# @example
# @client.stargazers('octokit/octokit.rb')
def stargazers(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/stargazers", options
+ paginate "#{Repository.path repo}/stargazers", options
end
# @deprecated Use {#stargazers} instead
@@ -395,7 +394,7 @@ module Octokit
#
# Requires authenticated client for private repos.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Array<Sawyer::Resource>] Array of hashes representing users.
# @see https://developer.github.com/v3/repos/watching/#list-watchers
# @example
@@ -403,14 +402,14 @@ module Octokit
# @example
# @client.watchers('octokit/octokit.rb')
def watchers(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/watchers", options
+ paginate "#{Repository.path repo}/watchers", options
end
# List forks
#
# Requires authenticated client for private repos.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Array<Sawyer::Resource>] Array of hashes representing repos.
# @see https://developer.github.com/v3/repos/forks/#list-forks
# @example
@@ -420,7 +419,7 @@ module Octokit
# @example
# @client.forks('octokit/octokit.rb')
def forks(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/forks", options
+ paginate "#{Repository.path repo}/forks", options
end
alias :network :forks
@@ -428,22 +427,22 @@ module Octokit
#
# Requires authenticated client for private repos.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Array<Sawyer::Resource>] Array of Hashes representing languages.
# @see https://developer.github.com/v3/repos/#list-languages
# @example
- # Octokit.langauges('octokit/octokit.rb')
+ # Octokit.languages('octokit/octokit.rb')
# @example
# @client.languages('octokit/octokit.rb')
def languages(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/languages", options
+ paginate "#{Repository.path repo}/languages", options
end
# List tags
#
# Requires authenticated client for private repos.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Array<Sawyer::Resource>] Array of hashes representing tags.
# @see https://developer.github.com/v3/repos/#list-tags
# @example
@@ -451,14 +450,14 @@ module Octokit
# @example
# @client.tags('octokit/octokit.rb')
def tags(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/tags", options
+ paginate "#{Repository.path repo}/tags", options
end
# List branches
#
# Requires authenticated client for private repos.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Array<Sawyer::Resource>] Array of hashes representing branches.
# @see https://developer.github.com/v3/repos/#list-branches
# @example
@@ -466,161 +465,27 @@ module Octokit
# @example
# @client.branches('octokit/octokit.rb')
def branches(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/branches", options
+ paginate "#{Repository.path repo}/branches", options
end
# Get a single branch from a repository
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param branch [String] Branch name
# @return [Sawyer::Resource] The branch requested, if it exists
# @see https://developer.github.com/v3/repos/#get-branch
# @example Get branch 'master` from octokit/octokit.rb
# Octokit.branch("octokit/octokit.rb", "master")
def branch(repo, branch, options = {})
- get "repos/#{Repository.new(repo)}/branches/#{branch}", options
+ get "#{Repository.path repo}/branches/#{branch}", options
end
alias :get_branch :branch
- # List repo hooks
- #
- # Requires authenticated client.
- #
- # @param repo [String, Hash, Repository] A GitHub repository.
- # @return [Array<Sawyer::Resource>] Array of hashes representing hooks.
- # @see https://developer.github.com/v3/repos/hooks/#list-hooks
- # @example
- # @client.hooks('octokit/octokit.rb')
- def hooks(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/hooks", options
- end
-
- # Get single hook
- #
- # Requires authenticated client.
- #
- # @param repo [String, Hash, Repository] A GitHub repository.
- # @param id [Integer] Id of the hook to get.
- # @return [Sawyer::Resource] Hash representing hook.
- # @see https://developer.github.com/v3/repos/hooks/#get-single-hook
- # @example
- # @client.hook('octokit/octokit.rb', 100000)
- def hook(repo, id, options = {})
- get "repos/#{Repository.new(repo)}/hooks/#{id}", options
- end
-
- # Create a hook
- #
- # Requires authenticated client.
- #
- # @param repo [String, Hash, Repository] A GitHub repository.
- # @param name [String] The name of the service that is being called. See
- # {https://api.github.com/hooks Hooks} for the possible names.
- # @param config [Hash] A Hash containing key/value pairs to provide
- # settings for this hook. These settings vary between the services and
- # are defined in the {https://github.com/github/github-services github-services} repo.
- # @option options [Array<String>] :events ('["push"]') Determines what
- # events the hook is triggered for.
- # @option options [Boolean] :active Determines whether the hook is
- # actually triggered on pushes.
- # @return [Sawyer::Resource] Hook info for the new hook
- # @see https://api.github.com/hooks
- # @see https://github.com/github/github-services
- # @see https://developer.github.com/v3/repos/hooks/#create-a-hook
- # @example
- # @client.create_hook(
- # 'octokit/octokit.rb',
- # 'web',
- # {
- # :url => 'http://something.com/webhook',
- # :content_type => 'json'
- # },
- # {
- # :events => ['push', 'pull_request'],
- # :active => true
- # }
- # )
- def create_hook(repo, name, config, options = {})
- options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
- post "repos/#{Repository.new(repo)}/hooks", options
- end
-
- # Edit a hook
- #
- # Requires authenticated client.
- #
- # @param repo [String, Hash, Repository] A GitHub repository.
- # @param id [Integer] Id of the hook being updated.
- # @param name [String] The name of the service that is being called. See
- # {https://api.github.com/hooks Hooks} for the possible names.
- # @param config [Hash] A Hash containing key/value pairs to provide
- # settings for this hook. These settings vary between the services and
- # are defined in the {https://github.com/github/github-services github-services} repo.
- # @option options [Array<String>] :events ('["push"]') Determines what
- # events the hook is triggered for.
- # @option options [Array<String>] :add_events Determines a list of events
- # to be added to the list of events that the Hook triggers for.
- # @option options [Array<String>] :remove_events Determines a list of events
- # to be removed from the list of events that the Hook triggers for.
- # @option options [Boolean] :active Determines whether the hook is
- # actually triggered on pushes.
- # @return [Sawyer::Resource] Hook info for the updated hook
- # @see https://api.github.com/hooks
- # @see https://github.com/github/github-services
- # @see https://developer.github.com/v3/repos/hooks/#edit-a-hook
- # @example
- # @client.edit_hook(
- # 'octokit/octokit.rb',
- # 100000,
- # 'web',
- # {
- # :url => 'http://something.com/webhook',
- # :content_type => 'json'
- # },
- # {
- # :add_events => ['status'],
- # :remove_events => ['pull_request'],
- # :active => true
- # }
- # )
- def edit_hook(repo, id, name, config, options = {})
- options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
- patch "repos/#{Repository.new(repo)}/hooks/#{id}", options
- end
-
- # Delete hook
- #
- # Requires authenticated client.
- #
- # @param repo [String, Hash, Repository] A GitHub repository.
- # @param id [Integer] Id of the hook to remove.
- # @return [Boolean] True if hook removed, false otherwise.
- # @see https://developer.github.com/v3/repos/hooks/#delete-a-hook
- # @example
- # @client.remove_hook('octokit/octokit.rb', 1000000)
- def remove_hook(repo, id, options = {})
- boolean_from_response :delete, "repos/#{Repository.new(repo)}/hooks/#{id}", options
- end
-
- # Test hook
- #
- # Requires authenticated client.
- #
- # @param repo [String, Hash, Repository] A GitHub repository.
- # @param id [Integer] Id of the hook to test.
- # @return [Boolean] Success
- # @see https://developer.github.com/v3/repos/hooks/#test-a-push-hook
- # @example
- # @client.test_hook('octokit/octokit.rb', 1000000)
- def test_hook(repo, id, options = {})
- boolean_from_response :post, "repos/#{Repository.new(repo)}/hooks/#{id}/tests", options
- end
-
# List users available for assigning to issues.
#
# Requires authenticated client for private repos.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Array<Sawyer::Resource>] Array of hashes representing users.
# @see https://developer.github.com/v3/issues/assignees/#list-assignees
# @example
@@ -630,47 +495,47 @@ module Octokit
# @example
# @client.repository_assignees('octokit/octokit.rb')
def repository_assignees(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/assignees", options
+ paginate "#{Repository.path repo}/assignees", options
end
alias :repo_assignees :repository_assignees
# Check to see if a particular user is an assignee for a repository.
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param assignee [String] User login to check
# @return [Boolean] True if assignable on project, false otherwise.
# @see https://developer.github.com/v3/issues/assignees/#check-assignee
# @example
# Octokit.check_assignee('octokit/octokit.rb', 'andrew')
def check_assignee(repo, assignee, options = {})
- boolean_from_response :get, "repos/#{Repository.new(repo)}/assignees/#{assignee}", options
+ boolean_from_response :get, "#{Repository.path repo}/assignees/#{assignee}", options
end
# List watchers subscribing to notifications for a repo
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Array<Sawyer::Resource>] Array of users watching.
# @see https://developer.github.com/v3/activity/watching/#list-watchers
# @example
# @client.subscribers("octokit/octokit.rb")
def subscribers(repo, options = {})
- paginate "repos/#{Repository.new(repo)}/subscribers", options
+ paginate "#{Repository.path repo}/subscribers", options
end
# Get a repository subscription
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Sawyer::Resource] Repository subscription.
# @see https://developer.github.com/v3/activity/watching/#get-a-repository-subscription
# @example
# @client.subscription("octokit/octokit.rb")
def subscription(repo, options = {})
- get "repos/#{Repository.new(repo)}/subscription", options
+ get "#{Repository.path repo}/subscription", options
end
# Update repository subscription
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param options [Hash]
#
# @option options [Boolean] :subscribed Determines if notifications
@@ -682,19 +547,19 @@ module Octokit
# @example Subscribe to notifications for a repository
# @client.update_subscription("octokit/octokit.rb", {subscribed: true})
def update_subscription(repo, options = {})
- put "repos/#{Repository.new(repo)}/subscription", options
+ put "#{Repository.path repo}/subscription", options
end
# Delete a repository subscription
#
- # @param repo [String, Hash, Repository] A GitHub repository.
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @return [Boolean] True if subscription deleted, false otherwise.
# @see https://developer.github.com/v3/activity/watching/#delete-a-repository-subscription
#
# @example
# @client.delete_subscription("octokit/octokit.rb")
def delete_subscription(repo, options = {})
- boolean_from_response :delete, "repos/#{Repository.new(repo)}/subscription", options
+ boolean_from_response :delete, "#{Repository.path repo}/subscription", options
end
end
end
diff --git a/lib/octokit/client/stats.rb b/lib/octokit/client/stats.rb
index eafa36d..62958e5 100644
--- a/lib/octokit/client/stats.rb
+++ b/lib/octokit/client/stats.rb
@@ -8,7 +8,7 @@ module Octokit
# Get contributors list with additions, deletions, and commit counts
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Array<Sawyer::Resource>] Array of contributor stats
# @see https://developer.github.com/v3/repos/statistics/#contributors
# @example Get contributor stats for octokit
@@ -20,7 +20,7 @@ module Octokit
# Get the last year of commit activity data
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Array<Sawyer::Resource>] The last year of commit activity grouped by
# week. The days array is a group of commits per day, starting on Sunday.
# @see https://developer.github.com/v3/repos/statistics/#get-the-last-year-of-commit-activity-data
@@ -32,7 +32,7 @@ module Octokit
# Get the number of additions and deletions per week
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Array<Sawyer::Resource>] Weekly aggregate of the number of additions
# and deletions pushed to a repository.
# @see https://developer.github.com/v3/repos/statistics/#code-frequency
@@ -44,7 +44,7 @@ module Octokit
# Get the weekly commit count for the repo owner and everyone else
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Sawyer::Resource] Total commit counts for the owner and total commit
# counts in all. all is everyone combined, including the owner in the last
# 52 weeks. If you’d like to get the commit counts for non-owners, you can
@@ -58,7 +58,7 @@ module Octokit
# Get the number of commits per hour in each day
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Array<Array>] Arrays containing the day number, hour number, and
# number of commits
# @see https://developer.github.com/v3/repos/statistics/#punch-card
@@ -73,11 +73,11 @@ module Octokit
# @private Get stats for a repository
#
- # @param repo [String, Hash, Repository] A GitHub repository
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param metric [String] The metrics you are looking for
# @return [Array<Sawyer::Resource>] Magical unicorn stats
def get_stats(repo, metric, options = {})
- data = get("repos/#{Repository.new(repo)}/stats/#{metric}", options)
+ data = get("#{Repository.path repo}/stats/#{metric}", options)
last_response.status == 202 ? nil : data
end
diff --git a/lib/octokit/client/statuses.rb b/lib/octokit/client/statuses.rb
index 663d988..2b11f1b 100644
--- a/lib/octokit/client/statuses.rb
+++ b/lib/octokit/client/statuses.rb
@@ -5,34 +5,32 @@ module Octokit
#
# @see https://developer.github.com/v3/repos/statuses/
module Statuses
- COMBINED_STATUS_MEDIA_TYPE = "application/vnd.github.she-hulk-preview+json"
# List all statuses for a given commit
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param sha [String] The SHA1 for the commit
# @return [Array<Sawyer::Resource>] A list of statuses
# @see https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
def statuses(repo, sha, options = {})
- get "repos/#{Repository.new(repo)}/statuses/#{sha}", options
+ get "#{Repository.path repo}/statuses/#{sha}", options
end
alias :list_statuses :statuses
# Get the combined status for a ref
#
- # @param repo [String, Repository, Hash] a GitHub repository
+ # @param repo [Integer, String, Repository, Hash] a GitHub repository
# @param ref [String] A Sha or Ref to fetch the status of
# @return [Sawyer::Resource] The combined status for the commit
# @see https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
def combined_status(repo, ref, options = {})
- ensure_combined_status_api_media_type(options)
- get "repos/#{Repository.new(repo)}/commits/#{ref}/status", options
+ get "#{Repository.path repo}/commits/#{ref}/status", options
end
alias :status :combined_status
# Create status for a commit
#
- # @param repo [String, Repository, Hash] A GitHub repository
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param sha [String] The SHA1 for the commit
# @param state [String] The state: pending, success, failure, error
# @option options [String] :context A context to differentiate this status from others
@@ -42,25 +40,7 @@ module Octokit
# @see https://developer.github.com/v3/repos/statuses/#create-a-status
def create_status(repo, sha, state, options = {})
options.merge!(:state => state)
- post "repos/#{Repository.new(repo)}/statuses/#{sha}", options
- end
-
- private
-
- def ensure_combined_status_api_media_type(options = {})
- unless options[:accept]
- options[:accept] = COMBINED_STATUS_MEDIA_TYPE
- warn_combined_status_preview
- end
- options
- end
-
- def warn_combined_status_preview
- octokit_warn <<-EOS
-WARNING: The preview version of the combined status API is not yet suitable
-for production use. You can avoid this message by supplying an appropriate
-media type in the 'Accept' header. See the blog post for details http://git.io/wtsdaA
-EOS
+ post "#{Repository.path repo}/statuses/#{sha}", options
end
end
end
diff --git a/lib/octokit/client/users.rb b/lib/octokit/client/users.rb
index dee272d..1ac7fb4 100644
--- a/lib/octokit/client/users.rb
+++ b/lib/octokit/client/users.rb
@@ -24,18 +24,14 @@ module Octokit
# Get a single user
#
- # @param user [String] A GitHub user name.
+ # @param user [Integer, String] GitHub user login or id.
# @return [Sawyer::Resource]
# @see https://developer.github.com/v3/users/#get-a-single-user
# @see https://developer.github.com/v3/users/#get-the-authenticated-user
# @example
# Octokit.user("sferik")
def user(user=nil, options = {})
- if user
- get "users/#{user}", options
- else
- get 'user', options
- end
+ get User.path(user), options
end
# Retrieve the access_token.
@@ -92,24 +88,28 @@ module Octokit
# Get a user's followers.
#
- # @param user [String] Username of the user whose list of followers you are getting.
- # @return [Array<Sawyer::Resource>] Array of hashes representing users followers.
+ # @param user [Integer, String] GitHub user login or id of the user whose
+ # list of followers you are getting.
+ # @return [Array<Sawyer::Resource>] Array of hashes representing users
+ # followers.
# @see https://developer.github.com/v3/users/followers/#list-followers-of-a-user
# @example
# Octokit.followers('pengwynn')
def followers(user=login, options = {})
- paginate "users/#{user}/followers", options
+ paginate "#{User.path user}/followers", options
end
# Get list of users a user is following.
#
- # @param user [String] Username of the user who you are getting the list of the people they follow.
- # @return [Array<Sawyer::Resource>] Array of hashes representing users a user is following.
+ # @param user [Intger, String] GitHub user login or id of the user who you
+ # are getting the list of the people they follow.
+ # @return [Array<Sawyer::Resource>] Array of hashes representing users a
+ # user is following.
# @see https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user
# @example
# Octokit.following('pengwynn')
def following(user=login, options = {})
- paginate "users/#{user}/following", options
+ paginate "#{User.path user}/following", options
end
# Check if you are following a user. Alternatively, check if a given user
@@ -118,10 +118,11 @@ module Octokit
# Requries an authenticated client.
#
# @overload follows?(target)
- # @param target [String] Username of the user that you want to check if you are following.
+ # @param target [String] GitHub login of the user that you want to
+ # check if you are following.
# @overload follows?(user, target)
- # @param user [String] Username of first user
- # @param target [String] Username of the target user
+ # @param user [Integer, String] GitHub user login or id of first user
+ # @param target [String] GitHub login of the target user
# @return [Boolean] True following target user, false otherwise.
# @see https://developer.github.com/v3/users/followers/#check-if-you-are-following-a-user
# @see https://developer.github.com/v3/users/followers/#check-if-one-user-follows-another
@@ -132,12 +133,7 @@ module Octokit
def follows?(*args)
target = args.pop
user = args.first
- if user.nil?
- url = "user/following/#{target}"
- else
- url = "users/#{user}/following/#{target}"
- end
- boolean_from_response :get, url
+ boolean_from_response :get, "#{User.path user}/following/#{target}"
end
# Follow a user.
@@ -168,7 +164,8 @@ module Octokit
# Get list of repos starred by a user.
#
- # @param user [String] Username of the user to get the list of their starred repositories.
+ # @param user [Integer, String] GitHub user login of the user to get the
+ # list of their starred repositories.
# @param options [Hash] Optional options
# @option options [String] :sort (created) Sort: <tt>created</tt> or <tt>updated</tt>.
# @option options [String] :direction (desc) Direction: <tt>asc</tt> or <tt>desc</tt>.
@@ -234,15 +231,14 @@ module Octokit
# Get list of public keys for user.
#
- # Requires authenticated client.
- #
+ # @param user [Integer, String] GitHub user login or id.
# @return [Array<Sawyer::Resource>] Array of hashes representing public keys.
# @see https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
# @example
- # @client.user_keys('pengwynn'
+ # @client.user_keys('pengwynn')
def user_keys(user, options = {})
# TODO: Roll this into .keys
- paginate "users/#{user}/keys", options
+ paginate "#{User.path user}/keys", options
end
# Add public key to user account.
@@ -268,7 +264,10 @@ module Octokit
# @option options [String] :title
# @option options [String] :key
# @return [Sawyer::Resource] Hash representing the updated public key.
+ #
+ # @deprecated This method is no longer supported in the API
# @see https://developer.github.com/v3/users/keys/#update-a-public-key
+ # @see https://developer.github.com/changes/2014-02-24-finer-grained-scopes-for-ssh-keys/
# @example
# @client.update_key(1, :title => 'new title', :key => "ssh-rsa BBB")
def update_key(key_id, options = {})
@@ -330,12 +329,9 @@ module Octokit
# List repositories being watched by a user.
#
- # @param user [String] User's GitHub username.
- #
+ # @param user [Integer, String] GitHub user login or id.
# @return [Array<Sawyer::Resource>] Array of repositories.
- #
# @see https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
- #
# @example
# @client.subscriptions("pengwynn")
def subscriptions(user=login, options = {})
@@ -351,7 +347,7 @@ module Octokit
if user == login && user_authenticated?
"user/#{path}"
else
- "users/#{user}/#{path}"
+ "#{User.path user}/#{path}"
end
end
end
diff --git a/lib/octokit/error.rb b/lib/octokit/error.rb
index 2e24ad1..f208da6 100644
--- a/lib/octokit/error.rb
+++ b/lib/octokit/error.rb
@@ -2,7 +2,7 @@ module Octokit
# Custom error class for rescuing from all GitHub errors
class Error < StandardError
- # Returns the appropriate Octokit::Error sublcass based
+ # Returns the appropriate Octokit::Error subclass based
# on status and response message
#
# @param [Hash] response HTTP response
@@ -17,6 +17,7 @@ module Octokit
when 401 then error_for_401(headers)
when 403 then error_for_403(body)
when 404 then Octokit::NotFound
+ when 405 then Octokit::MethodNotAllowed
when 406 then Octokit::NotAcceptable
when 409 then Octokit::Conflict
when 415 then Octokit::UnsupportedMediaType
@@ -189,6 +190,9 @@ module Octokit
# Raised when GitHub returns a 404 HTTP status code
class NotFound < ClientError; end
+ # Raised when GitHub returns a 405 HTTP status code
+ class MethodNotAllowed < ClientError; end
+
# Raised when GitHub returns a 406 HTTP status code
class NotAcceptable < ClientError; end
diff --git a/lib/octokit/organization.rb b/lib/octokit/organization.rb
new file mode 100644
index 0000000..24bd2da
--- /dev/null
+++ b/lib/octokit/organization.rb
@@ -0,0 +1,17 @@
+module Octokit
+ # GitHub organization class to generate API path urls
+ class Organization
+ # Get the api path for an organization
+ #
+ # @param org [String, Integer] GitHub organization login or id
+ # @return [String] Organization Api path
+ def self.path org
+ case org
+ when String
+ "orgs/#{org}"
+ when Integer
+ "organizations/#{org}"
+ end
+ end
+ end
+end
diff --git a/lib/octokit/rate_limit.rb b/lib/octokit/rate_limit.rb
index d4d6137..e7a76d3 100644
--- a/lib/octokit/rate_limit.rb
+++ b/lib/octokit/rate_limit.rb
@@ -24,7 +24,7 @@ module Octokit
info.limit = (response.headers['X-RateLimit-Limit'] || 1).to_i
info.remaining = (response.headers['X-RateLimit-Remaining'] || 1).to_i
info.resets_at = Time.at((response.headers['X-RateLimit-Reset'] || Time.now).to_i)
- info.resets_in = (info.resets_at - Time.now).to_i
+ info.resets_in = [(info.resets_at - Time.now).to_i, 0].max
end
info
diff --git a/lib/octokit/repository.rb b/lib/octokit/repository.rb
index 8ae872f..7a7bb68 100644
--- a/lib/octokit/repository.rb
+++ b/lib/octokit/repository.rb
@@ -3,7 +3,7 @@ module Octokit
# Class to parse GitHub repository owner and name from
# URLs and to generate URLs
class Repository
- attr_accessor :owner, :name
+ attr_accessor :owner, :name, :id
# Instantiate from a GitHub repository URL
#
@@ -14,6 +14,8 @@ module Octokit
def initialize(repo)
case repo
+ when Integer
+ @id = repo
when String
@owner, @name = repo.split('/')
when Repository
@@ -32,6 +34,29 @@ module Octokit
end
alias :to_s :slug
+ # @return [String] Repository API path
+ def path
+ return named_api_path if @owner && @name
+ return id_api_path if @id
+ end
+
+ # Get the api path for a repo
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
+ # @return [String] Api path.
+ def self.path repo
+ new(repo).path
+ end
+
+ # @return [String] Api path for owner/name identified repos
+ def named_api_path
+ "repos/#{slug}"
+ end
+
+ # @return [String] Api path for id identified repos
+ def id_api_path
+ "repositories/#{@id}"
+ end
+
# Repository URL based on {Octokit::Client#web_endpoint}
# @return [String]
def url
diff --git a/lib/octokit/response/feed_parser.rb b/lib/octokit/response/feed_parser.rb
index d39d9ac..77a880f 100644
--- a/lib/octokit/response/feed_parser.rb
+++ b/lib/octokit/response/feed_parser.rb
@@ -7,14 +7,11 @@ module Octokit
# Parses RSS and Atom feed responses.
class FeedParser < Faraday::Response::Middleware
- dependency do
- require 'rss'
- end
-
private
def on_complete(env)
if env[:response_headers]["content-type"] =~ /(\batom|\brss)/
+ require 'rss'
env[:body] = RSS::Parser.parse env[:body]
end
end
diff --git a/lib/octokit/user.rb b/lib/octokit/user.rb
new file mode 100644
index 0000000..d8f83f3
--- /dev/null
+++ b/lib/octokit/user.rb
@@ -0,0 +1,19 @@
+module Octokit
+ # GitHub user class to generate API path urls
+ class User
+ # Get the api path for a user
+ #
+ # @param user [String, Integer] GitHub user login or id
+ # @return [String] User Api path
+ def self.path user
+ case user
+ when String
+ "users/#{user}"
+ when Integer
+ "user/#{user}"
+ else
+ "user"
+ end
+ end
+ end
+end
diff --git a/lib/octokit/version.rb b/lib/octokit/version.rb
index 2440d67..18c31b0 100644
--- a/lib/octokit/version.rb
+++ b/lib/octokit/version.rb
@@ -2,6 +2,6 @@ module Octokit
# Current version
# @return [String]
- VERSION = "3.1.0".freeze
+ VERSION = "3.7.0".freeze
end
diff --git a/metadata.yml b/metadata.yml
index ae442b3..d6862ce 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,7 +1,7 @@
--- !ruby/object:Gem::Specification
name: octokit
version: !ruby/object:Gem::Version
- version: 3.1.0
+ version: 3.7.0
platform: ruby
authors:
- Wynn Netherland
@@ -10,7 +10,7 @@ authors:
autorequire:
bindir: bin
cert_chain: []
-date: 2014-04-18 00:00:00.000000000 Z
+date: 2014-12-03 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: bundler
@@ -30,16 +30,22 @@ dependencies:
name: sawyer
requirement: !ruby/object:Gem::Requirement
requirements:
- - - "~>"
+ - - ">="
- !ruby/object:Gem::Version
version: 0.5.3
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: 0.6.0
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - - "~>"
+ - - ">="
- !ruby/object:Gem::Version
version: 0.5.3
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: 0.6.0
description: Simple wrapper for the GitHub API
email:
- wynn.netherland at gmail.com
@@ -54,10 +60,11 @@ files:
- LICENSE.md
- README.md
- Rakefile
-- octokit.gemspec
+- lib/octokit.rb
- lib/octokit/arguments.rb
- lib/octokit/authentication.rb
- lib/octokit/backports/uri.rb
+- lib/octokit/client.rb
- lib/octokit/client/authorizations.rb
- lib/octokit/client/commit_comments.rb
- lib/octokit/client/commits.rb
@@ -92,18 +99,19 @@ files:
- lib/octokit/client/stats.rb
- lib/octokit/client/statuses.rb
- lib/octokit/client/users.rb
-- lib/octokit/client.rb
- lib/octokit/configurable.rb
- lib/octokit/default.rb
- lib/octokit/error.rb
- lib/octokit/gist.rb
+- lib/octokit/organization.rb
- lib/octokit/rate_limit.rb
- lib/octokit/repo_arguments.rb
- lib/octokit/repository.rb
- lib/octokit/response/feed_parser.rb
- lib/octokit/response/raise_error.rb
+- lib/octokit/user.rb
- lib/octokit/version.rb
-- lib/octokit.rb
+- octokit.gemspec
homepage: https://github.com/octokit/octokit.rb
licenses:
- MIT
@@ -124,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
version: 1.3.5
requirements: []
rubyforge_project:
-rubygems_version: 2.0.3
+rubygems_version: 2.2.2
signing_key:
specification_version: 4
summary: Ruby toolkit for working with the GitHub API
diff --git a/octokit.gemspec b/octokit.gemspec
index 1d81adb..858f1ee 100644
--- a/octokit.gemspec
+++ b/octokit.gemspec
@@ -5,7 +5,7 @@ require 'octokit/version'
Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler', '~> 1.0'
- spec.add_dependency 'sawyer', '~> 0.5.3'
+ spec.add_dependency 'sawyer', '>= 0.5.3', '~> 0.6.0'
spec.authors = ["Wynn Netherland", "Erik Michaels-Ober", "Clint Shryock"]
spec.description = %q{Simple wrapper for the GitHub API}
spec.email = ['wynn.netherland at gmail.com', 'sferik at gmail.com', 'clint at ctshryock.com']
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-octokit.git
More information about the Pkg-ruby-extras-commits
mailing list