octokit 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rspec +3 -0
- data/Rakefile +3 -10
- data/changelog.markdown +3 -0
- data/lib/octokit/client.rb +1 -2
- data/lib/octokit/client/authentication.rb +4 -0
- data/lib/octokit/client/commits.rb +1 -1
- data/lib/octokit/client/connection.rb +4 -2
- data/lib/octokit/client/issues.rb +8 -8
- data/lib/octokit/client/network.rb +3 -3
- data/lib/octokit/client/objects.rb +1 -1
- data/lib/octokit/client/organizations.rb +3 -2
- data/lib/octokit/client/pulls.rb +9 -3
- data/lib/octokit/client/repositories.rb +23 -10
- data/lib/octokit/client/request.rb +10 -10
- data/lib/octokit/client/timelines.rb +11 -9
- data/lib/octokit/configuration.rb +21 -19
- data/lib/octokit/version.rb +1 -1
- data/octokit.gemspec +4 -6
- data/spec/faraday/response_spec.rb +33 -0
- data/spec/fixtures/blob.json +1 -0
- data/spec/fixtures/blob_metadata.json +1 -0
- data/spec/fixtures/blobs.json +1 -0
- data/spec/fixtures/branches.json +1 -0
- data/spec/fixtures/collaborators.json +1 -0
- data/spec/fixtures/comment.json +1 -0
- data/spec/fixtures/comments.json +1 -0
- data/spec/fixtures/commit.json +1 -0
- data/spec/fixtures/commits.json +1 -0
- data/spec/fixtures/contributors.json +1 -0
- data/spec/fixtures/delete_token.json +1 -0
- data/spec/fixtures/emails.json +1 -0
- data/spec/fixtures/followers.json +1 -0
- data/spec/fixtures/following.json +1 -0
- data/spec/fixtures/issue.json +1 -0
- data/spec/fixtures/issues.json +1 -0
- data/spec/fixtures/labels.json +1 -0
- data/spec/fixtures/languages.json +1 -0
- data/spec/fixtures/network.json +1 -0
- data/spec/fixtures/network_data.json +1 -0
- data/spec/fixtures/network_meta.json +1 -0
- data/spec/fixtures/organization.json +1 -0
- data/spec/fixtures/organizations.json +1 -0
- data/spec/fixtures/public_keys.json +1 -0
- data/spec/fixtures/pull.json +1 -0
- data/spec/fixtures/pulls.json +1 -0
- data/spec/fixtures/raw.txt +7 -0
- data/spec/fixtures/repositories.json +1 -0
- data/spec/fixtures/repository.json +1 -0
- data/spec/fixtures/tags.json +1 -0
- data/spec/fixtures/team.json +1 -0
- data/spec/fixtures/teams.json +1 -0
- data/spec/fixtures/timeline.json +1237 -0
- data/spec/fixtures/tree.json +1 -0
- data/spec/fixtures/tree_metadata.json +1 -0
- data/spec/fixtures/user.json +1 -0
- data/spec/fixtures/users.json +1 -0
- data/spec/fixtures/watchers.json +1 -0
- data/spec/helper.rb +66 -0
- data/spec/octokit/client/commits_spec.rb +31 -0
- data/spec/octokit/client/issues_spec.rb +155 -0
- data/spec/octokit/client/network_spec.rb +31 -0
- data/spec/octokit/client/objects_spec.rb +75 -0
- data/spec/octokit/client/organizations_spec.rb +233 -0
- data/spec/octokit/client/pulls_spec.rb +43 -0
- data/spec/octokit/client/repositories_spec.rb +330 -0
- data/spec/octokit/client/timelines_spec.rb +41 -0
- data/spec/octokit/client/users_spec.rb +273 -0
- data/spec/octokit/client_spec.rb +12 -0
- data/spec/octokit_spec.rb +14 -0
- data/spec/repository_spec.rb +53 -0
- data/test/helper.rb +2 -0
- data/test/octokit_test.rb +14 -2
- metadata +147 -89
- data/lib/octokit/event.rb +0 -76
data/.rspec
ADDED
data/Rakefile
CHANGED
@@ -1,14 +1,7 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
1
|
require 'bundler'
|
3
2
|
Bundler::GemHelper.install_tasks
|
4
3
|
|
5
|
-
require '
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
6
|
|
7
|
-
|
8
|
-
Rake::TestTask.new(:test) do |test|
|
9
|
-
test.ruby_opts = ["-rubygems"] if defined? Gem
|
10
|
-
test.libs << "lib" << "test"
|
11
|
-
test.pattern = "test/**/*_test.rb"
|
12
|
-
end
|
13
|
-
|
14
|
-
task :default => :test
|
7
|
+
task :default => :spec
|
data/changelog.markdown
CHANGED
data/lib/octokit/client.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require File.expand_path('../event', __FILE__)
|
2
1
|
require File.expand_path('../repository', __FILE__)
|
3
2
|
Dir[File.expand_path('../client/*.rb', __FILE__)].each{|file| require file}
|
4
3
|
|
@@ -27,4 +26,4 @@ module Octokit
|
|
27
26
|
include Octokit::Client::Timelines
|
28
27
|
include Octokit::Client::Users
|
29
28
|
end
|
30
|
-
end
|
29
|
+
end
|
@@ -7,16 +7,18 @@ module Octokit
|
|
7
7
|
module Connection
|
8
8
|
private
|
9
9
|
|
10
|
-
def connection(raw=false)
|
10
|
+
def connection(raw=false, authenticate=true)
|
11
11
|
options = {
|
12
12
|
:proxy => proxy,
|
13
13
|
:ssl => {:verify => false},
|
14
14
|
:url => endpoint,
|
15
15
|
}
|
16
16
|
|
17
|
+
options.merge!(:params => { :access_token => oauth_token }) if oauthed? && !authenticated?
|
18
|
+
|
17
19
|
Faraday::Connection.new(options) do |connection|
|
18
20
|
connection.adapter(adapter)
|
19
|
-
connection.basic_auth authentication[:login], authentication[:password] if authenticated?
|
21
|
+
connection.basic_auth authentication[:login], authentication[:password] if authenticate and authenticated?
|
20
22
|
connection.use Faraday::Response::RaiseError
|
21
23
|
unless raw
|
22
24
|
case format.to_s.downcase
|
@@ -20,7 +20,7 @@ module Octokit
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def issue_comments(repo, number, options={})
|
23
|
-
|
23
|
+
get("issues/comments/#{Repository.new(repo)}/#{number}", options)['comments']
|
24
24
|
end
|
25
25
|
|
26
26
|
def create_issue(repo, title, body, options={})
|
@@ -43,15 +43,15 @@ module Octokit
|
|
43
43
|
def labels(repo, options={})
|
44
44
|
get("issues/labels/#{Repository.new(repo)}", options)['labels']
|
45
45
|
end
|
46
|
-
|
47
|
-
def add_label(repo,
|
48
|
-
post("issues/label/add/#{Repository.new(repo)}/#{label}
|
46
|
+
|
47
|
+
def add_label(repo, label, number=nil, options={})
|
48
|
+
post(["issues/label/add/#{Repository.new(repo)}/#{label}", number].compact.join('/'), options)['labels']
|
49
49
|
end
|
50
|
-
|
51
|
-
def remove_label(repo,
|
52
|
-
post("issues/label/remove/#{Repository.new(repo)}/#{label}
|
50
|
+
|
51
|
+
def remove_label(repo, label, number=nil, options={})
|
52
|
+
post(["issues/label/remove/#{Repository.new(repo)}/#{label}", number].compact.join('/'), options)['labels']
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def add_comment(repo, number, comment, options={})
|
56
56
|
post("issues/comment/#{Repository.new(repo)}/#{number}", options.merge({:comment => comment}))['comment']
|
57
57
|
end
|
@@ -5,9 +5,9 @@ module Octokit
|
|
5
5
|
def network_meta(repo, options={})
|
6
6
|
get("#{Repository.new(repo)}/network_meta", options, false, false)
|
7
7
|
end
|
8
|
-
|
9
|
-
def network_data(repo,
|
10
|
-
get("#{Repository.new(repo)}/network_data_chunk", options
|
8
|
+
|
9
|
+
def network_data(repo, options={})
|
10
|
+
get("#{Repository.new(repo)}/network_data_chunk", options, false, false)['commits']
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
@@ -20,7 +20,7 @@ module Octokit
|
|
20
20
|
alias :blob_meta :blob_metadata
|
21
21
|
|
22
22
|
def tree_metadata(repo, tree_sha, options={})
|
23
|
-
get("tree/full/#{Repository.new(repo)}/#{tree_sha}", options)['
|
23
|
+
get("tree/full/#{Repository.new(repo)}/#{tree_sha}", options)['tree']
|
24
24
|
end
|
25
25
|
alias :tree_meta :tree_metadata
|
26
26
|
|
@@ -23,7 +23,7 @@ module Octokit
|
|
23
23
|
alias :list_orgs :organizations
|
24
24
|
alias :orgs :organizations
|
25
25
|
|
26
|
-
def organization_repositories(org, options={})
|
26
|
+
def organization_repositories(org=nil, options={})
|
27
27
|
if org
|
28
28
|
get("organizations/#{org}/public_repositories", options)
|
29
29
|
else
|
@@ -38,9 +38,10 @@ module Octokit
|
|
38
38
|
end
|
39
39
|
alias :org_members :organization_members
|
40
40
|
|
41
|
-
def
|
41
|
+
def organization_teams(org, options={})
|
42
42
|
get("organizations/#{org}/teams", options)['teams']
|
43
43
|
end
|
44
|
+
alias :org_teams :organization_teams
|
44
45
|
|
45
46
|
def create_team(org, values, options={})
|
46
47
|
post("organizations/#{org}/teams", options.merge({:team => values}))['team']
|
data/lib/octokit/client/pulls.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
module Octokit
|
2
2
|
class Client
|
3
3
|
module Pulls
|
4
|
-
def create_pull_request(repo, options={})
|
5
|
-
|
4
|
+
def create_pull_request(repo, base, head, title, body, options={})
|
5
|
+
pull = {
|
6
|
+
:base => base,
|
7
|
+
:head => head,
|
8
|
+
:title => title,
|
9
|
+
:body => body,
|
10
|
+
}
|
11
|
+
post("pulls/#{Repository.new(repo)}", options.merge({:pull => pull}))['pulls']
|
6
12
|
end
|
7
13
|
|
8
14
|
def pull_requests(repo, state='open', options={})
|
@@ -11,7 +17,7 @@ module Octokit
|
|
11
17
|
alias :pulls :pull_requests
|
12
18
|
|
13
19
|
def pull_request(repo, number, options={})
|
14
|
-
get("pulls/#{Repository.new(repo)}/#{number}", options)['
|
20
|
+
get("pulls/#{Repository.new(repo)}/#{number}", options)['pull']
|
15
21
|
end
|
16
22
|
alias :pull :pull_request
|
17
23
|
end
|
@@ -17,7 +17,7 @@ module Octokit
|
|
17
17
|
end
|
18
18
|
alias :update_repo :update_repository
|
19
19
|
|
20
|
-
def repositories(username=
|
20
|
+
def repositories(username=login, options={})
|
21
21
|
get(["repos/show", username].compact.join('/'), options)['repositories']
|
22
22
|
end
|
23
23
|
alias :list_repositories :repositories
|
@@ -39,17 +39,28 @@ module Octokit
|
|
39
39
|
end
|
40
40
|
alias :fork :fork!
|
41
41
|
|
42
|
-
def create_repository(options={})
|
43
|
-
post("repos/create", options)['repository']
|
42
|
+
def create_repository(name, options={})
|
43
|
+
post("repos/create", options.merge(:name => name))['repository']
|
44
44
|
end
|
45
45
|
alias :create_repo :create_repository
|
46
46
|
alias :create :create_repository
|
47
47
|
|
48
48
|
def delete_repository(repo, options={})
|
49
|
-
post("repos/delete/#{Repository.new(repo)}", options)
|
49
|
+
response = post("repos/delete/#{Repository.new(repo)}", options)
|
50
|
+
if response.respond_to?(:delete_token)
|
51
|
+
response['delete_token']
|
52
|
+
else
|
53
|
+
response['repository']
|
54
|
+
end
|
50
55
|
end
|
51
56
|
alias :delete_repo :delete_repository
|
52
57
|
|
58
|
+
def delete_repository!(repo, options={})
|
59
|
+
response = post("repos/delete/#{Repository.new(repo)}", options)
|
60
|
+
post("repos/delete/#{Repository.new(repo)}", options.merge(:delete_token => response['delete_token']))['repository']
|
61
|
+
end
|
62
|
+
alias :delete_repo! :delete_repository!
|
63
|
+
|
53
64
|
def set_private!(repo, options={})
|
54
65
|
post("repos/set/private/#{Repository.new(repo)}", options)['repository']
|
55
66
|
end
|
@@ -65,7 +76,7 @@ module Octokit
|
|
65
76
|
end
|
66
77
|
alias :list_deploy_keys :deploy_keys
|
67
78
|
|
68
|
-
def add_deploy_key(repo, options={})
|
79
|
+
def add_deploy_key(repo, title, key, options={})
|
69
80
|
post("repos/key/#{Repository.new(repo)}/add", options)['public_keys']
|
70
81
|
end
|
71
82
|
|
@@ -92,15 +103,17 @@ module Octokit
|
|
92
103
|
get("repos/pushable", options)['repositories']
|
93
104
|
end
|
94
105
|
|
95
|
-
def
|
96
|
-
get("repos/show/#{Repository.new(repo)}/teams", options)['
|
106
|
+
def repository_teams(repo, options={})
|
107
|
+
get("repos/show/#{Repository.new(repo)}/teams", options)['teams']
|
97
108
|
end
|
109
|
+
alias :repo_teams :repository_teams
|
110
|
+
alias :teams :repository_teams
|
98
111
|
|
99
|
-
def contributors(repo, anon=
|
112
|
+
def contributors(repo, anon=false, options={})
|
100
113
|
if anon
|
101
|
-
get("repos/show/#{Repository.new(repo)}/contributors", options)
|
102
|
-
else
|
103
114
|
get("repos/show/#{Repository.new(repo)}/contributors/anon", options)
|
115
|
+
else
|
116
|
+
get("repos/show/#{Repository.new(repo)}/contributors", options)
|
104
117
|
end['contributors']
|
105
118
|
end
|
106
119
|
alias :contribs :contributors
|
@@ -1,26 +1,26 @@
|
|
1
1
|
module Octokit
|
2
2
|
class Client
|
3
3
|
module Request
|
4
|
-
def get(path, options={}, raw=false, format_path=true)
|
5
|
-
request(:get, path, options, raw, format_path)
|
4
|
+
def get(path, options={}, raw=false, format_path=true, authenticate=true)
|
5
|
+
request(:get, path, options, raw, format_path, authenticate)
|
6
6
|
end
|
7
7
|
|
8
|
-
def post(path, options={}, raw=false, format_path=true)
|
9
|
-
request(:post, path, options, raw, format_path)
|
8
|
+
def post(path, options={}, raw=false, format_path=true, authenticate=true)
|
9
|
+
request(:post, path, options, raw, format_path, authenticate)
|
10
10
|
end
|
11
11
|
|
12
|
-
def put(path, options={}, raw=false, format_path=true)
|
13
|
-
request(:put, path, options, raw, format_path)
|
12
|
+
def put(path, options={}, raw=false, format_path=true, authenticate=true)
|
13
|
+
request(:put, path, options, raw, format_path, authenticate)
|
14
14
|
end
|
15
15
|
|
16
|
-
def delete(path, options={}, raw=false, format_path=true)
|
17
|
-
request(:delete, path, options, raw, format_path)
|
16
|
+
def delete(path, options={}, raw=false, format_path=true, authenticate=true)
|
17
|
+
request(:delete, path, options, raw, format_path, authenticate)
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
def request(method, path, options, raw, format_path)
|
23
|
-
response = connection(raw).send(method) do |request|
|
22
|
+
def request(method, path, options, raw, format_path, authenticate)
|
23
|
+
response = connection(raw, authenticate).send(method) do |request|
|
24
24
|
path = formatted_path(path) if format_path
|
25
25
|
case method
|
26
26
|
when :get, :delete
|
@@ -2,17 +2,19 @@ module Octokit
|
|
2
2
|
class Client
|
3
3
|
module Timelines
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
else
|
9
|
-
path = "#{username}.json"
|
10
|
-
end
|
11
|
-
get(path, options, false, false)
|
5
|
+
def timeline(options={})
|
6
|
+
path = "https://github.com/timeline.json"
|
7
|
+
get(path, options, false, false, false)
|
12
8
|
end
|
13
9
|
|
14
|
-
def
|
15
|
-
|
10
|
+
def user_timeline(username=login, options={})
|
11
|
+
if token
|
12
|
+
path = "https://github.com/#{username}.private.json"
|
13
|
+
options[:token] = token
|
14
|
+
else
|
15
|
+
path = "https://github.com/#{username}.json"
|
16
|
+
end
|
17
|
+
get(path, options, false, false, false)
|
16
18
|
end
|
17
19
|
|
18
20
|
end
|
@@ -3,18 +3,19 @@ require File.expand_path('../version', __FILE__)
|
|
3
3
|
|
4
4
|
module Octokit
|
5
5
|
module Configuration
|
6
|
-
VALID_OPTIONS_KEYS = [:adapter, :endpoint, :format, :login, :password, :proxy, :token, :user_agent, :version].freeze
|
6
|
+
VALID_OPTIONS_KEYS = [:adapter, :endpoint, :format, :login, :password, :proxy, :token, :oauth_token, :user_agent, :version].freeze
|
7
7
|
VALID_FORMATS = [:json, :xml, :yaml].freeze
|
8
8
|
|
9
|
-
DEFAULT_ADAPTER
|
10
|
-
DEFAULT_ENDPOINT
|
11
|
-
DEFAULT_FORMAT
|
12
|
-
DEFAULT_LOGIN
|
13
|
-
DEFAULT_PASSWORD
|
14
|
-
DEFAULT_PROXY
|
15
|
-
DEFAULT_TOKEN
|
16
|
-
|
17
|
-
|
9
|
+
DEFAULT_ADAPTER = Faraday.default_adapter.freeze
|
10
|
+
DEFAULT_ENDPOINT = 'https://github.com/'.freeze
|
11
|
+
DEFAULT_FORMAT = :json.freeze
|
12
|
+
DEFAULT_LOGIN = nil.freeze
|
13
|
+
DEFAULT_PASSWORD = nil.freeze
|
14
|
+
DEFAULT_PROXY = nil.freeze
|
15
|
+
DEFAULT_TOKEN = nil.freeze
|
16
|
+
DEFAULT_OAUTH_TOKEN = nil.freeze
|
17
|
+
DEFAULT_USER_AGENT = "Octokit Ruby Gem #{Octokit::VERSION}".freeze
|
18
|
+
DEFAULT_VERSION = 2
|
18
19
|
|
19
20
|
attr_accessor *VALID_OPTIONS_KEYS
|
20
21
|
|
@@ -31,15 +32,16 @@ module Octokit
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def reset
|
34
|
-
self.adapter
|
35
|
-
self.endpoint
|
36
|
-
self.format
|
37
|
-
self.login
|
38
|
-
self.password
|
39
|
-
self.proxy
|
40
|
-
self.token
|
41
|
-
self.
|
42
|
-
self.
|
35
|
+
self.adapter = DEFAULT_ADAPTER
|
36
|
+
self.endpoint = DEFAULT_ENDPOINT
|
37
|
+
self.format = DEFAULT_FORMAT
|
38
|
+
self.login = DEFAULT_LOGIN
|
39
|
+
self.password = DEFAULT_PASSWORD
|
40
|
+
self.proxy = DEFAULT_PROXY
|
41
|
+
self.token = DEFAULT_TOKEN
|
42
|
+
self.oauth_token = DEFAULT_OAUTH_TOKEN
|
43
|
+
self.user_agent = DEFAULT_USER_AGENT
|
44
|
+
self.version = DEFAULT_VERSION
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
data/lib/octokit/version.rb
CHANGED
data/octokit.gemspec
CHANGED
@@ -2,18 +2,16 @@
|
|
2
2
|
require File.expand_path('../lib/octokit/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.add_development_dependency('fakeweb', '~> 1.3')
|
6
|
-
s.add_development_dependency('jnunemaker-matchy', '~> 0.4')
|
7
5
|
s.add_development_dependency('json', '~> 1.4')
|
8
|
-
s.add_development_dependency('mocha', '~> 0.9')
|
9
6
|
s.add_development_dependency('nokogiri', '~> 1.4')
|
10
7
|
s.add_development_dependency('rake', '~> 0.8')
|
11
|
-
s.add_development_dependency('
|
8
|
+
s.add_development_dependency('rspec', '~> 2.4')
|
9
|
+
s.add_development_dependency('simplecov', '~> 0.3')
|
12
10
|
s.add_development_dependency('webmock', '~> 1.6')
|
13
11
|
s.add_development_dependency('ZenTest', '~> 4.4')
|
14
|
-
s.add_runtime_dependency('addressable', '~> 2.2.
|
12
|
+
s.add_runtime_dependency('addressable', '~> 2.2.3')
|
15
13
|
s.add_runtime_dependency('hashie', '~> 0.4.0')
|
16
|
-
s.add_runtime_dependency('faraday', '~> 0.5.
|
14
|
+
s.add_runtime_dependency('faraday', '~> 0.5.4')
|
17
15
|
s.add_runtime_dependency('faraday_middleware', '~> 0.3.1')
|
18
16
|
s.add_runtime_dependency('multi_json', '~> 0.0.5')
|
19
17
|
s.add_runtime_dependency('multi_xml', '~> 0.2.0')
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path('../../helper', __FILE__)
|
2
|
+
|
3
|
+
describe Faraday::Response do
|
4
|
+
before do
|
5
|
+
@client = Octokit::Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
{
|
9
|
+
400 => Octokit::BadRequest,
|
10
|
+
401 => Octokit::Unauthorized,
|
11
|
+
403 => Octokit::Forbidden,
|
12
|
+
404 => Octokit::NotFound,
|
13
|
+
406 => Octokit::NotAcceptable,
|
14
|
+
500 => Octokit::InternalServerError,
|
15
|
+
501 => Octokit::NotImplemented,
|
16
|
+
502 => Octokit::BadGateway,
|
17
|
+
503 => Octokit::ServiceUnavailable,
|
18
|
+
}.each do |status, exception|
|
19
|
+
context "when HTTP status is #{status}" do
|
20
|
+
|
21
|
+
before do
|
22
|
+
stub_get('user/show/sferik').
|
23
|
+
to_return(:status => status)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should raise #{exception.name} error" do
|
27
|
+
lambda do
|
28
|
+
@client.user('sferik')
|
29
|
+
end.should raise_error(exception)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|