github_api 0.7.0 → 0.7.1
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/README.md +11 -5
- data/Rakefile +2 -0
- data/features/repos/statuses.feature +12 -12
- data/lib/github_api/api.rb +1 -1
- data/lib/github_api/authorizations.rb +3 -3
- data/lib/github_api/events.rb +7 -7
- data/lib/github_api/gists.rb +7 -7
- data/lib/github_api/gists/comments.rb +4 -4
- data/lib/github_api/git_data/blobs.rb +2 -3
- data/lib/github_api/git_data/commits.rb +2 -3
- data/lib/github_api/git_data/references.rb +10 -17
- data/lib/github_api/git_data/tags.rb +2 -3
- data/lib/github_api/git_data/trees.rb +2 -3
- data/lib/github_api/issues.rb +4 -6
- data/lib/github_api/issues/assignees.rb +5 -4
- data/lib/github_api/issues/comments.rb +5 -10
- data/lib/github_api/issues/events.rb +2 -3
- data/lib/github_api/issues/labels.rb +11 -20
- data/lib/github_api/issues/milestones.rb +5 -8
- data/lib/github_api/orgs.rb +2 -2
- data/lib/github_api/orgs/members.rb +7 -7
- data/lib/github_api/orgs/teams.rb +13 -13
- data/lib/github_api/page_iterator.rb +3 -1
- data/lib/github_api/pull_requests.rb +8 -16
- data/lib/github_api/pull_requests/comments.rb +5 -10
- data/lib/github_api/repos.rb +27 -8
- data/lib/github_api/repos/collaborators.rb +4 -7
- data/lib/github_api/repos/commits.rb +9 -16
- data/lib/github_api/repos/downloads.rb +5 -7
- data/lib/github_api/repos/forks.rb +3 -3
- data/lib/github_api/repos/hooks.rb +10 -13
- data/lib/github_api/repos/keys.rb +5 -8
- data/lib/github_api/repos/pub_sub_hubbub.rb +4 -4
- data/lib/github_api/repos/starring.rb +4 -4
- data/lib/github_api/repos/statuses.rb +2 -2
- data/lib/github_api/repos/watching.rb +4 -4
- data/lib/github_api/users/followers.rb +3 -3
- data/lib/github_api/users/keys.rb +3 -3
- data/lib/github_api/validations/presence.rb +16 -17
- data/lib/github_api/version.rb +1 -1
- data/spec/fixtures/repos/repos_sorted_by_pushed.json +56 -0
- data/spec/github/git_data_spec.rb +5 -7
- data/spec/github/issues_spec.rb +12 -12
- data/spec/github/orgs_spec.rb +2 -4
- data/spec/github/pull_requests_spec.rb +1 -1
- data/spec/github/repos/branch_spec.rb +48 -0
- data/spec/github/repos/branches_spec.rb +62 -0
- data/spec/github/repos/contributors_spec.rb +62 -0
- data/spec/github/repos/create_spec.rb +77 -0
- data/spec/github/repos/delete_spec.rb +43 -0
- data/spec/github/repos/downloads_spec.rb +51 -45
- data/spec/github/repos/edit_spec.rb +66 -0
- data/spec/github/repos/forks/create_spec.rb +49 -0
- data/spec/github/repos/forks/list_spec.rb +65 -0
- data/spec/github/repos/get_spec.rb +57 -0
- data/spec/github/repos/languages_spec.rb +61 -0
- data/spec/github/repos/list_spec.rb +99 -0
- data/spec/github/repos/tags_spec.rb +59 -0
- data/spec/github/repos/teams_spec.rb +59 -0
- data/spec/github/repos_spec.rb +13 -578
- data/spec/github/validations/presence_spec.rb +23 -4
- metadata +48 -42
- data/spec/github/repos/forks_spec.rb +0 -106
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos, '#contributors' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
|
9
|
+
after { reset_authentication_for subject }
|
10
|
+
|
11
|
+
let(:request_path) { "/repos/#{user}/#{repo}/contributors" }
|
12
|
+
|
13
|
+
before do
|
14
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
15
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
16
|
+
end
|
17
|
+
|
18
|
+
context "resource found" do
|
19
|
+
let(:body) { fixture('repos/contributors.json') }
|
20
|
+
let(:status) { 200 }
|
21
|
+
|
22
|
+
it "should raise error when no user/repo parameters" do
|
23
|
+
expect { subject.contributors nil, repo }.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should raise error when no repository" do
|
27
|
+
expect { subject.contributors user, nil }.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should find resources" do
|
31
|
+
subject.contributors user, repo
|
32
|
+
a_get(request_path).should have_been_made
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return array of resources" do
|
36
|
+
contributors = subject.contributors user, repo
|
37
|
+
contributors.should be_an Array
|
38
|
+
contributors.should have(1).items
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should get branch information" do
|
42
|
+
contributors = subject.contributors user, repo
|
43
|
+
contributors.first.login.should == 'octocat'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should yield to a block" do
|
47
|
+
subject.should_receive(:contributors).with(user, repo).and_yield('web')
|
48
|
+
subject.contributors(user, repo) { |param| 'web'}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "resource not found" do
|
53
|
+
let(:body) { '' }
|
54
|
+
let(:status) { 404 }
|
55
|
+
|
56
|
+
it "should fail to get resource" do
|
57
|
+
expect {
|
58
|
+
subject.contributors user, repo
|
59
|
+
}.to raise_error(Github::Error::NotFound)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end # contributors
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos, '#create' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:inputs) { {
|
9
|
+
:name => 'web',
|
10
|
+
:description => "This is your first repo",
|
11
|
+
:homepage => "https://github.com",
|
12
|
+
:public => true,
|
13
|
+
:has_issues => true,
|
14
|
+
:has_wiki => true
|
15
|
+
} }
|
16
|
+
|
17
|
+
before {
|
18
|
+
subject.oauth_token = OAUTH_TOKEN
|
19
|
+
stub_post(request_path).with(inputs).
|
20
|
+
to_return(:body => body, :status => status,
|
21
|
+
:headers => {:content_type => "application/json; charset=utf-8"} )
|
22
|
+
}
|
23
|
+
|
24
|
+
after { reset_authentication_for subject }
|
25
|
+
|
26
|
+
context "resource created successfully" do
|
27
|
+
let(:body) { fixture('repos/repo.json') }
|
28
|
+
let(:status) { 201 }
|
29
|
+
|
30
|
+
context "for the authenticated user" do
|
31
|
+
let(:request_path) { "/user/repos?access_token=#{OAUTH_TOKEN}" }
|
32
|
+
|
33
|
+
it "should faile to create resource if 'name' inputs is missing" do
|
34
|
+
expect {
|
35
|
+
subject.create inputs.except(:name)
|
36
|
+
}.to raise_error(Github::Error::RequiredParams)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should create resource" do
|
40
|
+
subject.create inputs
|
41
|
+
a_post(request_path).with(inputs).should have_been_made
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return the resource" do
|
45
|
+
repository = subject.create inputs
|
46
|
+
repository.name.should == 'Hello-World'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return mash type" do
|
50
|
+
repository = subject.create inputs
|
51
|
+
repository.should be_a Hashie::Mash
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "for the authenticated user belonging to organization" do
|
56
|
+
let(:request_path) { "/orgs/#{org}/repos?access_token=#{OAUTH_TOKEN}" }
|
57
|
+
let(:org) { '37signals' }
|
58
|
+
|
59
|
+
it "should get the resource" do
|
60
|
+
subject.create inputs.merge(:org => org)
|
61
|
+
a_post(request_path).with(inputs).should have_been_made
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "failed to create" do
|
67
|
+
let(:request_path) { "/user/repos?access_token=#{OAUTH_TOKEN}" }
|
68
|
+
let(:body) { '' }
|
69
|
+
let(:status) { 404 }
|
70
|
+
|
71
|
+
it "should faile to retrieve resource" do
|
72
|
+
expect {
|
73
|
+
subject.create inputs
|
74
|
+
}.to raise_error(Github::Error::NotFound)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end # create
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:request_path) { "/repos/#{user}/#{repo}" }
|
9
|
+
let(:body) { '' }
|
10
|
+
let(:status) { 204 }
|
11
|
+
|
12
|
+
before {
|
13
|
+
stub_delete(request_path).to_return(:body => body, :status => status,
|
14
|
+
:headers => { :content_type => "application/json; charset=utf-8"})
|
15
|
+
}
|
16
|
+
|
17
|
+
after { reset_authentication_for subject }
|
18
|
+
|
19
|
+
it { should respond_to :remove }
|
20
|
+
|
21
|
+
it "should delete the resource successfully" do
|
22
|
+
subject.delete user, repo
|
23
|
+
a_delete(request_path).should have_been_made
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should fail to delete resource without 'user' parameter" do
|
27
|
+
expect { subject.delete nil, repo }.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should fail to delete resource without 'repo' parameter" do
|
31
|
+
expect { subject.delete user, nil }.to raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'failed to delete' do
|
35
|
+
let(:status) { 404 }
|
36
|
+
|
37
|
+
it "should fail to delete resource that is not found" do
|
38
|
+
expect {
|
39
|
+
subject.delete user, repo
|
40
|
+
}.to raise_error(Github::Error::NotFound)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end # delete
|
@@ -8,20 +8,25 @@ describe Github::Repos::Downloads do
|
|
8
8
|
let(:user) { 'peter-murach' }
|
9
9
|
let(:repo) { 'github' }
|
10
10
|
|
11
|
-
after { github
|
11
|
+
after { reset_authentication_for(github) }
|
12
12
|
|
13
13
|
it { described_class::VALID_DOWNLOAD_PARAM_NAMES.should_not be_nil }
|
14
|
+
|
14
15
|
it { described_class::REQUIRED_PARAMS.should_not be_nil }
|
15
16
|
|
16
17
|
describe "#list" do
|
17
|
-
|
18
|
+
|
19
|
+
before do
|
20
|
+
stub_get("/repos/#{user}/#{repo}/downloads").
|
21
|
+
to_return(:body => body, :status => status,
|
22
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
23
|
+
end
|
18
24
|
|
19
25
|
context "resource found" do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
26
|
+
let(:body) { fixture('repos/downloads.json') }
|
27
|
+
let(:status) { 200 }
|
28
|
+
|
29
|
+
it { should respond_to :list }
|
25
30
|
|
26
31
|
it "should fail to get resource without username" do
|
27
32
|
expect { github.repos.downloads.list }.to raise_error(ArgumentError)
|
@@ -56,10 +61,8 @@ describe Github::Repos::Downloads do
|
|
56
61
|
end
|
57
62
|
|
58
63
|
context "resource not found" do
|
59
|
-
|
60
|
-
|
61
|
-
to_return(:body => "", :status => [404, "Not Found"])
|
62
|
-
end
|
64
|
+
let(:body) { "" }
|
65
|
+
let(:status) { [404, "Not Found"] }
|
63
66
|
|
64
67
|
it "should return 404 with a message 'Not Found'" do
|
65
68
|
expect {
|
@@ -72,14 +75,17 @@ describe Github::Repos::Downloads do
|
|
72
75
|
describe "#get" do
|
73
76
|
let(:download_id) { 1 }
|
74
77
|
|
75
|
-
|
78
|
+
before do
|
79
|
+
stub_get("/repos/#{user}/#{repo}/downloads/#{download_id}").
|
80
|
+
to_return(:body => body, :status => status,
|
81
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
82
|
+
end
|
76
83
|
|
77
84
|
context "resource found" do
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
85
|
+
let(:body) { fixture('repos/download.json') }
|
86
|
+
let(:status) { 200 }
|
87
|
+
|
88
|
+
it { github.repos.downloads.should respond_to :find }
|
83
89
|
|
84
90
|
it "should fail to get resource without download id" do
|
85
91
|
expect {
|
@@ -105,10 +111,8 @@ describe Github::Repos::Downloads do
|
|
105
111
|
end
|
106
112
|
|
107
113
|
context "resource not found" do
|
108
|
-
|
109
|
-
|
110
|
-
to_return(:body => fixture('repos/download.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
111
|
-
end
|
114
|
+
let(:body) { "" }
|
115
|
+
let(:status) { [404, "Not Found"] }
|
112
116
|
|
113
117
|
it "should fail to retrive resource" do
|
114
118
|
expect {
|
@@ -121,12 +125,15 @@ describe Github::Repos::Downloads do
|
|
121
125
|
describe "#delete" do
|
122
126
|
let(:download_id) { 1 }
|
123
127
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
128
|
+
before do
|
129
|
+
stub_delete("/repos/#{user}/#{repo}/downloads/#{download_id}").
|
130
|
+
to_return(:body => body, :status => status,
|
131
|
+
:headers => { :content_type => "application/json; charset=utf-8"})
|
132
|
+
end
|
133
|
+
|
134
|
+
context "resource deleted successfully" do
|
135
|
+
let(:body) { "" }
|
136
|
+
let(:status) { 204 }
|
130
137
|
|
131
138
|
it "should fail to delete without 'user/repo' parameters" do
|
132
139
|
expect { github.repos.downloads.delete }.to raise_error(ArgumentError)
|
@@ -144,12 +151,9 @@ describe Github::Repos::Downloads do
|
|
144
151
|
end
|
145
152
|
end
|
146
153
|
|
147
|
-
context "failed to
|
148
|
-
|
149
|
-
|
150
|
-
to_return(:body => fixture("repos/download.json"), :status => 404,
|
151
|
-
:headers => { :content_type => "application/json; charset=utf-8"})
|
152
|
-
end
|
154
|
+
context "failed to delete resource" do
|
155
|
+
let(:body) { "" }
|
156
|
+
let(:status) { [404, "Not Found"] }
|
153
157
|
|
154
158
|
it "should fail to find resource" do
|
155
159
|
expect {
|
@@ -162,12 +166,15 @@ describe Github::Repos::Downloads do
|
|
162
166
|
describe "#create" do
|
163
167
|
let(:inputs) { {:name => 'new_file.jpg', :size => 114034, :description => "Latest release", :content_type => 'text/plain'} }
|
164
168
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
+
before do
|
170
|
+
stub_post("/repos/#{user}/#{repo}/downloads").with(inputs).
|
171
|
+
to_return(:body => body, :status => status,
|
172
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
173
|
+
end
|
169
174
|
|
170
|
-
|
175
|
+
context "resouce created" do
|
176
|
+
let(:body) { fixture('repos/download_s3.json') }
|
177
|
+
let(:status) { 201}
|
171
178
|
|
172
179
|
it "should fail to create resource if 'name' input is missing" do
|
173
180
|
expect {
|
@@ -198,11 +205,8 @@ describe Github::Repos::Downloads do
|
|
198
205
|
end
|
199
206
|
|
200
207
|
context "failed to create resource" do
|
201
|
-
|
202
|
-
|
203
|
-
to_return(:body => fixture('repos/download_s3.json'), :status => 404,
|
204
|
-
:headers => {:content_type => "application/json; charset=utf-8"})
|
205
|
-
end
|
208
|
+
let(:body) { "" }
|
209
|
+
let(:status) { [404, "Not Found"] }
|
206
210
|
|
207
211
|
it "should faile to retrieve resource" do
|
208
212
|
expect {
|
@@ -215,7 +219,7 @@ describe Github::Repos::Downloads do
|
|
215
219
|
describe 'upload' do
|
216
220
|
let(:resource) { stub(:resource) }
|
217
221
|
let(:filename) { 'filename' }
|
218
|
-
let(:res)
|
222
|
+
let(:res) { stub(:response, :body => 'success') }
|
219
223
|
let(:uploader) { stub(:uploader, :send => res) }
|
220
224
|
|
221
225
|
context 'resource uploaded' do
|
@@ -224,7 +228,9 @@ describe Github::Repos::Downloads do
|
|
224
228
|
end
|
225
229
|
|
226
230
|
it "should fail if resource is of incorrect type" do
|
227
|
-
expect {
|
231
|
+
expect {
|
232
|
+
github.repos.downloads.upload resource, nil
|
233
|
+
}.to raise_error(ArgumentError)
|
228
234
|
end
|
229
235
|
|
230
236
|
it "should upload resource successfully" do
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos, '#edit' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:request_path) { "/repos/#{user}/#{repo}" }
|
9
|
+
let(:inputs) do
|
10
|
+
{ :name => 'web',
|
11
|
+
:description => "This is your first repo",
|
12
|
+
:homepage => "https://github.com",
|
13
|
+
:private => false,
|
14
|
+
:has_issues => true,
|
15
|
+
:has_wiki => true }
|
16
|
+
end
|
17
|
+
|
18
|
+
before {
|
19
|
+
stub_patch(request_path).with(inputs).
|
20
|
+
to_return(:body => body, :status => status,
|
21
|
+
:headers => { :content_type => "application/json; charset=utf-8"})
|
22
|
+
}
|
23
|
+
|
24
|
+
after { reset_authentication_for subject }
|
25
|
+
|
26
|
+
context "resource edited successfully" do
|
27
|
+
let(:body) { fixture("repos/repo.json") }
|
28
|
+
let(:status) { 200 }
|
29
|
+
|
30
|
+
it "should fail to edit without 'user/repo' parameters" do
|
31
|
+
expect { subject.edit user, nil }.to raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should fail to edit resource without 'name' parameter" do
|
35
|
+
expect{
|
36
|
+
subject.edit user, repo, inputs.except(:name)
|
37
|
+
}.to raise_error(Github::Error::RequiredParams)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should edit the resource" do
|
41
|
+
subject.edit user, repo, inputs
|
42
|
+
a_patch(request_path).with(inputs).should have_been_made
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return resource" do
|
46
|
+
repository = subject.edit user, repo, inputs
|
47
|
+
repository.should be_a Hashie::Mash
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be able to retrieve information" do
|
51
|
+
repository = subject.edit user, repo, inputs
|
52
|
+
repository.name.should == 'Hello-World'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "failed to edit resource" do
|
57
|
+
let(:body) { '' }
|
58
|
+
let(:status) { 404 }
|
59
|
+
|
60
|
+
it "should fail to find resource" do
|
61
|
+
expect {
|
62
|
+
subject.edit user, repo, inputs
|
63
|
+
}.to raise_error(Github::Error::NotFound)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end # edit
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos::Forks, '#create' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:request_path) { "/repos/#{user}/#{repo}/forks" }
|
9
|
+
let(:inputs) { {:org => 'github'} }
|
10
|
+
|
11
|
+
before {
|
12
|
+
stub_post(request_path).with(inputs).
|
13
|
+
to_return(:body => body, :status => status,
|
14
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
15
|
+
}
|
16
|
+
|
17
|
+
after { reset_authentication_for(subject) }
|
18
|
+
|
19
|
+
context "resouce created" do
|
20
|
+
let(:body) { fixture('repos/fork.json') }
|
21
|
+
let(:status) { 202 }
|
22
|
+
|
23
|
+
it "should create resource successfully" do
|
24
|
+
subject.create(user, repo, inputs)
|
25
|
+
a_post(request_path).with(inputs).should have_been_made
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return the resource" do
|
29
|
+
fork = subject.create user, repo, inputs
|
30
|
+
fork.should be_a Hashie::Mash
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get the fork information" do
|
34
|
+
fork = subject.create user, repo, inputs
|
35
|
+
fork.name.should == 'Hello-World'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "failed to create resource" do
|
40
|
+
let(:body) { "" }
|
41
|
+
let(:status) { 404 }
|
42
|
+
|
43
|
+
it "should faile to retrieve resource" do
|
44
|
+
expect {
|
45
|
+
subject.create user, repo, inputs
|
46
|
+
}.to raise_error(Github::Error::NotFound)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end # create
|