github_api 0.6.5 → 0.7.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.
Files changed (44) hide show
  1. data/features/cassettes/{repos → issues}/assignees/ckeck.yml +0 -0
  2. data/features/cassettes/{repos → issues}/assignees/ckeck_not.yml +0 -0
  3. data/features/cassettes/{repos → issues}/assignees/list.yml +0 -0
  4. data/features/cassettes/repos/starring/list.yml +98 -0
  5. data/features/cassettes/repos/starring/star.yml +48 -0
  6. data/features/cassettes/repos/starring/starred.yml +195 -0
  7. data/features/cassettes/repos/starring/starring.yml +56 -0
  8. data/features/cassettes/repos/starring/unstar.yml +46 -0
  9. data/features/cassettes/repos/statuses/create.yml +52 -0
  10. data/features/cassettes/repos/statuses/list.yml +64 -0
  11. data/features/cassettes/repos/watching/list.yml +76 -0
  12. data/features/cassettes/repos/watching/unwatch.yml +46 -0
  13. data/features/cassettes/repos/watching/watch.yml +48 -0
  14. data/features/cassettes/repos/watching/watched.yml +166 -0
  15. data/features/cassettes/repos/watching/watching.yml +56 -0
  16. data/features/{repos → issues}/assignees.feature +5 -5
  17. data/features/repos/starring.feature +50 -0
  18. data/features/repos/statuses.feature +27 -0
  19. data/features/repos/watching.feature +50 -0
  20. data/lib/github_api/error/service_error.rb +5 -2
  21. data/lib/github_api/issues.rb +6 -0
  22. data/lib/github_api/{repos → issues}/assignees.rb +2 -2
  23. data/lib/github_api/jsonable.rb +17 -0
  24. data/lib/github_api/orgs/teams.rb +45 -45
  25. data/lib/github_api/repos.rb +23 -11
  26. data/lib/github_api/repos/commits.rb +4 -3
  27. data/lib/github_api/repos/merging.rb +40 -0
  28. data/lib/github_api/repos/starring.rb +97 -0
  29. data/lib/github_api/repos/statuses.rb +64 -0
  30. data/lib/github_api/repos/watching.rb +16 -13
  31. data/lib/github_api/response.rb +1 -0
  32. data/lib/github_api/response/jsonize.rb +4 -5
  33. data/lib/github_api/version.rb +2 -2
  34. data/spec/fixtures/repos/merge.json +48 -0
  35. data/spec/fixtures/repos/stargazers.json +9 -0
  36. data/spec/fixtures/repos/starred.json +34 -0
  37. data/spec/fixtures/repos/status.json +16 -0
  38. data/spec/fixtures/repos/statuses.json +18 -0
  39. data/spec/github/{repos → issues}/assignees_spec.rb +2 -2
  40. data/spec/github/repos/merging_spec.rb +71 -0
  41. data/spec/github/repos/starring_spec.rb +203 -0
  42. data/spec/github/repos/statuses_spec.rb +124 -0
  43. data/spec/github/repos/watching_spec.rb +37 -35
  44. metadata +66 -39
@@ -0,0 +1,9 @@
1
+ [
2
+ {
3
+ "login": "octocat",
4
+ "id": 1,
5
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
6
+ "gravatar_id": "somehexcode",
7
+ "url": "https://api.github.com/users/octocat"
8
+ }
9
+ ]
@@ -0,0 +1,34 @@
1
+ [
2
+ {
3
+ "url": "https://api.github.com/repos/octocat/Hello-World",
4
+ "html_url": "https://github.com/octocat/Hello-World",
5
+ "clone_url": "https://github.com/octocat/Hello-World.git",
6
+ "git_url": "git://github.com/octocat/Hello-World.git",
7
+ "ssh_url": "git@github.com:octocat/Hello-World.git",
8
+ "svn_url": "https://svn.github.com/octocat/Hello-World",
9
+ "mirror_url": "git://git.example.com/octocat/Hello-World",
10
+ "id": 1296269,
11
+ "owner": {
12
+ "login": "octocat",
13
+ "id": 1,
14
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
15
+ "gravatar_id": "somehexcode",
16
+ "url": "https://api.github.com/users/octocat"
17
+ },
18
+ "name": "Hello-World",
19
+ "full_name": "octocat/Hello-World",
20
+ "description": "This your first repo!",
21
+ "homepage": "https://github.com",
22
+ "language": null,
23
+ "private": false,
24
+ "fork": false,
25
+ "forks": 9,
26
+ "watchers": 80,
27
+ "size": 108,
28
+ "master_branch": "master",
29
+ "open_issues": 0,
30
+ "pushed_at": "2011-01-26T19:06:43Z",
31
+ "created_at": "2011-01-26T19:01:12Z",
32
+ "updated_at": "2011-01-26T19:14:43Z"
33
+ }
34
+ ]
@@ -0,0 +1,16 @@
1
+ {
2
+ "created_at": "2012-07-20T01:19:13Z",
3
+ "updated_at": "2012-07-20T01:19:13Z",
4
+ "state": "success",
5
+ "target_url": "https://ci.example.com/1000/output",
6
+ "description": "Build has completed successfully",
7
+ "id": 1,
8
+ "url": "https://api.github.com/repos/octocat/example/statuses/1",
9
+ "creator": {
10
+ "login": "octocat",
11
+ "id": 1,
12
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
13
+ "gravatar_id": "somehexcode",
14
+ "url": "https://api.github.com/users/octocat"
15
+ }
16
+ }
@@ -0,0 +1,18 @@
1
+ [
2
+ {
3
+ "created_at": "2012-07-20T01:19:13Z",
4
+ "updated_at": "2012-07-20T01:19:13Z",
5
+ "state": "success",
6
+ "target_url": "https://ci.example.com/1000/output",
7
+ "description": "Build has completed successfully",
8
+ "id": 1,
9
+ "url": "https://api.github.com/repos/octocat/example/statuses/1",
10
+ "creator": {
11
+ "login": "octocat",
12
+ "id": 1,
13
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
14
+ "gravatar_id": "somehexcode",
15
+ "url": "https://api.github.com/users/octocat"
16
+ }
17
+ }
18
+ ]
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Repos::Assignees do
4
- let(:github) { Github::Repos::Assignees.new }
3
+ describe Github::Issues::Assignees do
4
+ let(:github) { Github::Issues::Assignees.new }
5
5
  let(:user) { 'peter-murach' }
6
6
  let(:repo) { 'github' }
7
7
  let(:assignee) { 'octocat' }
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Repos::Merging do
4
+ let(:github) { Github.new }
5
+ let(:user) { 'peter-murach' }
6
+ let(:repo) { 'github' }
7
+
8
+ after { github.user, github.repo, github.oauth_token = nil, nil, nil }
9
+
10
+ describe "#merge" do
11
+ let(:inputs) do
12
+ {
13
+ "base" => "master",
14
+ "head" => "cool_feature",
15
+ "commit_message" => "Shipped cool_feature!"
16
+ }
17
+ end
18
+
19
+ context "resouce merged" do
20
+ before do
21
+ stub_post("/repos/#{user}/#{repo}/merges").with(inputs).
22
+ to_return(:body => fixture('repos/merge.json'),
23
+ :status => 201,
24
+ :headers => {:content_type => "application/json; charset=utf-8"})
25
+ end
26
+
27
+ it "should fail to merge resource if 'base' input is missing" do
28
+ expect {
29
+ github.repos.merging.merge user, repo, inputs.except('base')
30
+ }.to raise_error(Github::Error::RequiredParams)
31
+ end
32
+
33
+ it "should fail to create resource if 'head' input is missing" do
34
+ expect {
35
+ github.repos.merging.merge user, repo, inputs.except('head')
36
+ }.to raise_error(Github::Error::RequiredParams)
37
+ end
38
+
39
+ it "should merge resource successfully" do
40
+ github.repos.merging.merge user, repo, inputs
41
+ a_post("/repos/#{user}/#{repo}/merges").with(inputs).should have_been_made
42
+ end
43
+
44
+ it "should return the resource" do
45
+ merge = github.repos.merging.merge user, repo, inputs
46
+ merge.should be_a Hashie::Mash
47
+ end
48
+
49
+ it "should get the commit comment information" do
50
+ merge = github.repos.merging.merge user, repo, inputs
51
+ merge.commit.author.login.should == 'octocat'
52
+ end
53
+ end
54
+
55
+ context "failed to create resource" do
56
+ before do
57
+ stub_post("/repos/#{user}/#{repo}/merges").with(inputs).
58
+ to_return(:body => fixture('repos/merge.json'),
59
+ :status => 404,
60
+ :headers => {:content_type => "application/json; charset=utf-8"})
61
+ end
62
+
63
+ it "should fail to retrieve resource" do
64
+ expect {
65
+ github.repos.merging.merge user, repo, inputs
66
+ }.to raise_error(Github::Error::NotFound)
67
+ end
68
+ end
69
+ end # merge
70
+
71
+ end # Github::Repos::Merging
@@ -0,0 +1,203 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Starring do
6
+ let(:github) { Github.new }
7
+ let(:user) { 'peter-murach' }
8
+ let(:repo) { 'github' }
9
+
10
+ after { github.user, github.repo, github.oauth_token = nil, nil, nil }
11
+
12
+ describe "#list" do
13
+ before do
14
+ stub_get("/repos/#{user}/#{repo}/stargazers").
15
+ to_return(:body => fixture("repos/stargazers.json"),
16
+ :status => 200, :headers => {})
17
+ end
18
+
19
+ it "should fail to get resource without username" do
20
+ expect {
21
+ github.repos.starring.list
22
+ }.to raise_error(ArgumentError)
23
+ end
24
+
25
+ it "should yield iterator if block given" do
26
+ github.repos.starring.should_receive(:list).
27
+ with(user, repo).and_yield('github')
28
+ github.repos.starring.list(user, repo) { |param| 'github' }
29
+ end
30
+
31
+ it "should get the resources" do
32
+ github.repos.starring.list user, repo
33
+ a_get("/repos/#{user}/#{repo}/stargazers").should have_been_made
34
+ end
35
+
36
+ it "should return array of resources" do
37
+ stargazers = github.repos.starring.list user, repo
38
+ stargazers.should be_an Array
39
+ stargazers.should have(1).items
40
+ end
41
+
42
+ it "should return result of mash type" do
43
+ stargazers = github.repos.starring.list user, repo
44
+ stargazers.first.should be_a Hashie::Mash
45
+ end
46
+
47
+ it "should get watcher information" do
48
+ stargazers = github.repos.starring.list user, repo
49
+ stargazers.first.login.should == 'octocat'
50
+ end
51
+
52
+ context "fail to find resource" do
53
+ before do
54
+ stub_get("/repos/#{user}/#{repo}/stargazers").
55
+ to_return(:body => "", :status => 404)
56
+ end
57
+
58
+ it "should return 404 not found message" do
59
+ expect {
60
+ github.repos.starring.list user, repo
61
+ }.to raise_error(Github::Error::NotFound)
62
+ end
63
+ end
64
+ end
65
+
66
+ describe "#starred" do
67
+ context "if user unauthenticated" do
68
+ it "should fail to get resource without username " do
69
+ stub_get("/user/starred").
70
+ to_return(:body => '', :status => 401, :headers => {})
71
+ expect {
72
+ github.repos.starring.starred
73
+ }.to raise_error(Github::Error::Unauthorized)
74
+ end
75
+
76
+ it "should get the resource with username" do
77
+ stub_get("/users/#{user}/starred").
78
+ to_return(:body => fixture("repos/starred.json"), :status => 200, :headers => {})
79
+ github.repos.starring.starred :user => user
80
+ a_get("/users/#{user}/starred").should have_been_made
81
+ end
82
+ end
83
+
84
+ context "if user authenticated" do
85
+ before do
86
+ github.oauth_token = OAUTH_TOKEN
87
+ stub_get("/user/starred").
88
+ with(:query => {:access_token => OAUTH_TOKEN}).
89
+ to_return(:body => fixture("repos/starred.json"),
90
+ :status => 200, :headers => {})
91
+ end
92
+
93
+ it "should get the resources" do
94
+ github.repos.starring.starred
95
+ a_get("/user/starred").with(:query => {:access_token => OAUTH_TOKEN}).
96
+ should have_been_made
97
+ end
98
+
99
+ it "should return array of resources" do
100
+ starred = github.repos.starring.starred
101
+ starred.should be_an Array
102
+ starred.should have(1).items
103
+ end
104
+
105
+ it "should get starred information" do
106
+ starred = github.repos.starring.starred
107
+ starred.first.name.should == 'Hello-World'
108
+ starred.first.owner.login.should == 'octocat'
109
+ end
110
+ end
111
+ end # starred
112
+
113
+ describe "starring?" do
114
+ context "with username ane reponame passed" do
115
+ context "this repo is being watched by the user"
116
+ before do
117
+ stub_get("/user/starred/#{user}/#{repo}").
118
+ to_return(:body => "", :status => 404,
119
+ :headers => {:user_agent => github.user_agent})
120
+ end
121
+
122
+ it "should return false if resource not found" do
123
+ starring = github.repos.starring.starring? user, repo
124
+ starring.should be_false
125
+ end
126
+
127
+ it "should return true if resoure found" do
128
+ stub_get("/user/starred/#{user}/#{repo}").
129
+ to_return(:body => "", :status => 200,
130
+ :headers => {:user_agent => github.user_agent})
131
+ starring = github.repos.starring.starring? user, repo
132
+ starring.should be_true
133
+ end
134
+ end
135
+
136
+ context "without username and reponame passed" do
137
+ it "should fail validation " do
138
+ expect {
139
+ github.repos.starring.starring?(nil, nil)
140
+ }.to raise_error(ArgumentError)
141
+ end
142
+ end
143
+ end # starring?
144
+
145
+ describe "#star" do
146
+ context "user authenticated" do
147
+ context "with correct information" do
148
+ before do
149
+ github.oauth_token = OAUTH_TOKEN
150
+ stub_put("/user/starred/#{user}/#{repo}").
151
+ with(:query => {:access_token => OAUTH_TOKEN}).
152
+ to_return(:body => "", :status => 204, :headers => {})
153
+ end
154
+
155
+ it "should successfully star a repo" do
156
+ github.repos.starring.star user, repo
157
+ a_put("/user/starred/#{user}/#{repo}").
158
+ with(:query => {:access_token => OAUTH_TOKEN}).
159
+ should have_been_made
160
+ end
161
+ end
162
+ end
163
+
164
+ context "user unauthenticated" do
165
+ it "should fail" do
166
+ stub_put("/user/starred/#{user}/#{repo}").
167
+ to_return(:body => "", :status => 401, :headers => {})
168
+ expect {
169
+ github.repos.starring.star user, repo
170
+ }.to raise_error(Github::Error::Unauthorized)
171
+ end
172
+ end
173
+ end # star
174
+
175
+ describe "#unstar" do
176
+ context "user authenticated" do
177
+ context "with correct information" do
178
+ before do
179
+ github.oauth_token = OAUTH_TOKEN
180
+ stub_delete("/user/starred/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").
181
+ to_return(:body => "", :status => 204, :headers => {})
182
+ end
183
+
184
+ it "should successfully unstar a repo" do
185
+ github.repos.starring.unstar user, repo
186
+ a_delete("/user/starred/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").
187
+ should have_been_made
188
+ end
189
+ end
190
+ end
191
+
192
+ context "user unauthenticated" do
193
+ it "should fail" do
194
+ stub_delete("/user/starred/#{user}/#{repo}").
195
+ to_return(:body => "", :status => 401, :headers => {})
196
+ expect {
197
+ github.repos.starring.unstar user, repo
198
+ }.to raise_error(Github::Error::Unauthorized)
199
+ end
200
+ end
201
+ end # stop_watching
202
+
203
+ end # Github::Respos::Starring
@@ -0,0 +1,124 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Statuses do
6
+ let(:github) { Github.new }
7
+ let(:user) { 'peter-murach' }
8
+ let(:repo) { 'github' }
9
+ let(:sha) { 'f5f71ce1b7295c31f091be1654618c7ec0cc6b71' }
10
+
11
+ after { github.user, github.repo, github.oauth_token = nil, nil, nil }
12
+
13
+ it { described_class::VALID_STATUS_PARAM_NAMES.should_not be_nil }
14
+ it { described_class::REQUIRED_PARAMS.should_not be_nil }
15
+
16
+ describe "#list" do
17
+ it { github.repos.statuses.should respond_to :all }
18
+
19
+ context "resource found" do
20
+ before do
21
+ stub_get("/repos/#{user}/#{repo}/statuses/#{sha}").
22
+ to_return(:body => fixture('repos/statuses.json'), :status => 200,
23
+ :headers => {:content_type => "application/json; charset=utf-8"})
24
+ end
25
+
26
+ it "should fail to get resource without sha" do
27
+ expect { github.repos.statuses.list }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should get the resources" do
31
+ github.repos.statuses.list user, repo, sha
32
+ a_get("/repos/#{user}/#{repo}/statuses/#{sha}").should have_been_made
33
+ end
34
+
35
+ it "should return array of resources" do
36
+ statuses = github.repos.statuses.list user, repo, sha
37
+ statuses.should be_an Array
38
+ statuses.should have(1).items
39
+ end
40
+
41
+ it "should be a mash type" do
42
+ statuses = github.repos.statuses.list user, repo, sha
43
+ statuses.first.should be_a Hashie::Mash
44
+ end
45
+
46
+ it "should get status information" do
47
+ statuses = github.repos.statuses.list user, repo, sha
48
+ statuses.first.state.should == 'success'
49
+ end
50
+
51
+ it "should yield to a block" do
52
+ github.repos.statuses.should_receive(:list).with(user, repo, sha).and_yield('web')
53
+ github.repos.statuses.list(user, repo, sha) { |param| 'web' }
54
+ end
55
+ end
56
+
57
+ context "resource not found" do
58
+ before do
59
+ stub_get("/repos/#{user}/#{repo}/statuses/#{sha}").
60
+ to_return(:body => "", :status => [404, "Not Found"])
61
+ end
62
+
63
+ it "should return 404 with a message 'Not Found'" do
64
+ expect {
65
+ github.repos.statuses.list user, repo, sha
66
+ }.to raise_error(Github::Error::NotFound)
67
+ end
68
+ end
69
+ end # list
70
+
71
+ describe "#create" do
72
+ let(:inputs) {
73
+ {
74
+ 'state' => 'success'
75
+ }
76
+ }
77
+
78
+ context "resource created" do
79
+ before do
80
+ stub_post("/repos/#{user}/#{repo}/statuses/#{sha}").
81
+ with(inputs.except('unrelated')).
82
+ to_return(:body => fixture('repos/status.json'),
83
+ :status => 201,
84
+ :headers => {:content_type => "application/json; charset=utf-8"})
85
+ end
86
+
87
+ it "should fail to create resource if 'state' input is missing" do
88
+ expect {
89
+ github.repos.statuses.create user, repo, sha, inputs.except('state')
90
+ }.to raise_error(Github::Error::RequiredParams)
91
+ end
92
+
93
+ it "should create resource successfully" do
94
+ github.repos.statuses.create user, repo, sha, inputs
95
+ a_post("/repos/#{user}/#{repo}/statuses/#{sha}").with(inputs).should have_been_made
96
+ end
97
+
98
+ it "should return the resource" do
99
+ status = github.repos.statuses.create user, repo, sha, inputs
100
+ status.should be_a Hashie::Mash
101
+ end
102
+
103
+ it "should get the status information" do
104
+ status = github.repos.statuses.create user, repo, sha, inputs
105
+ status.state.should == 'success'
106
+ end
107
+ end
108
+
109
+ context "fail to create resource" do
110
+ before do
111
+ stub_post("/repos/#{user}/#{repo}/statuses/#{sha}").with(inputs).
112
+ to_return(:body => fixture('repos/status.json'), :status => 404,
113
+ :headers => {:content_type => "application/json; charset=utf-8"})
114
+ end
115
+
116
+ it "should fail to retrieve resource" do
117
+ expect {
118
+ github.repos.statuses.create user, repo, sha, inputs
119
+ }.to raise_error(Github::Error::NotFound)
120
+ end
121
+ end
122
+ end # create
123
+
124
+ end # Github::Repos::Statuses