github_api 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -1
- data/features/support/vcr.rb +6 -0
- data/lib/github_api.rb +2 -2
- data/lib/github_api/api.rb +3 -1
- data/lib/github_api/issues/labels.rb +22 -10
- data/lib/github_api/request.rb +1 -1
- data/lib/github_api/version.rb +1 -1
- data/spec/fixtures/issues/label.json +5 -0
- data/spec/fixtures/issues/labels.json +7 -0
- data/spec/github/issues/labels_spec.rb +532 -2
- data/spec/support/github_api_shared_examples.rb +40 -0
- metadata +6 -2
data/README.rdoc
CHANGED
@@ -26,6 +26,13 @@ At this stage you can also supply various configuration parameters, such as :use
|
|
26
26
|
|
27
27
|
@github = Github.new :user => 'peter-murach', :repo => 'github-api'
|
28
28
|
|
29
|
+
or
|
30
|
+
|
31
|
+
@github = Github.new do |opts|
|
32
|
+
opts.user = 'peter-murach'
|
33
|
+
opts.repo = 'github-api'
|
34
|
+
end
|
35
|
+
|
29
36
|
You can authenticate either using OAuth authentication convenience methods(see section OAuth) or through basic authentication by passing your login and password credentials
|
30
37
|
|
31
38
|
@github = Github.new :login => 'peter-murach', :password => '...'
|
@@ -45,7 +52,7 @@ The code base is modular and allows for you to work specifically with a given pa
|
|
45
52
|
@repos = Github::Repos.new
|
46
53
|
@repos.branches 'peter-murach', 'github'
|
47
54
|
|
48
|
-
or
|
55
|
+
or
|
49
56
|
|
50
57
|
@repos = Github::Repos.new :user => 'peter-murach', :repo => 'github'
|
51
58
|
@repos.branches
|
data/lib/github_api.rb
CHANGED
data/lib/github_api/api.rb
CHANGED
@@ -36,13 +36,15 @@ module Github
|
|
36
36
|
end
|
37
37
|
|
38
38
|
# Creates new API
|
39
|
-
def initialize(options = {})
|
39
|
+
def initialize(options = {}, &block)
|
40
40
|
options = Github.options.merge(options)
|
41
41
|
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
42
42
|
send("#{key}=", options[key])
|
43
43
|
end
|
44
44
|
_process_basic_auth(options[:basic_auth])
|
45
45
|
client if client_id? && client_secret?
|
46
|
+
|
47
|
+
self.instance_eval(&block) if block_given?
|
46
48
|
end
|
47
49
|
|
48
50
|
private
|
@@ -4,7 +4,7 @@ module Github
|
|
4
4
|
class Issues
|
5
5
|
module Labels
|
6
6
|
|
7
|
-
VALID_LABEL_INPUTS = %w[ name color ]
|
7
|
+
VALID_LABEL_INPUTS = %w[ name color ].freeze
|
8
8
|
|
9
9
|
# List all labels for a repository
|
10
10
|
#
|
@@ -22,6 +22,7 @@ module Github
|
|
22
22
|
return response unless block_given?
|
23
23
|
response.each { |el| yield el }
|
24
24
|
end
|
25
|
+
alias :list_labels :labels
|
25
26
|
|
26
27
|
# Get a single label
|
27
28
|
#
|
@@ -32,10 +33,12 @@ module Github
|
|
32
33
|
def label(user_name, repo_name, label_id, params={})
|
33
34
|
_update_user_repo_params(user_name, repo_name)
|
34
35
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
36
|
+
_validate_presence_of label_id
|
35
37
|
_normalize_params_keys(params)
|
36
38
|
|
37
39
|
get("/repos/#{user}/#{repo}/labels/#{label_id}", params)
|
38
40
|
end
|
41
|
+
alias :get_label :label
|
39
42
|
|
40
43
|
# Create a label
|
41
44
|
#
|
@@ -91,8 +94,9 @@ module Github
|
|
91
94
|
def delete_label(user_name, repo_name, label_id, params={})
|
92
95
|
_update_user_repo_params(user_name, repo_name)
|
93
96
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
94
|
-
|
95
|
-
|
97
|
+
|
98
|
+
_validate_presence_of label_id
|
99
|
+
_normalize_params_keys params
|
96
100
|
|
97
101
|
delete("/repos/#{user}/#{repo}/labels/#{label_id}", params)
|
98
102
|
end
|
@@ -111,6 +115,7 @@ module Github
|
|
111
115
|
|
112
116
|
get("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
|
113
117
|
end
|
118
|
+
alias :issue_labels :labels_for
|
114
119
|
|
115
120
|
# Add labels to an issue
|
116
121
|
#
|
@@ -120,7 +125,8 @@ module Github
|
|
120
125
|
#
|
121
126
|
def add_labels(user_name, repo_name, issue_id, *args)
|
122
127
|
params = args.last.is_a?(Hash) ? args.pop : {}
|
123
|
-
params['data'] =
|
128
|
+
params['data'] = args unless args.empty?
|
129
|
+
|
124
130
|
_update_user_repo_params(user_name, repo_name)
|
125
131
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
126
132
|
_validate_presence_of(issue_id)
|
@@ -128,6 +134,7 @@ module Github
|
|
128
134
|
|
129
135
|
post("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
|
130
136
|
end
|
137
|
+
alias :add_issue_labels :add_labels
|
131
138
|
|
132
139
|
# Remove a label from an issue
|
133
140
|
#
|
@@ -143,8 +150,8 @@ module Github
|
|
143
150
|
def remove_label(user_name, repo_name, issue_id, label_id=nil, params={})
|
144
151
|
_update_user_repo_params(user_name, repo_name)
|
145
152
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
146
|
-
_validate_presence_of
|
147
|
-
_normalize_params_keys
|
153
|
+
_validate_presence_of issue_id
|
154
|
+
_normalize_params_keys params
|
148
155
|
|
149
156
|
if label_id
|
150
157
|
delete("/repos/#{user}/#{repo}/issues/#{issue_id}/labels/#{label_id}", params)
|
@@ -152,13 +159,14 @@ module Github
|
|
152
159
|
delete("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
|
153
160
|
end
|
154
161
|
end
|
162
|
+
alias :remove_label_from_issue :remove_label
|
155
163
|
|
156
164
|
# Replace all labels for an issue
|
157
165
|
#
|
158
166
|
# Sending an empty array ([]) will remove all Labels from the Issue.
|
159
167
|
#
|
160
168
|
# = Examples
|
161
|
-
# @github = Github.new
|
169
|
+
# @github = Github.new
|
162
170
|
# @github.issues.replace_labels 'user-name', 'repo-name', 'issue-id', 'label1', 'label2', ...
|
163
171
|
#
|
164
172
|
def replace_labels(user_name, repo_name, issue_id, *args)
|
@@ -178,13 +186,17 @@ module Github
|
|
178
186
|
# @github = Github.new
|
179
187
|
# @github.issues.get_label 'user-name', 'repo-name', 'milestone-id'
|
180
188
|
#
|
181
|
-
def
|
189
|
+
def milestone_labels(user_name, repo_name, milestone_id, params={})
|
182
190
|
_update_user_repo_params(user_name, repo_name)
|
183
191
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
184
|
-
_validate_presence_of
|
192
|
+
_validate_presence_of milestone_id
|
185
193
|
|
186
|
-
get("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels", params)
|
194
|
+
response = get("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels", params)
|
195
|
+
return response unless block_given?
|
196
|
+
response.each { |el| yield el }
|
187
197
|
end
|
198
|
+
alias :milestone_issues_labels :milestone_labels
|
199
|
+
alias :list_milestone_labels :milestone_labels
|
188
200
|
|
189
201
|
end # Labels
|
190
202
|
end # Issues
|
data/lib/github_api/request.rb
CHANGED
data/lib/github_api/version.rb
CHANGED
@@ -1,5 +1,535 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Github::Issues::Labels do
|
4
|
-
|
5
|
-
|
4
|
+
include SpecHelpers::Base
|
5
|
+
|
6
|
+
it { described_class::VALID_LABEL_INPUTS.should_not be_nil }
|
7
|
+
|
8
|
+
describe 'labels' do
|
9
|
+
it { github.issues.should respond_to :labels }
|
10
|
+
it { github.issues.should respond_to :list_labels }
|
11
|
+
|
12
|
+
context "resource found" do
|
13
|
+
before do
|
14
|
+
stub_get("/repos/#{user}/#{repo}/labels").
|
15
|
+
to_return(:body => fixture('issues/labels.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should fail to get resource without username" do
|
19
|
+
github.user, github.repo = nil, nil
|
20
|
+
expect { github.issues.labels nil, repo }.to raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should get the resources" do
|
24
|
+
github.issues.labels user, repo
|
25
|
+
a_get("/repos/#{user}/#{repo}/labels").should have_been_made
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return array of resources" do
|
29
|
+
labels = github.issues.labels user, repo
|
30
|
+
labels.should be_an Array
|
31
|
+
labels.should have(1).items
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be a mash type" do
|
35
|
+
labels = github.issues.labels user, repo
|
36
|
+
labels.first.should be_a Hashie::Mash
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should get issue information" do
|
40
|
+
labels = github.issues.labels user, repo
|
41
|
+
labels.first.name.should == 'bug'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should yield to a block" do
|
45
|
+
github.issues.should_receive(:labels).with(user, repo).and_yield('web')
|
46
|
+
github.issues.labels(user, repo) { |param| 'web' }.should == 'web'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "resource not found" do
|
51
|
+
before do
|
52
|
+
stub_get("/repos/#{user}/#{repo}/labels").
|
53
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return 404 with a message 'Not Found'" do
|
57
|
+
expect {
|
58
|
+
github.issues.labels user, repo
|
59
|
+
}.to raise_error(Github::ResourceNotFound)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end # labels
|
63
|
+
|
64
|
+
describe "label" do
|
65
|
+
let(:label_id) { 1 }
|
66
|
+
|
67
|
+
it { github.issues.should respond_to :label }
|
68
|
+
it { github.issues.should respond_to :get_label }
|
69
|
+
|
70
|
+
context "resource found" do
|
71
|
+
before do
|
72
|
+
stub_get("/repos/#{user}/#{repo}/labels/#{label_id}").
|
73
|
+
to_return(:body => fixture('issues/label.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should fail to get resource without label id" do
|
77
|
+
expect { github.issues.label(user, repo, nil)}.to raise_error(ArgumentError)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should get the resource" do
|
81
|
+
github.issues.label user, repo, label_id
|
82
|
+
a_get("/repos/#{user}/#{repo}/labels/#{label_id}").should have_been_made
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should get label information" do
|
86
|
+
label = github.issues.label user, repo, label_id
|
87
|
+
label.name.should == 'bug'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return mash" do
|
91
|
+
label = github.issues.label user, repo, label_id
|
92
|
+
label.should be_a Hashie::Mash
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "resource not found" do
|
97
|
+
before do
|
98
|
+
stub_get("/repos/#{user}/#{repo}/labels/#{label_id}").
|
99
|
+
to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should fail to retrive resource" do
|
103
|
+
expect {
|
104
|
+
github.issues.label user, repo, label_id
|
105
|
+
}.to raise_error(Github::ResourceNotFound)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end # label
|
109
|
+
|
110
|
+
describe "create_label" do
|
111
|
+
let(:inputs) {
|
112
|
+
{
|
113
|
+
"name" => "API",
|
114
|
+
"color" => "FFFFFF",
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
context "resouce created" do
|
119
|
+
before do
|
120
|
+
stub_post("/repos/#{user}/#{repo}/labels").with(inputs).
|
121
|
+
to_return(:body => fixture('issues/label.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should fail to create resource if 'name' input is missing" do
|
125
|
+
expect {
|
126
|
+
github.issues.create_label user, repo, inputs.except('name')
|
127
|
+
}.to raise_error(ArgumentError)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should fail to create resource if 'color' input is missing" do
|
131
|
+
expect {
|
132
|
+
github.issues.create_label user, repo, inputs.except('color')
|
133
|
+
}.to raise_error(ArgumentError)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should create resource successfully" do
|
137
|
+
github.issues.create_label user, repo, inputs
|
138
|
+
a_post("/repos/#{user}/#{repo}/labels").with(inputs).should have_been_made
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should return the resource" do
|
142
|
+
label = github.issues.create_label user, repo, inputs
|
143
|
+
label.should be_a Hashie::Mash
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should get the label information" do
|
147
|
+
label = github.issues.create_label user, repo, inputs
|
148
|
+
label.name.should == 'bug'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "failed to create resource" do
|
153
|
+
before do
|
154
|
+
stub_post("/repos/#{user}/#{repo}/labels").with(inputs).
|
155
|
+
to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should faile to retrieve resource" do
|
160
|
+
expect {
|
161
|
+
github.issues.create_label user, repo, inputs
|
162
|
+
}.to raise_error(Github::ResourceNotFound)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end # create_label
|
166
|
+
|
167
|
+
describe "update_label" do
|
168
|
+
let(:label_id) { 1 }
|
169
|
+
let(:inputs) {
|
170
|
+
{
|
171
|
+
"name" => "API",
|
172
|
+
"color" => "FFFFFF",
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
context "resouce updated" do
|
177
|
+
before do
|
178
|
+
stub_patch("/repos/#{user}/#{repo}/labels/#{label_id}").with(inputs).
|
179
|
+
to_return(:body => fixture('issues/label.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should fail to create resource if 'name' input is missing" do
|
183
|
+
expect {
|
184
|
+
github.issues.update_label user, repo, label_id, inputs.except('name')
|
185
|
+
}.to raise_error(ArgumentError)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should fail to create resource if 'color' input is missing" do
|
189
|
+
expect {
|
190
|
+
github.issues.update_label user, repo, label_id, inputs.except('color')
|
191
|
+
}.to raise_error(ArgumentError)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should update resource successfully" do
|
195
|
+
github.issues.update_label user, repo, label_id, inputs
|
196
|
+
a_patch("/repos/#{user}/#{repo}/labels/#{label_id}").with(inputs).should have_been_made
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should return the resource" do
|
200
|
+
label = github.issues.update_label user, repo, label_id, inputs
|
201
|
+
label.should be_a Hashie::Mash
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should get the label information" do
|
205
|
+
label = github.issues.update_label user, repo, label_id, inputs
|
206
|
+
label.name.should == 'bug'
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context "failed to create resource" do
|
211
|
+
before do
|
212
|
+
stub_patch("/repos/#{user}/#{repo}/labels/#{label_id}").with(inputs).
|
213
|
+
to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should faile to retrieve resource" do
|
218
|
+
expect {
|
219
|
+
github.issues.update_label user, repo, label_id, inputs
|
220
|
+
}.to raise_error(Github::ResourceNotFound)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end # update_label
|
224
|
+
|
225
|
+
describe "delete_label" do
|
226
|
+
let(:label_id) { 1 }
|
227
|
+
|
228
|
+
context "resouce removed" do
|
229
|
+
before do
|
230
|
+
stub_delete("/repos/#{user}/#{repo}/labels/#{label_id}").
|
231
|
+
to_return(:body => fixture('issues/label.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should remove resource successfully" do
|
235
|
+
github.issues.delete_label user, repo, label_id
|
236
|
+
a_delete("/repos/#{user}/#{repo}/labels/#{label_id}").should have_been_made
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should return the resource" do
|
240
|
+
label = github.issues.delete_label user, repo, label_id
|
241
|
+
label.should be_a Hashie::Mash
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should get the label information" do
|
245
|
+
label = github.issues.delete_label user, repo, label_id
|
246
|
+
label.name.should == 'bug'
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context "failed to remove resource" do
|
251
|
+
before do
|
252
|
+
stub_delete("/repos/#{user}/#{repo}/labels/#{label_id}").
|
253
|
+
to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should faile to retrieve resource" do
|
257
|
+
expect {
|
258
|
+
github.issues.delete_label user, repo, label_id
|
259
|
+
}.to raise_error(Github::ResourceNotFound)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end # delete_label
|
263
|
+
|
264
|
+
describe 'labels_for' do
|
265
|
+
let(:issue_id) { 1 }
|
266
|
+
|
267
|
+
it { github.issues.should respond_to :labels_for }
|
268
|
+
it { github.issues.should respond_to :issue_labels }
|
269
|
+
|
270
|
+
context "resource found" do
|
271
|
+
before do
|
272
|
+
stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
|
273
|
+
to_return(:body => fixture('issues/labels.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should fail to get resource without issue_id" do
|
277
|
+
expect {
|
278
|
+
github.issues.labels_for user, repo, nil
|
279
|
+
}.to raise_error(ArgumentError)
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should get the resources" do
|
283
|
+
github.issues.labels_for user, repo, issue_id
|
284
|
+
a_get("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").should have_been_made
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should return array of resources" do
|
288
|
+
labels = github.issues.labels_for user, repo, issue_id
|
289
|
+
labels.should be_an Array
|
290
|
+
labels.should have(1).items
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should be a mash type" do
|
294
|
+
labels = github.issues.labels_for user, repo, issue_id
|
295
|
+
labels.first.should be_a Hashie::Mash
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should get issue information" do
|
299
|
+
labels = github.issues.labels_for user, repo, issue_id
|
300
|
+
labels.first.name.should == 'bug'
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should yield to a block" do
|
304
|
+
github.issues.should_receive(:labels_for).with(user, repo, issue_id).and_yield('web')
|
305
|
+
github.issues.labels_for(user, repo, issue_id) { |param| 'web' }.should == 'web'
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context "resource not found" do
|
310
|
+
before do
|
311
|
+
stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
|
312
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should return 404 with a message 'Not Found'" do
|
316
|
+
expect {
|
317
|
+
github.issues.labels_for user, repo, issue_id
|
318
|
+
}.to raise_error(Github::ResourceNotFound)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end # labels_for
|
322
|
+
|
323
|
+
describe "add_labels" do
|
324
|
+
let(:issue_id) { 1 }
|
325
|
+
let(:labels) { "Label 1" }
|
326
|
+
|
327
|
+
context "labels added" do
|
328
|
+
before do
|
329
|
+
stub_post("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
|
330
|
+
to_return(:body => fixture('issues/labels.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should fail to add labels if issue-id is missing" do
|
334
|
+
expect {
|
335
|
+
github.issues.add_labels user, repo, nil, labels
|
336
|
+
}.to raise_error(ArgumentError)
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should create resource successfully" do
|
340
|
+
github.issues.add_labels user, repo, issue_id, labels
|
341
|
+
a_post("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").should have_been_made
|
342
|
+
end
|
343
|
+
|
344
|
+
it "should return the resource" do
|
345
|
+
labels = github.issues.add_labels user, repo, issue_id, labels
|
346
|
+
labels.first.should be_a Hashie::Mash
|
347
|
+
end
|
348
|
+
|
349
|
+
it "should get the label information" do
|
350
|
+
labels = github.issues.add_labels user, repo, issue_id, labels
|
351
|
+
labels.first.name.should == 'bug'
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
context "failed to add labels" do
|
356
|
+
before do
|
357
|
+
stub_post("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
|
358
|
+
to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
359
|
+
|
360
|
+
end
|
361
|
+
|
362
|
+
it "should fail to retrieve resource" do
|
363
|
+
expect {
|
364
|
+
github.issues.add_labels user, repo, issue_id, labels
|
365
|
+
}.to raise_error(Github::ResourceNotFound)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end # add_labels
|
369
|
+
|
370
|
+
describe "remove_label" do
|
371
|
+
let(:issue_id) { 1 }
|
372
|
+
let(:label_id) { 1 }
|
373
|
+
|
374
|
+
context "remove a label from an issue" do
|
375
|
+
before do
|
376
|
+
stub_delete("/repos/#{user}/#{repo}/issues/#{issue_id}/labels/#{label_id}").
|
377
|
+
to_return(:body => fixture('issues/labels.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
378
|
+
end
|
379
|
+
|
380
|
+
it "should throw exception if issue-id not present" do
|
381
|
+
expect {
|
382
|
+
github.issues.remove_label user, repo, nil
|
383
|
+
}.to raise_error(ArgumentError)
|
384
|
+
end
|
385
|
+
|
386
|
+
it "should remove label successfully" do
|
387
|
+
github.issues.remove_label user, repo, issue_id, label_id
|
388
|
+
a_delete("/repos/#{user}/#{repo}/issues/#{issue_id}/labels/#{label_id}").should have_been_made
|
389
|
+
end
|
390
|
+
|
391
|
+
it "should return the resource" do
|
392
|
+
labels = github.issues.remove_label user, repo, issue_id, label_id
|
393
|
+
labels.first.should be_a Hashie::Mash
|
394
|
+
end
|
395
|
+
|
396
|
+
it "should get the label information" do
|
397
|
+
labels = github.issues.remove_label user, repo, issue_id, label_id
|
398
|
+
labels.first.name.should == 'bug'
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
context "remove all labels from an issue" do
|
403
|
+
before do
|
404
|
+
stub_delete("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
|
405
|
+
to_return(:body => "", :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
|
406
|
+
end
|
407
|
+
|
408
|
+
it "should remove labels successfully" do
|
409
|
+
github.issues.remove_label user, repo, issue_id
|
410
|
+
a_delete("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").should have_been_made
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
context "failed to remove label from an issue" do
|
415
|
+
before do
|
416
|
+
stub_delete("/repos/#{user}/#{repo}/issues/#{issue_id}/labels/#{label_id}").
|
417
|
+
to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
418
|
+
end
|
419
|
+
|
420
|
+
it "should faile to retrieve resource" do
|
421
|
+
expect {
|
422
|
+
github.issues.remove_label user, repo, issue_id, label_id
|
423
|
+
}.to raise_error(Github::ResourceNotFound)
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end # remove_label
|
427
|
+
|
428
|
+
describe "replace_labels" do
|
429
|
+
let(:issue_id) { 1 }
|
430
|
+
let(:labels) { "Label 1" }
|
431
|
+
|
432
|
+
context "labels added" do
|
433
|
+
before do
|
434
|
+
stub_put("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
|
435
|
+
to_return(:body => fixture('issues/labels.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
436
|
+
end
|
437
|
+
|
438
|
+
it "should fail to add labels if issue-id is missing" do
|
439
|
+
expect {
|
440
|
+
github.issues.replace_labels user, repo, nil, labels
|
441
|
+
}.to raise_error(ArgumentError)
|
442
|
+
end
|
443
|
+
|
444
|
+
it "should create resource successfully" do
|
445
|
+
github.issues.replace_labels user, repo, issue_id, labels
|
446
|
+
a_put("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").should have_been_made
|
447
|
+
end
|
448
|
+
|
449
|
+
it "should return the resource" do
|
450
|
+
labels = github.issues.replace_labels user, repo, issue_id, labels
|
451
|
+
labels.first.should be_a Hashie::Mash
|
452
|
+
end
|
453
|
+
|
454
|
+
it "should get the label information" do
|
455
|
+
labels = github.issues.replace_labels user, repo, issue_id, labels
|
456
|
+
labels.first.name.should == 'bug'
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
context "failed to add labels" do
|
461
|
+
before do
|
462
|
+
stub_put("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
|
463
|
+
to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
464
|
+
|
465
|
+
end
|
466
|
+
|
467
|
+
it "should fail to retrieve resource" do
|
468
|
+
expect {
|
469
|
+
github.issues.replace_labels user, repo, issue_id, labels
|
470
|
+
}.to raise_error(Github::ResourceNotFound)
|
471
|
+
end
|
472
|
+
end
|
473
|
+
end # add_labels
|
474
|
+
|
475
|
+
describe 'milestone_labels' do
|
476
|
+
let(:milestone_id) { 1 }
|
477
|
+
|
478
|
+
it { github.issues.should respond_to :milestone_labels }
|
479
|
+
it { github.issues.should respond_to :milestone_issues_labels }
|
480
|
+
it { github.issues.should respond_to :list_milestone_labels }
|
481
|
+
|
482
|
+
context "resource found" do
|
483
|
+
before do
|
484
|
+
stub_get("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels").
|
485
|
+
to_return(:body => fixture('issues/labels.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
486
|
+
end
|
487
|
+
|
488
|
+
it "should throw exception if milestone-id not present" do
|
489
|
+
expect {
|
490
|
+
github.issues.remove_label user, repo, nil
|
491
|
+
}.to raise_error(ArgumentError)
|
492
|
+
end
|
493
|
+
|
494
|
+
it "should get the resources" do
|
495
|
+
github.issues.milestone_labels user, repo, milestone_id
|
496
|
+
a_get("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels").should have_been_made
|
497
|
+
end
|
498
|
+
|
499
|
+
it "should return array of resources" do
|
500
|
+
labels = github.issues.milestone_labels user, repo, milestone_id
|
501
|
+
labels.should be_an Array
|
502
|
+
labels.should have(1).items
|
503
|
+
end
|
504
|
+
|
505
|
+
it "should be a mash type" do
|
506
|
+
labels = github.issues.milestone_labels user, repo, milestone_id
|
507
|
+
labels.first.should be_a Hashie::Mash
|
508
|
+
end
|
509
|
+
|
510
|
+
it "should get issue information" do
|
511
|
+
labels = github.issues.milestone_labels user, repo, milestone_id
|
512
|
+
labels.first.name.should == 'bug'
|
513
|
+
end
|
514
|
+
|
515
|
+
it "should yield to a block" do
|
516
|
+
github.issues.should_receive(:milestone_labels).with(user, repo, milestone_id).and_yield('web')
|
517
|
+
github.issues.milestone_labels(user, repo, milestone_id) { |param| 'web' }.should == 'web'
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
context "resource not found" do
|
522
|
+
before do
|
523
|
+
stub_get("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels").
|
524
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
525
|
+
end
|
526
|
+
|
527
|
+
it "should return 404 with a message 'Not Found'" do
|
528
|
+
expect {
|
529
|
+
github.issues.milestone_labels user, repo, milestone_id
|
530
|
+
}.to raise_error(Github::ResourceNotFound)
|
531
|
+
end
|
532
|
+
end
|
533
|
+
end # milestone_labels
|
534
|
+
|
535
|
+
end # Github::Issues::Labels
|
@@ -0,0 +1,40 @@
|
|
1
|
+
shared_examples_for "collection of resources" do
|
2
|
+
|
3
|
+
context "resource found" do
|
4
|
+
before do
|
5
|
+
stub_get(resource_path).
|
6
|
+
to_return(:body => fixture(fixture_dir), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should fail to get resource without username" do
|
10
|
+
github.user, github.repo = nil, nil
|
11
|
+
expect { github.issues.milestones nil, repo }.to raise_error(ArgumentError)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should get the resources" do
|
15
|
+
github.send *method_chain, user, repo
|
16
|
+
a_get(resource_path).should have_been_made
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return array of resources" do
|
20
|
+
milestones = github.issues.milestones user, repo
|
21
|
+
milestones.should be_an Array
|
22
|
+
milestones.should have(1).items
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be a mash type" do
|
26
|
+
milestones = github.issues.milestones user, repo
|
27
|
+
milestones.first.should be_a Hashie::Mash
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should get issue information" do
|
31
|
+
milestones = github.issues.milestones user, repo
|
32
|
+
milestones.first.title.should == 'v1.0'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should yield to a block" do
|
36
|
+
github.issues.should_receive(:milestones).with(user, repo).and_yield('web')
|
37
|
+
github.issues.milestones(user, repo) { |param| 'web' }.should == 'web'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: github_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Piotr Murach
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2012-01-01 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- features/pagination.feature
|
172
172
|
- features/step_definitions/github_api_steps.rb
|
173
173
|
- features/support/env.rb
|
174
|
+
- features/support/vcr.rb
|
174
175
|
- lib/github_api/api/utils.rb
|
175
176
|
- lib/github_api/api.rb
|
176
177
|
- lib/github_api/authorization.rb
|
@@ -238,6 +239,8 @@ files:
|
|
238
239
|
- spec/fixtures/issues/events.json
|
239
240
|
- spec/fixtures/issues/issue.json
|
240
241
|
- spec/fixtures/issues/issues.json
|
242
|
+
- spec/fixtures/issues/label.json
|
243
|
+
- spec/fixtures/issues/labels.json
|
241
244
|
- spec/fixtures/issues/milestone.json
|
242
245
|
- spec/fixtures/issues/milestones.json
|
243
246
|
- spec/fixtures/orgs/members.json
|
@@ -309,6 +312,7 @@ files:
|
|
309
312
|
- spec/README.rdoc
|
310
313
|
- spec/spec_helper.rb
|
311
314
|
- spec/support/base.rb
|
315
|
+
- spec/support/github_api_shared_examples.rb
|
312
316
|
- README.rdoc
|
313
317
|
- LICENSE.txt
|
314
318
|
has_rdoc: true
|