github_api 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,11 @@ When /^(.*) within a cassette named "([^"]*)"$/ do |step_to_call, cassette_name|
6
6
  VCR.use_cassette(cassette_name) { step step_to_call }
7
7
  end
8
8
 
9
+ When /^(.*) within a cassette named "([^"]*)" and match on (.*)$/ do |step_to_call, cassette_name, matchers|
10
+ matches = matchers.split(',').map { |m| m.gsub(/\s*/,'') }.map(&:to_sym)
11
+ VCR.use_cassette(cassette_name, :match_requests_on => matches) { step step_to_call }
12
+ end
13
+
9
14
  Then /^the response should equal (.*)$/ do |expected_response|
10
15
  expected = case expected_response
11
16
  when /t/
@@ -3,7 +3,7 @@ require 'vcr'
3
3
  VCR.configure do |conf|
4
4
  conf.hook_into :webmock
5
5
  conf.cassette_library_dir = 'features/cassettes'
6
- conf.default_cassette_options = { :record => :new_episodes }
6
+ conf.default_cassette_options = { :record => :once }
7
7
  conf.filter_sensitive_data('<EMAIL>') { SETTINGS['email'] }
8
8
  conf.filter_sensitive_data('<TOKEN>') { SETTINGS['oauth_token'] }
9
9
  conf.filter_sensitive_data('<BASIC_AUTH>') { SETTINGS['basic_auth'] }
@@ -29,7 +29,7 @@ module Github
29
29
  ].freeze
30
30
 
31
31
  VALID_ISSUE_PARAM_VALUES = {
32
- 'filter' => %w[ assigned created mentioned subscribed ],
32
+ 'filter' => %w[ assigned created mentioned subscribed all ],
33
33
  'state' => %w[ open closed ],
34
34
  'sort' => %w[ created updated comments ],
35
35
  'direction' => %w[ desc asc ],
@@ -98,9 +98,10 @@ module Github
98
98
  # = Parameters
99
99
  # <tt>:filter</tt>
100
100
  # * <tt>assigned</tt> Issues assigned to you (default)
101
- # * <tt>created</tt> Issues assigned to you (default)
102
- # * <tt>mentioned</tt> Issues assigned to you (default)
103
- # * <tt>subscribed</tt> Issues assigned to you (default)
101
+ # * <tt>created</tt> Issues created by you
102
+ # * <tt>mentioned</tt> Issues mentioning you
103
+ # * <tt>subscribed</tt> Issues you've subscribed to updates for
104
+ # * <tt>all</tt> All issues the user can see
104
105
  # <tt>:milestone</tt>
105
106
  # * Integer Milestone number
106
107
  # * <tt>none</tt> for Issues with no Milestone.
@@ -17,12 +17,30 @@ module Github
17
17
  # github.issues.labels.list
18
18
  # github.issues.labels.list { |label| ... }
19
19
  #
20
+ # Get labels for every issue in a milestone
21
+ #
22
+ # = Examples
23
+ # github = Github.new
24
+ # github.issues.labels.list 'user-name', 'repo-name', milestone_id: 'milestone-id'
25
+ #
26
+ # List labels on an issue
27
+ #
28
+ # = Examples
29
+ # @github = Github.new
30
+ # @github.issues.labels.list 'user-name', 'repo-name', issue_id: 'issue-id'
31
+ #
20
32
  def list(user_name, repo_name, params={})
21
33
  set :user => user_name, :repo => repo_name
22
34
  assert_presence_of user, repo
23
35
  normalize! params
24
36
 
25
- response = get_request("/repos/#{user}/#{repo}/labels", params)
37
+ response = if (milestone_id = params.delete('milestone_id'))
38
+ get_request("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels", params)
39
+ elsif (issue_id = params.delete('issue_id'))
40
+ get_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
41
+ else
42
+ get_request("/repos/#{user}/#{repo}/labels", params)
43
+ end
26
44
  return response unless block_given?
27
45
  response.each { |el| yield el }
28
46
  end
@@ -32,14 +50,14 @@ module Github
32
50
  #
33
51
  # = Examples
34
52
  # github = Github.new
35
- # github.issues.labels.find 'user-name', 'repo-name', 'label-id'
53
+ # github.issues.labels.find 'user-name', 'repo-name', 'label-name'
36
54
  #
37
- def get(user_name, repo_name, label_id, params={})
55
+ def get(user_name, repo_name, label_name, params={})
38
56
  set :user => user_name, :repo => repo_name
39
- assert_presence_of user, repo, label_id
57
+ assert_presence_of user, repo, label_name
40
58
  normalize! params
41
59
 
42
- get_request("/repos/#{user}/#{repo}/labels/#{label_id}", params)
60
+ get_request("/repos/#{user}/#{repo}/labels/#{label_name}", params)
43
61
  end
44
62
  alias :find :get
45
63
 
@@ -72,18 +90,18 @@ module Github
72
90
  #
73
91
  # = Examples
74
92
  # @github = Github.new
75
- # @github.issues.labels.update 'user-name', 'repo-name', 'label-id',
93
+ # @github.issues.labels.update 'user-name', 'repo-name', 'label-name',
76
94
  # :name => 'API', :color => "FFFFFF"
77
95
  #
78
- def update(user_name, repo_name, label_id, params={})
96
+ def update(user_name, repo_name, label_name, params={})
79
97
  set :user => user_name, :repo => repo_name
80
- assert_presence_of user, repo, label_id
98
+ assert_presence_of user, repo, label_name
81
99
 
82
100
  normalize! params
83
101
  filter! VALID_LABEL_INPUTS, params
84
102
  assert_required_keys(VALID_LABEL_INPUTS, params)
85
103
 
86
- patch_request("/repos/#{user}/#{repo}/labels/#{label_id}", params)
104
+ patch_request("/repos/#{user}/#{repo}/labels/#{label_name}", params)
87
105
  end
88
106
  alias :edit :update
89
107
 
@@ -91,30 +109,16 @@ module Github
91
109
  #
92
110
  # = Examples
93
111
  # github = Github.new
94
- # github.issues.labels.delete 'user-name', 'repo-name', 'label-id'
112
+ # github.issues.labels.delete 'user-name', 'repo-name', 'label-name'
95
113
  #
96
- def delete(user_name, repo_name, label_id, params={})
114
+ def delete(user_name, repo_name, label_name, params={})
97
115
  set :user => user_name, :repo => repo_name
98
116
  assert_presence_of user, repo
99
117
 
100
- assert_presence_of label_id
118
+ assert_presence_of label_name
101
119
  normalize! params
102
120
 
103
- delete_request("/repos/#{user}/#{repo}/labels/#{label_id}", params)
104
- end
105
-
106
- # List labels on an issue
107
- #
108
- # = Examples
109
- # @github = Github.new
110
- # @github.issues.labels.issue 'user-name', 'repo-name', 'issue-id'
111
- #
112
- def issue(user_name, repo_name, issue_id, params={})
113
- set :user => user_name, :repo => repo_name
114
- assert_presence_of user, repo, issue_id
115
- normalize! params
116
-
117
- get_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
121
+ delete_request("/repos/#{user}/#{repo}/labels/#{label_name}", params)
118
122
  end
119
123
 
120
124
  # Add labels to an issue
@@ -146,19 +150,19 @@ module Github
146
150
  # github = Github.new
147
151
  # github.issues.labels.remove 'user-name', 'repo-name', 'issue-id'
148
152
  #
149
- def remove(user_name, repo_name, issue_id, label_id=nil, params={})
153
+ def remove(user_name, repo_name, issue_id, label_name=nil, params={})
150
154
  set :user => user_name, :repo => repo_name
151
155
  assert_presence_of user, repo, issue_id
152
156
  normalize! params
153
157
 
154
- if label_id
155
- delete_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels/#{label_id}", params)
158
+ if label_name
159
+ delete_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels/#{label_name}", params)
156
160
  else
157
161
  delete_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
158
162
  end
159
163
  end
160
164
 
161
- # Replace all labels for an issue
165
+ # Replace all labels for an issue
162
166
  #
163
167
  # Sending an empty array ([]) will remove all Labels from the Issue.
164
168
  #
@@ -177,21 +181,5 @@ module Github
177
181
  put_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
178
182
  end
179
183
 
180
- # Get labels for every issue in a milestone
181
- #
182
- # = Examples
183
- # github = Github.new
184
- # github.issues.labels. 'user-name', 'repo-name', 'milestone-id'
185
- #
186
- def milestone(user_name, repo_name, milestone_id, params={})
187
- set :user => user_name, :repo => repo_name
188
- assert_presence_of user, repo, milestone_id
189
- normalize! params
190
-
191
- response = get_request("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels", params)
192
- return response unless block_given?
193
- response.each { |el| yield el }
194
- end
195
-
196
184
  end # Issues::Labels
197
185
  end # Github
@@ -4,7 +4,7 @@ module Github
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 8
7
- PATCH = 3
7
+ PATCH = 4
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues::Labels, '#add' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/issues/#{issue_id}/labels" }
9
+
10
+ before {
11
+ stub_post(request_path).
12
+ 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
+ let(:issue_id) { 1 }
19
+ let(:labels) { "Label 1" }
20
+
21
+ context "labels added" do
22
+ let(:body) { fixture('issues/labels.json') }
23
+ let(:status) { 200 }
24
+
25
+ it "should fail to add labels if issue-id is missing" do
26
+ expect {
27
+ subject.add user, repo, nil, labels
28
+ }.to raise_error(ArgumentError)
29
+ end
30
+
31
+ it "should create resource successfully" do
32
+ subject.add user, repo, issue_id, labels
33
+ a_post(request_path).should have_been_made
34
+ end
35
+
36
+ it "should return the resource" do
37
+ labels = subject.add user, repo, issue_id, labels
38
+ labels.first.should be_a Hashie::Mash
39
+ end
40
+
41
+ it "should get the label information" do
42
+ labels = subject.add user, repo, issue_id, labels
43
+ labels.first.name.should == 'bug'
44
+ end
45
+ end
46
+
47
+ it_should_behave_like 'request failure' do
48
+ let(:requestable) { subject.add user, repo, issue_id, labels }
49
+ end
50
+ end # add
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues::Labels, '#create' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/labels" }
9
+ let(:inputs) {
10
+ {
11
+ "name" => "API",
12
+ "color" => "FFFFFF",
13
+ }
14
+ }
15
+
16
+ before {
17
+ stub_post(request_path).with(inputs).
18
+ to_return(:body => body, :status => status,
19
+ :headers => {:content_type => "application/json; charset=utf-8"})
20
+ }
21
+
22
+ after { reset_authentication_for(subject) }
23
+
24
+ context "resouce created" do
25
+ let(:body) { fixture('issues/label.json') }
26
+ let(:status) { 200 }
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 fail to create resource if 'color' input is missing" do
35
+ expect {
36
+ subject.create user, repo, inputs.except('color')
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
+ label = subject.create user, repo, inputs
47
+ label.should be_a Hashie::Mash
48
+ end
49
+
50
+ it "should get the label information" do
51
+ label = subject.create user, repo, inputs
52
+ label.name.should == 'bug'
53
+ end
54
+ end
55
+
56
+ it_should_behave_like 'request failure' do
57
+ let(:requestable) { subject.create user, repo, inputs }
58
+ end
59
+ end # create
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues::Labels, '#delete' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:label_id) { 1 }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/labels/#{label_id}" }
10
+ let(:inputs) {
11
+ {
12
+ "name" => "API",
13
+ "color" => "FFFFFF",
14
+ }
15
+ }
16
+
17
+ before {
18
+ stub_delete(request_path).with(inputs).
19
+ to_return(:body => body, :status => status,
20
+ :headers => {:content_type => "application/json; charset=utf-8"})
21
+ }
22
+
23
+ after { reset_authentication_for(subject) }
24
+
25
+ context "resouce removed" do
26
+ let(:body) { fixture('issues/label.json') }
27
+ let(:status) { 204 }
28
+
29
+ it "should remove resource successfully" do
30
+ subject.delete user, repo, label_id
31
+ a_delete(request_path).should have_been_made
32
+ end
33
+ end
34
+
35
+ it_should_behave_like 'request failure' do
36
+ let(:requestable) { subject.delete user, repo, label_id }
37
+ end
38
+
39
+ end # delete
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues::Labels, '#get' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:label_id) { 1 }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/labels/#{label_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('issues/label.json') }
20
+ let(:status) { 200 }
21
+
22
+ it { should respond_to :get }
23
+
24
+ it "should fail to get resource without label 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, label_id
30
+ a_get(request_path).should have_been_made
31
+ end
32
+
33
+ it "should get label information" do
34
+ label = subject.get user, repo, label_id
35
+ label.name.should == 'bug'
36
+ end
37
+
38
+ it "should return mash" do
39
+ label = subject.get user, repo, label_id
40
+ label.should be_a Hashie::Mash
41
+ end
42
+ end
43
+
44
+ it_should_behave_like 'request failure' do
45
+ let(:requestable) { subject.get user, repo, label_id }
46
+ end
47
+ end # find
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues::Labels, '#list' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/labels" }
9
+ let(:body) { fixture('issues/labels.json') }
10
+ let(:status) { 200 }
11
+
12
+ before {
13
+ stub_get(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
+ context "for this repository" do
20
+ it { should respond_to :all }
21
+
22
+ it "should fail to get resource without username" do
23
+ expect { subject.list nil, repo }.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_behave_like 'an array of resources' do
32
+ let(:requestable) { subject.list user, repo }
33
+ end
34
+
35
+ it "should get issue information" do
36
+ labels = subject.list user, repo
37
+ labels.first.name.should == 'bug'
38
+ end
39
+
40
+ it "should yield to a block" do
41
+ yielded = []
42
+ result = subject.list(user, repo) { |obj| yielded << obj }
43
+ yielded.should == result
44
+ end
45
+ end
46
+
47
+ context "for this milestone" do
48
+ let(:milestone_id) { 1 }
49
+ let(:request_path) { "/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels"}
50
+ let(:body) { fixture('issues/labels.json') }
51
+ let(:status) { 200 }
52
+
53
+ it "should get the resources" do
54
+ subject.list user, repo, :milestone_id => milestone_id
55
+ a_get(request_path).should have_been_made
56
+ end
57
+
58
+ it_should_behave_like 'an array of resources' do
59
+ let(:requestable) { subject.list user, repo, :milestone_id => milestone_id }
60
+ end
61
+
62
+ it "should get issue information" do
63
+ labels = subject.list user, repo, :milestone_id => milestone_id
64
+ labels.first.name.should == 'bug'
65
+ end
66
+
67
+ it "should yield to a block" do
68
+ yielded = []
69
+ result = subject.list(user, repo, :milestone_id => milestone_id) { |obj| yielded << obj }
70
+ yielded.should == result
71
+ end
72
+ end
73
+
74
+ context "resource found" do
75
+ let(:issue_id) { 1 }
76
+ let(:request_path) { "/repos/#{user}/#{repo}/issues/#{issue_id}/labels" }
77
+ let(:body) { fixture('issues/labels.json') }
78
+ let(:status) { 200 }
79
+
80
+ it "should get the resources" do
81
+ subject.list user, repo, :issue_id => issue_id
82
+ a_get(request_path).should have_been_made
83
+ end
84
+
85
+ it "should get issue information" do
86
+ labels = subject.list user, repo, :issue_id => issue_id
87
+ labels.first.name.should == 'bug'
88
+ end
89
+
90
+ it "should yield to a block" do
91
+ yielded = []
92
+ result = subject.list(user, repo, :issue_id => issue_id) { |obj| yielded << obj }
93
+ yielded.should == result
94
+ end
95
+ end
96
+
97
+ it_should_behave_like 'request failure' do
98
+ let(:requestable) { subject.list user, repo }
99
+ end
100
+ end # list