github_api 0.7.1 → 0.7.2

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.
Files changed (50) hide show
  1. data/README.md +11 -0
  2. data/lib/github_api/api.rb +20 -22
  3. data/lib/github_api/core_ext/hash.rb +17 -0
  4. data/lib/github_api/events.rb +3 -3
  5. data/lib/github_api/git_data/blobs.rb +2 -2
  6. data/lib/github_api/git_data/commits.rb +2 -2
  7. data/lib/github_api/git_data/references.rb +5 -5
  8. data/lib/github_api/git_data/tags.rb +2 -2
  9. data/lib/github_api/git_data/trees.rb +2 -2
  10. data/lib/github_api/issues.rb +4 -4
  11. data/lib/github_api/issues/comments.rb +6 -6
  12. data/lib/github_api/issues/events.rb +2 -2
  13. data/lib/github_api/issues/labels.rb +10 -10
  14. data/lib/github_api/issues/milestones.rb +5 -5
  15. data/lib/github_api/page_iterator.rb +4 -3
  16. data/lib/github_api/pull_requests.rb +8 -8
  17. data/lib/github_api/pull_requests/comments.rb +5 -5
  18. data/lib/github_api/repos.rb +15 -8
  19. data/lib/github_api/repos/collaborators.rb +4 -4
  20. data/lib/github_api/repos/comments.rb +121 -0
  21. data/lib/github_api/repos/commits.rb +56 -177
  22. data/lib/github_api/repos/contents.rb +3 -0
  23. data/lib/github_api/repos/downloads.rb +4 -4
  24. data/lib/github_api/repos/forks.rb +2 -2
  25. data/lib/github_api/repos/hooks.rb +6 -6
  26. data/lib/github_api/repos/keys.rb +5 -5
  27. data/lib/github_api/repos/merging.rb +1 -0
  28. data/lib/github_api/repos/starring.rb +3 -1
  29. data/lib/github_api/repos/statuses.rb +2 -2
  30. data/lib/github_api/repos/watching.rb +1 -1
  31. data/lib/github_api/version.rb +1 -1
  32. data/spec/github/api/set_spec.rb +19 -0
  33. data/spec/github/repos/comments/create_spec.rb +86 -0
  34. data/spec/github/repos/comments/delete_spec.rb +47 -0
  35. data/spec/github/repos/comments/get_spec.rb +54 -0
  36. data/spec/github/repos/comments/list_spec.rb +120 -0
  37. data/spec/github/repos/comments/update_spec.rb +54 -0
  38. data/spec/github/repos/commits/compare_spec.rb +37 -0
  39. data/spec/github/repos/commits/get_spec.rb +56 -0
  40. data/spec/github/repos/commits/list_spec.rb +63 -0
  41. data/spec/github/repos/downloads/create_spec.rb +66 -0
  42. data/spec/github/repos/downloads/delete_spec.rb +48 -0
  43. data/spec/github/repos/downloads/get_spec.rb +58 -0
  44. data/spec/github/repos/downloads/list_spec.rb +63 -0
  45. data/spec/github/repos/downloads/upload_spec.rb +32 -0
  46. data/spec/github/repos/downloads_spec.rb +1 -233
  47. data/spec/github/repos_spec.rb +2 -0
  48. data/spec/spec_helper.rb +1 -0
  49. metadata +48 -34
  50. data/spec/github/repos/commits_spec.rb +0 -471
@@ -0,0 +1,120 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Comments, '#list' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+
9
+ after { reset_authentication_for subject }
10
+
11
+ context 'without sha' do
12
+ let(:request_path) { "/repos/#{user}/#{repo}/comments" }
13
+
14
+ before {
15
+ stub_get(request_path).to_return(:body => body, :status => status,
16
+ :headers => {:content_type => "application/json; charset=utf-8"})
17
+ }
18
+
19
+ context "resource found" do
20
+ let(:body) { fixture('repos/repo_comments.json') }
21
+ let(:status) { 200 }
22
+
23
+ it { should respond_to(:all) }
24
+
25
+ it "should fail to get resource without username" do
26
+ expect { subject.list }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it "should get the resources" do
30
+ subject.list user, repo
31
+ a_get(request_path).should have_been_made
32
+ end
33
+
34
+ it "should return array of resources" do
35
+ repo_comments = subject.list user, repo
36
+ repo_comments.should be_an Array
37
+ repo_comments.should have(1).items
38
+ end
39
+
40
+ it "should be a mash type" do
41
+ repo_comments = subject.list user, repo
42
+ repo_comments.first.should be_a Hashie::Mash
43
+ end
44
+
45
+ it "should get commit comment information" do
46
+ repo_comments = subject.list user, repo
47
+ repo_comments.first.user.login.should == 'octocat'
48
+ end
49
+
50
+ it "should yield to a block" do
51
+ subject.should_receive(:list).with(user, repo).and_yield('web')
52
+ subject.list(user, repo) { |param| 'web' }
53
+ end
54
+ end
55
+
56
+ context "resource not found" do
57
+ let(:body) { '' }
58
+ let(:status) { [404, "Not Found"] }
59
+
60
+ it "should return 404 with a message 'Not Found'" do
61
+ expect {
62
+ subject.list user, repo
63
+ }.to raise_error(Github::Error::NotFound)
64
+ end
65
+ end
66
+ end # without sha
67
+
68
+ context 'with sha' do
69
+ let(:sha) { '23432dfosfsufd' }
70
+ let(:request_path) { "/repos/#{user}/#{repo}/commits/#{sha}/comments" }
71
+
72
+ before {
73
+ stub_get(request_path).to_return(:body => body, :status => status,
74
+ :headers => {:content_type => "application/json; charset=utf-8"})
75
+ }
76
+
77
+ context "resource found" do
78
+ let(:body) { fixture('repos/commit_comments.json') }
79
+ let(:status) { 200 }
80
+
81
+ it "should get the resource" do
82
+ subject.list user, repo, :sha => sha
83
+ a_get(request_path).should have_been_made
84
+ end
85
+
86
+ it "should return array of resources" do
87
+ commit_comments = subject.list user, repo, :sha => sha
88
+ commit_comments.should be_an Array
89
+ commit_comments.should have(1).items
90
+ end
91
+
92
+ it "should be a mash type" do
93
+ commit_comments = subject.list user, repo, :sha => sha
94
+ commit_comments.first.should be_a Hashie::Mash
95
+ end
96
+
97
+ it "should get commit comment information" do
98
+ commit_comments = subject.list user, repo, :sha => sha
99
+ commit_comments.first.user.login.should == 'octocat'
100
+ end
101
+
102
+ it "should yield to a block" do
103
+ subject.should_receive(:list).with(user, repo, :sha=>sha).and_yield('web')
104
+ subject.list(user, repo, :sha => sha) { |param| 'web' }
105
+ end
106
+ end
107
+
108
+ context "resource not found" do
109
+ let(:body) { '' }
110
+ let(:status) { 404 }
111
+
112
+ it "should fail to retrive resource" do
113
+ expect {
114
+ subject.list user, repo, :sha => sha
115
+ }.to raise_error(Github::Error::NotFound)
116
+ end
117
+ end
118
+ end # with sha
119
+
120
+ end # list
@@ -0,0 +1,54 @@
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(:inputs) { {'body'=> 'web'} }
10
+ let(:request_path) { "/repos/#{user}/#{repo}/comments/#{comment_id}" }
11
+
12
+ before {
13
+ stub_patch(request_path).with(inputs).
14
+ to_return(:body => body,:status => status,
15
+ :headers => {:content_type => "application/json; charset=utf-8"})
16
+ }
17
+
18
+ context "resouce created" do
19
+ let(:body) { fixture('repos/commit_comment.json') }
20
+ let(:status) { 200 }
21
+
22
+ it "should fail to create resource if 'body' input is missing" do
23
+ expect {
24
+ subject.update user, repo, comment_id, inputs.except('body')
25
+ }.to raise_error(Github::Error::RequiredParams)
26
+ end
27
+
28
+ it "should create resource successfully" do
29
+ subject.update user, repo, comment_id, inputs
30
+ a_patch(request_path).with(inputs).should have_been_made
31
+ end
32
+
33
+ it "should return the resource" do
34
+ comment = subject.update user, repo, comment_id, inputs
35
+ comment.should be_a Hashie::Mash
36
+ end
37
+
38
+ it "should get the commit comment information" do
39
+ comment = subject.update user, repo, comment_id, inputs
40
+ comment.user.login.should == 'octocat'
41
+ end
42
+ end
43
+
44
+ context "failed to update resource" do
45
+ let(:body) { '' }
46
+ let(:status) { 404 }
47
+
48
+ it "should fail to retrieve resource" do
49
+ expect {
50
+ subject.update user, repo, comment_id, inputs
51
+ }.to raise_error(Github::Error::NotFound)
52
+ end
53
+ end
54
+ end # update_comment
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Commits, '#compare' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:base) { 'master' }
9
+ let(:head) { 'topic' }
10
+ let(:request_path) { "/repos/#{user}/#{repo}/compare/#{base}...#{head}" }
11
+
12
+ before {
13
+ stub_get(request_path).
14
+ to_return(:body => fixture('repos/commit_comparison.json'),
15
+ :status => 200,
16
+ :headers => {:content_type => "application/json; charset=utf-8"})
17
+ }
18
+
19
+ after { reset_authentication_for(subject) }
20
+
21
+ it "should fail to get resource without base" do
22
+ expect {
23
+ subject.compare user, repo, nil, head
24
+ }.to raise_error(ArgumentError)
25
+ end
26
+
27
+ it "should compare successfully" do
28
+ subject.compare user, repo, base, head
29
+ a_get(request_path).should have_been_made
30
+ end
31
+
32
+ it "should get comparison information" do
33
+ commit = subject.compare user, repo, base, head
34
+ commit.base_commit.commit.author.name.should == 'Monalisa Octocat'
35
+ end
36
+
37
+ end # compare
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Commits, '#get' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:sha) { '23432dfosfsufd' }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/commits/#{sha}" }
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.json') }
20
+ let(:status) { 200 }
21
+
22
+ it { should respond_to :find }
23
+
24
+ it "should fail to get resource without sha key" do
25
+ expect {
26
+ subject.get user, repo, nil
27
+ }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should get the resource" do
31
+ subject.get user, repo, sha
32
+ a_get(request_path).should have_been_made
33
+ end
34
+
35
+ it "should get commit information" do
36
+ commit = subject.get user, repo, sha
37
+ commit.commit.author.name.should == 'Monalisa Octocat'
38
+ end
39
+
40
+ it "should return mash" do
41
+ commit = subject.get user, repo, sha
42
+ commit.should be_a Hashie::Mash
43
+ end
44
+ end
45
+
46
+ context "resource not found" do
47
+ let(:body) { '' }
48
+ let(:status) { 404 }
49
+
50
+ it "should fail to retrive resource" do
51
+ expect {
52
+ subject.get user, repo, sha
53
+ }.to raise_error(Github::Error::NotFound)
54
+ end
55
+ end
56
+ end # get
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Commits, '#list' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/commits" }
9
+
10
+ before {
11
+ stub_get(request_path).to_return(:body => body, :status => status,
12
+ :headers => {:content_type => "application/json; charset=utf-8"})
13
+ }
14
+
15
+ after { reset_authentication_for(subject) }
16
+
17
+ context "resource found" do
18
+ let(:body) { fixture('repos/commits.json') }
19
+ let(:status) { 200 }
20
+
21
+ it { should respond_to :all }
22
+ it "should fail to get resource without username" do
23
+ expect { subject.list }.to raise_error(ArgumentError)
24
+ end
25
+
26
+ it "should get the resources" do
27
+ subject.list user, repo
28
+ a_get(request_path).should have_been_made
29
+ end
30
+
31
+ it "should return array of resources" do
32
+ commits = subject.list user, repo
33
+ commits.should be_an Array
34
+ commits.should have(1).items
35
+ end
36
+
37
+ it "should be a mash type" do
38
+ commits = subject.list user, repo
39
+ commits.first.should be_a Hashie::Mash
40
+ end
41
+
42
+ it "should get commit information" do
43
+ commits = subject.list user, repo
44
+ commits.first.author.name.should == 'Scott Chacon'
45
+ end
46
+
47
+ it "should yield to a block" do
48
+ subject.should_receive(:list).with(user, repo).and_yield('web')
49
+ subject.list(user, repo) { |param| 'web' }
50
+ end
51
+ end
52
+
53
+ context "resource not found" do
54
+ let(:body) { '' }
55
+ let(:status) { [404, "Not Found"] }
56
+
57
+ it "should return 404 with a message 'Not Found'" do
58
+ expect {
59
+ subject.list user, repo
60
+ }.to raise_error(Github::Error::NotFound)
61
+ end
62
+ end
63
+ end # list
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Downloads, '#create' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/downloads" }
9
+ let(:inputs) { {
10
+ :name => 'new_file.jpg',
11
+ :size => 114034,
12
+ :description => "Latest release",
13
+ :content_type => 'text/plain'}
14
+ }
15
+
16
+ after { reset_authentication_for(subject) }
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
+ context "resouce created" do
25
+ let(:body) { fixture('repos/download_s3.json') }
26
+ let(:status) { 201}
27
+
28
+ it "should fail to create resource if 'name' input is missing" do
29
+ expect {
30
+ subject.create user, repo, inputs.except(:name)
31
+ }.to raise_error(Github::Error::RequiredParams)
32
+ end
33
+
34
+ it "should failt to create resource if 'size' input is missing" do
35
+ expect {
36
+ subject.create user, repo, inputs.except(:size)
37
+ }.to raise_error(Github::Error::RequiredParams)
38
+ end
39
+
40
+ it "should create resource successfully" do
41
+ subject.create user, repo, inputs
42
+ a_post(request_path).with(inputs).should have_been_made
43
+ end
44
+
45
+ it "should return the resource" do
46
+ download = subject.create user, repo, inputs
47
+ download.should be_a Hashie::Mash
48
+ end
49
+
50
+ it "should get the download information" do
51
+ download = subject.create user, repo, inputs
52
+ download.name.should == 'new_file.jpg'
53
+ end
54
+ end
55
+
56
+ context "failed to create resource" do
57
+ let(:body) { "" }
58
+ let(:status) { [404, "Not Found"] }
59
+
60
+ it "should faile to retrieve resource" do
61
+ expect {
62
+ subject.create user, repo, inputs
63
+ }.to raise_error(Github::Error::NotFound)
64
+ end
65
+ end
66
+ end # create
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Downloads, '#delete' do
6
+ let(:github) { Github.new }
7
+ let(:user) { 'peter-murach' }
8
+ let(:repo) { 'github' }
9
+ let(:download_id) { 1 }
10
+ let(:request_path) { "/repos/#{user}/#{repo}/downloads/#{download_id}" }
11
+
12
+ after { reset_authentication_for(github) }
13
+
14
+ before do
15
+ stub_delete(request_path).
16
+ to_return(:body => body, :status => status,
17
+ :headers => { :content_type => "application/json; charset=utf-8"})
18
+ end
19
+
20
+ context "resource deleted successfully" do
21
+ let(:body) { "" }
22
+ let(:status) { 204 }
23
+
24
+ it "should fail to delete without 'user/repo' parameters" do
25
+ expect { subject.delete }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it "should fail to delete resource without 'download_id'" do
29
+ expect { subject.delete user, repo }.to raise_error(ArgumentError)
30
+ end
31
+
32
+ it "should delete the resource" do
33
+ github.repos.downloads.delete user, repo, download_id
34
+ a_delete(request_path).should have_been_made
35
+ end
36
+ end
37
+
38
+ context "failed to delete resource" do
39
+ let(:body) { "" }
40
+ let(:status) { [404, "Not Found"] }
41
+
42
+ it "should fail to find resource" do
43
+ expect {
44
+ subject.delete user, repo, download_id
45
+ }.to raise_error(Github::Error::NotFound)
46
+ end
47
+ end
48
+ end # delete