github_api 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -0
- data/lib/github_api/api.rb +20 -22
- data/lib/github_api/core_ext/hash.rb +17 -0
- data/lib/github_api/events.rb +3 -3
- data/lib/github_api/git_data/blobs.rb +2 -2
- data/lib/github_api/git_data/commits.rb +2 -2
- data/lib/github_api/git_data/references.rb +5 -5
- data/lib/github_api/git_data/tags.rb +2 -2
- data/lib/github_api/git_data/trees.rb +2 -2
- data/lib/github_api/issues.rb +4 -4
- data/lib/github_api/issues/comments.rb +6 -6
- data/lib/github_api/issues/events.rb +2 -2
- data/lib/github_api/issues/labels.rb +10 -10
- data/lib/github_api/issues/milestones.rb +5 -5
- data/lib/github_api/page_iterator.rb +4 -3
- data/lib/github_api/pull_requests.rb +8 -8
- data/lib/github_api/pull_requests/comments.rb +5 -5
- data/lib/github_api/repos.rb +15 -8
- data/lib/github_api/repos/collaborators.rb +4 -4
- data/lib/github_api/repos/comments.rb +121 -0
- data/lib/github_api/repos/commits.rb +56 -177
- data/lib/github_api/repos/contents.rb +3 -0
- data/lib/github_api/repos/downloads.rb +4 -4
- data/lib/github_api/repos/forks.rb +2 -2
- data/lib/github_api/repos/hooks.rb +6 -6
- data/lib/github_api/repos/keys.rb +5 -5
- data/lib/github_api/repos/merging.rb +1 -0
- data/lib/github_api/repos/starring.rb +3 -1
- data/lib/github_api/repos/statuses.rb +2 -2
- data/lib/github_api/repos/watching.rb +1 -1
- data/lib/github_api/version.rb +1 -1
- data/spec/github/api/set_spec.rb +19 -0
- data/spec/github/repos/comments/create_spec.rb +86 -0
- data/spec/github/repos/comments/delete_spec.rb +47 -0
- data/spec/github/repos/comments/get_spec.rb +54 -0
- data/spec/github/repos/comments/list_spec.rb +120 -0
- data/spec/github/repos/comments/update_spec.rb +54 -0
- data/spec/github/repos/commits/compare_spec.rb +37 -0
- data/spec/github/repos/commits/get_spec.rb +56 -0
- data/spec/github/repos/commits/list_spec.rb +63 -0
- data/spec/github/repos/downloads/create_spec.rb +66 -0
- data/spec/github/repos/downloads/delete_spec.rb +48 -0
- data/spec/github/repos/downloads/get_spec.rb +58 -0
- data/spec/github/repos/downloads/list_spec.rb +63 -0
- data/spec/github/repos/downloads/upload_spec.rb +32 -0
- data/spec/github/repos/downloads_spec.rb +1 -233
- data/spec/github/repos_spec.rb +2 -0
- data/spec/spec_helper.rb +1 -0
- metadata +48 -34
- data/spec/github/repos/commits_spec.rb +0 -471
@@ -13,6 +13,7 @@ module Github
|
|
13
13
|
# github.repos.contents.readme 'user-name', 'repo-name'
|
14
14
|
#
|
15
15
|
def readme(user_name, repo_name, params={})
|
16
|
+
set :user => user_name, :repo => repo_name
|
16
17
|
normalize! params
|
17
18
|
|
18
19
|
get_request("/repos/#{user_name}/#{repo_name}/readme", params)
|
@@ -30,6 +31,7 @@ module Github
|
|
30
31
|
# github.repos.contents.get 'user-name', 'repo-name', 'path'
|
31
32
|
#
|
32
33
|
def get(user_name, repo_name, path, params={})
|
34
|
+
set :user => user_name, :repo => repo_name
|
33
35
|
normalize! params
|
34
36
|
|
35
37
|
get_request("/repos/#{user_name}/#{repo_name}/contents/#{path}", params)
|
@@ -56,6 +58,7 @@ module Github
|
|
56
58
|
# "ref" => "master"
|
57
59
|
#
|
58
60
|
def archive(user_name, repo_name, params={})
|
61
|
+
set :user => user_name, :repo => repo_name
|
59
62
|
normalize! params
|
60
63
|
archive_format = params.delete('archive_format') || 'zipball'
|
61
64
|
ref = params.delete('ref') || 'master'
|
@@ -22,7 +22,7 @@ module Github
|
|
22
22
|
# github.repos.downloads.list 'user-name', 'repo-name' { |downl| ... }
|
23
23
|
#
|
24
24
|
def list(user_name, repo_name, params={})
|
25
|
-
|
25
|
+
set :user => user_name, :repo => repo_name
|
26
26
|
assert_presence_of user, repo
|
27
27
|
normalize! params
|
28
28
|
|
@@ -39,7 +39,7 @@ module Github
|
|
39
39
|
# github.repos.downloads.get 'user-name', 'repo-name', 'download-id'
|
40
40
|
#
|
41
41
|
def get(user_name, repo_name, download_id, params={})
|
42
|
-
|
42
|
+
set :user => user_name, :repo => repo_name
|
43
43
|
assert_presence_of user, repo, download_id
|
44
44
|
normalize! params
|
45
45
|
|
@@ -54,7 +54,7 @@ module Github
|
|
54
54
|
# github.repos.downloads.delete 'user-name', 'repo-name', 'download-id'
|
55
55
|
#
|
56
56
|
def delete(user_name, repo_name, download_id, params={})
|
57
|
-
|
57
|
+
set :user => user_name, :repo => repo_name
|
58
58
|
assert_presence_of user, repo, download_id
|
59
59
|
normalize! params
|
60
60
|
|
@@ -80,7 +80,7 @@ module Github
|
|
80
80
|
# "content_type" => "text/plain"
|
81
81
|
#
|
82
82
|
def create(user_name, repo_name, params={})
|
83
|
-
|
83
|
+
set :user => user_name, :repo => repo_name
|
84
84
|
assert_presence_of user, repo
|
85
85
|
|
86
86
|
normalize! params
|
@@ -14,7 +14,7 @@ module Github
|
|
14
14
|
# github.repos.forks.list 'user-name', 'repo-name' { |fork| ... }
|
15
15
|
#
|
16
16
|
def list(user_name, repo_name, params = {})
|
17
|
-
|
17
|
+
set :user => user_name, :repo => repo_name
|
18
18
|
assert_presence_of user, repo
|
19
19
|
normalize! params
|
20
20
|
|
@@ -35,7 +35,7 @@ module Github
|
|
35
35
|
# "org" => "github"
|
36
36
|
#
|
37
37
|
def create(user_name, repo_name, params={})
|
38
|
-
|
38
|
+
set :user => user_name, :repo => repo_name
|
39
39
|
assert_presence_of user, repo
|
40
40
|
normalize! params
|
41
41
|
filter! %w[ org ], params
|
@@ -43,7 +43,7 @@ module Github
|
|
43
43
|
# github.repos.hooks.list 'user-name', 'repo-name' { |hook| ... }
|
44
44
|
#
|
45
45
|
def list(user_name, repo_name, params={})
|
46
|
-
|
46
|
+
set :user => user_name, :repo => repo_name
|
47
47
|
assert_presence_of user, repo
|
48
48
|
normalize! params
|
49
49
|
|
@@ -60,7 +60,7 @@ module Github
|
|
60
60
|
# github.repos.hooks.get 'user-name', 'repo-name'
|
61
61
|
#
|
62
62
|
def get(user_name, repo_name, hook_id, params={})
|
63
|
-
|
63
|
+
set :user => user_name, :repo => repo_name
|
64
64
|
assert_presence_of user, repo, hook_id
|
65
65
|
normalize! params
|
66
66
|
|
@@ -87,7 +87,7 @@ module Github
|
|
87
87
|
# }
|
88
88
|
#
|
89
89
|
def create(user_name, repo_name, params={})
|
90
|
-
|
90
|
+
set :user => user_name, :repo => repo_name
|
91
91
|
assert_presence_of user, repo
|
92
92
|
|
93
93
|
normalize! params
|
@@ -119,7 +119,7 @@ module Github
|
|
119
119
|
# }
|
120
120
|
#
|
121
121
|
def edit(user_name, repo_name, hook_id, params={})
|
122
|
-
|
122
|
+
set :user => user_name, :repo => repo_name
|
123
123
|
assert_presence_of user, repo, hook_id
|
124
124
|
|
125
125
|
normalize! params
|
@@ -138,7 +138,7 @@ module Github
|
|
138
138
|
# github.repos.hooks.test 'user-name', 'repo-name', 'hook-id'
|
139
139
|
#
|
140
140
|
def test(user_name, repo_name, hook_id, params={})
|
141
|
-
|
141
|
+
set :user => user_name, :repo => repo_name
|
142
142
|
assert_presence_of user, repo, hook_id
|
143
143
|
normalize! params
|
144
144
|
|
@@ -152,7 +152,7 @@ module Github
|
|
152
152
|
# github.repos.hooks.delete 'user-name', 'repo-name', 'hook-id'
|
153
153
|
#
|
154
154
|
def delete(user_name, repo_name, hook_id, params={})
|
155
|
-
|
155
|
+
set :user => user_name, :repo => repo_name
|
156
156
|
assert_presence_of user, repo, hook_id
|
157
157
|
normalize! params
|
158
158
|
|
@@ -13,7 +13,7 @@ module Github
|
|
13
13
|
# github.repos.keys.list 'user-name', 'repo-name' { |key| ... }
|
14
14
|
#
|
15
15
|
def list(user_name, repo_name, params={})
|
16
|
-
|
16
|
+
set :user => user_name, :repo => repo_name
|
17
17
|
assert_presence_of user, repo
|
18
18
|
normalize! params
|
19
19
|
|
@@ -30,7 +30,7 @@ module Github
|
|
30
30
|
# github.repos.keys.get 'user-name', 'repo-name', 'key-id'
|
31
31
|
#
|
32
32
|
def get(user_name, repo_name, key_id, params={})
|
33
|
-
|
33
|
+
set :user => user_name, :repo => repo_name
|
34
34
|
assert_presence_of user, repo, key_id
|
35
35
|
normalize! params
|
36
36
|
|
@@ -51,7 +51,7 @@ module Github
|
|
51
51
|
# "key" => "ssh-rsa AAA..."
|
52
52
|
#
|
53
53
|
def create(user_name, repo_name, params={})
|
54
|
-
|
54
|
+
set :user => user_name, :repo => repo_name
|
55
55
|
assert_presence_of user, repo
|
56
56
|
normalize! params
|
57
57
|
filter! VALID_KEY_PARAM_NAMES, params
|
@@ -73,7 +73,7 @@ module Github
|
|
73
73
|
# "key" => "ssh-rsa AAA..."
|
74
74
|
#
|
75
75
|
def edit(user_name, repo_name, key_id, params={})
|
76
|
-
|
76
|
+
set :user => user_name, :repo => repo_name
|
77
77
|
assert_presence_of user, repo, key_id
|
78
78
|
|
79
79
|
normalize! params
|
@@ -89,7 +89,7 @@ module Github
|
|
89
89
|
# @github.repos.keys.delete 'user-name', 'repo-name', 'key-id'
|
90
90
|
#
|
91
91
|
def delete(user_name, repo_name, key_id, params={})
|
92
|
-
|
92
|
+
set :user => user_name, :repo => repo_name
|
93
93
|
assert_presence_of user, repo, key_id
|
94
94
|
normalize! params
|
95
95
|
|
@@ -29,6 +29,7 @@ module Github
|
|
29
29
|
# "commit_message": "Shipped cool_feature!"
|
30
30
|
#
|
31
31
|
def merge(user_name, repo_name, params={})
|
32
|
+
set :user => user_name, :repo => repo_name
|
32
33
|
normalize! params
|
33
34
|
filter! VALID_MERGE_PARAM_NAMES, params
|
34
35
|
assert_required_keys REQUIRED_MERGE_PARAMS, params
|
@@ -13,7 +13,7 @@ module Github
|
|
13
13
|
# github.repos.starring.list { |star| ... }
|
14
14
|
#
|
15
15
|
def list(user_name, repo_name, params={})
|
16
|
-
|
16
|
+
set :user => user_name, :repo => repo_name
|
17
17
|
assert_presence_of user, repo
|
18
18
|
normalize! params
|
19
19
|
|
@@ -74,6 +74,7 @@ module Github
|
|
74
74
|
# github.repos.starring.star 'user-name', 'repo-name'
|
75
75
|
#
|
76
76
|
def star(user_name, repo_name, params={})
|
77
|
+
set :user => user_name, :repo => repo_name
|
77
78
|
assert_presence_of user_name, repo_name
|
78
79
|
normalize! params
|
79
80
|
put_request("/user/starred/#{user_name}/#{repo_name}", params)
|
@@ -88,6 +89,7 @@ module Github
|
|
88
89
|
# github.repos.starring.unstar 'user-name', 'repo-name'
|
89
90
|
#
|
90
91
|
def unstar(user_name, repo_name, params={})
|
92
|
+
set :user => user_name, :repo => repo_name
|
91
93
|
assert_presence_of user_name, repo_name
|
92
94
|
normalize! params
|
93
95
|
delete_request("/user/starred/#{user_name}/#{repo_name}", params)
|
@@ -22,7 +22,7 @@ module Github
|
|
22
22
|
# github.repos.statuses.list 'user-name', 'repo-name', 'sha' { |status| ... }
|
23
23
|
#
|
24
24
|
def list(user_name, repo_name, sha, params={})
|
25
|
-
|
25
|
+
set :user => user_name, :repo => repo_name
|
26
26
|
assert_presence_of user, repo
|
27
27
|
normalize! params
|
28
28
|
|
@@ -50,7 +50,7 @@ module Github
|
|
50
50
|
# "description" => "Successful build #3 from origin/master"
|
51
51
|
#
|
52
52
|
def create(user_name, repo_name, sha, params={})
|
53
|
-
|
53
|
+
set :user => user_name, :repo => repo_name
|
54
54
|
assert_presence_of user, repo
|
55
55
|
|
56
56
|
normalize! params
|
@@ -13,7 +13,7 @@ module Github
|
|
13
13
|
# github.repos.watching.list { |watcher| ... }
|
14
14
|
#
|
15
15
|
def list(user_name, repo_name, params={})
|
16
|
-
|
16
|
+
set :user => user_name, :repo => repo_name
|
17
17
|
assert_presence_of user, repo
|
18
18
|
normalize! params
|
19
19
|
|
data/lib/github_api/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::API, '#set' do
|
6
|
+
|
7
|
+
after { reset_authentication_for subject }
|
8
|
+
|
9
|
+
it 'requires value to be set' do
|
10
|
+
expect { subject.set :option }.to raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'accepts more than one option' do
|
14
|
+
subject.set :user => 'user-name', :repo => 'repo-name'
|
15
|
+
subject.user.should == 'user-name'
|
16
|
+
subject.repo.should == 'repo-name'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos::Comments, '#create' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:sha) { '23432dfosfsufd' }
|
9
|
+
let(:inputs) do
|
10
|
+
{ 'body' => 'web',
|
11
|
+
:commit_id => 1,
|
12
|
+
:line => 1,
|
13
|
+
:path => 'file1.txt',
|
14
|
+
:position => 4 }
|
15
|
+
end
|
16
|
+
let(:request_path) { "/repos/#{user}/#{repo}/commits/#{sha}/comments" }
|
17
|
+
|
18
|
+
before {
|
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 "resouce created" do
|
27
|
+
let(:body) { fixture('repos/commit_comment.json') }
|
28
|
+
let(:status) { 201 }
|
29
|
+
|
30
|
+
it "should fail to create resource if 'body' input is missing" do
|
31
|
+
expect {
|
32
|
+
subject.create user, repo, sha, inputs.except('body')
|
33
|
+
}.to raise_error(Github::Error::RequiredParams)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should fail to create resource if 'commit_id' input is missing" do
|
37
|
+
expect {
|
38
|
+
subject.create user, repo, sha, inputs.except(:commit_id)
|
39
|
+
}.to raise_error(Github::Error::RequiredParams)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should fail to create resource if 'line' input is missing" do
|
43
|
+
expect {
|
44
|
+
subject.create user, repo, sha, inputs.except(:line)
|
45
|
+
}.to raise_error(Github::Error::RequiredParams)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should fail to create resource if 'path' input is missing" do
|
49
|
+
expect {
|
50
|
+
subject.create user, repo, sha, inputs.except(:path)
|
51
|
+
}.to raise_error(Github::Error::RequiredParams)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should fail to create resource if 'position' input is missing" do
|
55
|
+
expect {
|
56
|
+
subject.create user, repo, sha, inputs.except(:position)
|
57
|
+
}.to raise_error(Github::Error::RequiredParams)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should create resource successfully" do
|
61
|
+
subject.create user, repo, sha, inputs
|
62
|
+
a_post(request_path).with(inputs).should have_been_made
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return the resource" do
|
66
|
+
comment = subject.create user, repo, sha, inputs
|
67
|
+
comment.should be_a Hashie::Mash
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should get the commit comment information" do
|
71
|
+
comment = subject.create user, repo, sha, inputs
|
72
|
+
comment.user.login.should == 'octocat'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "failed to create resource" do
|
77
|
+
let(:body) { '' }
|
78
|
+
let(:status) { 404 }
|
79
|
+
|
80
|
+
it "should fail to retrieve resource" do
|
81
|
+
expect {
|
82
|
+
subject.create user, repo, sha, inputs
|
83
|
+
}.to raise_error(Github::Error::NotFound)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end # create
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos::Comments, '#delete' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:comment_id) { 1 }
|
9
|
+
let(:request_path) { "/repos/#{user}/#{repo}/comments/#{comment_id}" }
|
10
|
+
|
11
|
+
before {
|
12
|
+
stub_delete(request_path).
|
13
|
+
to_return(:body => body, :status => status,
|
14
|
+
:headers => { :content_type => "application/json; charset=utf-8"})
|
15
|
+
}
|
16
|
+
|
17
|
+
context "resource deleted successfully" do
|
18
|
+
let(:body) { '' }
|
19
|
+
let(:status) { 204 }
|
20
|
+
|
21
|
+
it "should fail to delete without 'user/repo' parameters" do
|
22
|
+
expect { subject.delete }.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should fail to delete resource without 'comment_id'" do
|
26
|
+
expect {
|
27
|
+
subject.delete user, repo, nil
|
28
|
+
}.to raise_error(ArgumentError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should delete the resource" do
|
32
|
+
subject.delete user, repo, comment_id
|
33
|
+
a_delete(request_path).should have_been_made
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "failed to delete resource" do
|
38
|
+
let(:body) { '' }
|
39
|
+
let(:status) { 404 }
|
40
|
+
|
41
|
+
it "should fail to find resource" do
|
42
|
+
expect {
|
43
|
+
subject.delete user, repo, comment_id
|
44
|
+
}.to raise_error(Github::Error::NotFound)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end # delete
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos::Comments, '#get' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:comment_id) { 1 }
|
9
|
+
let(:request_path) { "/repos/#{user}/#{repo}/comments/#{comment_id}" }
|
10
|
+
|
11
|
+
before {
|
12
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
13
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
14
|
+
}
|
15
|
+
|
16
|
+
after { reset_authentication_for subject }
|
17
|
+
|
18
|
+
context "resource found" do
|
19
|
+
let(:body) { fixture('repos/commit_comment.json') }
|
20
|
+
let(:status) { 200 }
|
21
|
+
|
22
|
+
it { should respond_to(:find) }
|
23
|
+
|
24
|
+
it "should fail to get resource without comment id" do
|
25
|
+
expect { subject.get user, repo, nil }.to raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should get the resource" do
|
29
|
+
subject.get user, repo, comment_id
|
30
|
+
a_get(request_path).should have_been_made
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get commit comment information" do
|
34
|
+
commit_comment = subject.get user, repo, comment_id
|
35
|
+
commit_comment.user.login.should == 'octocat'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return mash" do
|
39
|
+
commit_comment = subject.get user, repo, comment_id
|
40
|
+
commit_comment.should be_a Hashie::Mash
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "resource not found" do
|
45
|
+
let(:body) { '' }
|
46
|
+
let(:status) { 404 }
|
47
|
+
|
48
|
+
it "should fail to retrive resource" do
|
49
|
+
expect {
|
50
|
+
subject.get user, repo, comment_id
|
51
|
+
}.to raise_error(Github::Error::NotFound)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end # get
|