github_api 0.8.6 → 0.8.7
Sign up to get free protection for your applications and to get access to all the features.
- data/features/pull_requests.feature +2 -2
- data/lib/github_api/activity/events.rb +18 -18
- data/lib/github_api/authorization.rb +2 -1
- data/lib/github_api/connection.rb +0 -1
- data/lib/github_api/pull_requests.rb +29 -38
- data/lib/github_api/repos/commits.rb +9 -1
- data/lib/github_api/version.rb +1 -1
- data/spec/github/pull_requests/comments/list_spec.rb +74 -0
- data/spec/github/pull_requests/comments_spec.rb +0 -96
- data/spec/github/pull_requests/commits_spec.rb +51 -0
- data/spec/github/pull_requests/create_spec.rb +52 -0
- data/spec/github/pull_requests/files_spec.rb +47 -0
- data/spec/github/pull_requests/get_spec.rb +49 -0
- data/spec/github/pull_requests/list_spec.rb +54 -0
- data/spec/github/pull_requests/merge_spec.rb +42 -0
- data/spec/github/pull_requests/merged_spec.rb +37 -0
- data/spec/github/pull_requests/pull_requests_spec.rb +13 -0
- data/spec/github/pull_requests/update_spec.rb +51 -0
- metadata +42 -33
- data/spec/github/pull_requests_spec.rb +0 -402
@@ -19,8 +19,8 @@ Feature: Pull Requests API
|
|
19
19
|
Scenario: Get
|
20
20
|
|
21
21
|
Given I want to get resource with the following params:
|
22
|
-
| user | repo |
|
23
|
-
| peter-murach | github | 36
|
22
|
+
| user | repo | number |
|
23
|
+
| peter-murach | github | 36 |
|
24
24
|
When I make request within a cassette named "pull_requests/get"
|
25
25
|
Then the response status should be 200
|
26
26
|
And the response type should be JSON
|
@@ -30,8 +30,8 @@ module Github
|
|
30
30
|
#
|
31
31
|
# = Examples
|
32
32
|
# github = Github.new
|
33
|
-
# github.events.repository 'user-name', 'repo-name'
|
34
|
-
# github.events.repository 'user-name', 'repo-name' { |event| ... }
|
33
|
+
# github.activity.events.repository 'user-name', 'repo-name'
|
34
|
+
# github.activity.events.repository 'user-name', 'repo-name' { |event| ... }
|
35
35
|
#
|
36
36
|
def repository(user_name, repo_name, params={})
|
37
37
|
set :user => user_name, :repo => repo_name
|
@@ -51,8 +51,8 @@ module Github
|
|
51
51
|
#
|
52
52
|
# = Examples
|
53
53
|
# github = Github.new
|
54
|
-
# github.events.issue 'user-name', 'repo-name'
|
55
|
-
# github.events.issue 'user-name', 'repo-name' { |event| ... }
|
54
|
+
# github.activity.events.issue 'user-name', 'repo-name'
|
55
|
+
# github.activity.events.issue 'user-name', 'repo-name' { |event| ... }
|
56
56
|
#
|
57
57
|
def issue(user_name, repo_name, params={})
|
58
58
|
set :user => user_name, :repo => repo_name
|
@@ -71,8 +71,8 @@ module Github
|
|
71
71
|
#
|
72
72
|
# = Examples
|
73
73
|
# github = Github.new
|
74
|
-
# github.events.network 'user-name', 'repo-name'
|
75
|
-
# github.events.network 'user-name', 'repo-name' { |event| ... }
|
74
|
+
# github.activity.events.network 'user-name', 'repo-name'
|
75
|
+
# github.activity.events.network 'user-name', 'repo-name' { |event| ... }
|
76
76
|
#
|
77
77
|
def network(user_name, repo_name, params={})
|
78
78
|
set :user => user_name, :repo => repo_name
|
@@ -92,8 +92,8 @@ module Github
|
|
92
92
|
#
|
93
93
|
# = Examples
|
94
94
|
# github = Github.new
|
95
|
-
# github.events.org 'org-name'
|
96
|
-
# github.events.org 'org-name' { |event| ... }
|
95
|
+
# github.activity.events.org 'org-name'
|
96
|
+
# github.activity.events.org 'org-name' { |event| ... }
|
97
97
|
#
|
98
98
|
def org(org_name, params={})
|
99
99
|
assert_presence_of org_name
|
@@ -116,15 +116,15 @@ module Github
|
|
116
116
|
#
|
117
117
|
# = Examples
|
118
118
|
# github = Github.new
|
119
|
-
# github.events.received 'user-name'
|
120
|
-
# github.events.received 'user-name' { |event| ... }
|
119
|
+
# github.activity.events.received 'user-name'
|
120
|
+
# github.activity.events.received 'user-name' { |event| ... }
|
121
121
|
#
|
122
122
|
# List all public events that a user has received
|
123
123
|
#
|
124
124
|
# = Examples
|
125
125
|
# github = Github.new
|
126
|
-
# github.events.received 'user-name', :public => true
|
127
|
-
# github.events.received 'user-name', :public => true { |event| ... }
|
126
|
+
# github.activity.events.received 'user-name', :public => true
|
127
|
+
# github.activity.events.received 'user-name', :public => true { |event| ... }
|
128
128
|
#
|
129
129
|
def received(user_name, params={})
|
130
130
|
assert_presence_of user_name
|
@@ -149,15 +149,15 @@ module Github
|
|
149
149
|
#
|
150
150
|
# = Examples
|
151
151
|
# github = Github.new
|
152
|
-
# github.events.performed 'user-name'
|
153
|
-
# github.events.performed 'user-name' { |event| ... }
|
152
|
+
# github.activity.events.performed 'user-name'
|
153
|
+
# github.activity.events.performed 'user-name' { |event| ... }
|
154
154
|
#
|
155
155
|
# List all public events that a user has performed
|
156
156
|
#
|
157
157
|
# = Examples
|
158
158
|
# github = Github.new
|
159
|
-
# github.events.performed 'user-name', :public => true
|
160
|
-
# github.events.performed 'user-name', :public => true { |event| ... }
|
159
|
+
# github.activity.events.performed 'user-name', :public => true
|
160
|
+
# github.activity.events.performed 'user-name', :public => true { |event| ... }
|
161
161
|
#
|
162
162
|
def performed(user_name, params={})
|
163
163
|
assert_presence_of user_name
|
@@ -182,8 +182,8 @@ module Github
|
|
182
182
|
#
|
183
183
|
# = Examples
|
184
184
|
# github = Github.new
|
185
|
-
# github.events.user_org 'user-name', 'org-name'
|
186
|
-
# github.events.user_org 'user-name', 'org-name' { |event| ... }
|
185
|
+
# github.activity.events.user_org 'user-name', 'org-name'
|
186
|
+
# github.activity.events.user_org 'user-name', 'org-name' { |event| ... }
|
187
187
|
#
|
188
188
|
def user_org(user_name, org_name, params={})
|
189
189
|
assert_presence_of user_name, org_name
|
@@ -62,18 +62,17 @@ module Github
|
|
62
62
|
#
|
63
63
|
# = Examples
|
64
64
|
# github = Github.new
|
65
|
-
# github.pull_requests.get 'user-name', 'repo-name', '
|
65
|
+
# github.pull_requests.get 'user-name', 'repo-name', 'number'
|
66
66
|
#
|
67
|
-
#
|
68
|
-
#
|
67
|
+
# pull_reqs = Github::PullRequests.new
|
68
|
+
# pull_reqs.get 'user-name', 'repo-name', 'number'
|
69
69
|
#
|
70
|
-
def get(user_name, repo_name,
|
70
|
+
def get(user_name, repo_name, number, params={})
|
71
71
|
set :user => user_name, :repo => repo_name
|
72
|
-
assert_presence_of user, repo,
|
72
|
+
assert_presence_of user, repo, number
|
73
73
|
normalize! params
|
74
|
-
# _merge_mime_type(:pull_request, params)
|
75
74
|
|
76
|
-
get_request("/repos/#{user}/#{repo}/pulls/#{
|
75
|
+
get_request("/repos/#{user}/#{repo}/pulls/#{number}", params)
|
77
76
|
end
|
78
77
|
alias :find :get
|
79
78
|
|
@@ -101,7 +100,7 @@ module Github
|
|
101
100
|
#
|
102
101
|
# alternatively
|
103
102
|
#
|
104
|
-
#
|
103
|
+
# github.pull_requests.create 'user-name', 'repo-name',
|
105
104
|
# "issue" => "5",
|
106
105
|
# "head" => "octocat:new-feature",
|
107
106
|
# "base" => "master"
|
@@ -111,7 +110,6 @@ module Github
|
|
111
110
|
assert_presence_of user, repo
|
112
111
|
|
113
112
|
normalize! params
|
114
|
-
# _merge_mime_type(:pull_request, params)
|
115
113
|
filter! VALID_REQUEST_PARAM_NAMES, params
|
116
114
|
|
117
115
|
post_request("/repos/#{user}/#{repo}/pulls", params)
|
@@ -126,37 +124,33 @@ module Github
|
|
126
124
|
#
|
127
125
|
# = Examples
|
128
126
|
# github = Github.new :oauth_token => '...'
|
129
|
-
# github.pull_requests.update 'user-name', 'repo-name', '
|
127
|
+
# github.pull_requests.update 'user-name', 'repo-name', 'number'
|
130
128
|
# "title" => "Amazing new title",
|
131
129
|
# "body" => "Update body",
|
132
130
|
# "state" => "open",
|
133
131
|
#
|
134
|
-
def update(user_name, repo_name,
|
132
|
+
def update(user_name, repo_name, number, params={})
|
135
133
|
set :user => user_name, :repo => repo_name
|
136
|
-
assert_presence_of user, repo,
|
137
|
-
|
134
|
+
assert_presence_of user, repo, number
|
138
135
|
normalize! params
|
139
136
|
filter! VALID_REQUEST_PARAM_NAMES, params
|
140
|
-
# _merge_mime_type(:pull_request, params)
|
141
137
|
assert_valid_values(VALID_REQUEST_PARAM_VALUES, params)
|
142
138
|
|
143
|
-
patch_request("/repos/#{user}/#{repo}/pulls/#{
|
139
|
+
patch_request("/repos/#{user}/#{repo}/pulls/#{number}", params)
|
144
140
|
end
|
145
141
|
|
146
142
|
# List commits on a pull request
|
147
143
|
#
|
148
144
|
# = Examples
|
149
145
|
# github = Github.new
|
150
|
-
# github.pull_requests.commits 'user-name', 'repo-name', '
|
146
|
+
# github.pull_requests.commits 'user-name', 'repo-name', 'number'
|
151
147
|
#
|
152
|
-
def commits(user_name, repo_name,
|
148
|
+
def commits(user_name, repo_name, number, params={})
|
153
149
|
set :user => user_name, :repo => repo_name
|
154
|
-
assert_presence_of user, repo,
|
155
|
-
|
150
|
+
assert_presence_of user, repo, number
|
156
151
|
normalize! params
|
157
|
-
# _merge_mime_type(:pull_request, params)
|
158
152
|
|
159
|
-
response = get_request("/repos/#{user}/#{repo}/pulls/#{
|
153
|
+
response = get_request("/repos/#{user}/#{repo}/pulls/#{number}/commits", params)
|
160
154
|
return response unless block_given?
|
161
155
|
response.each { |el| yield el }
|
162
156
|
end
|
@@ -165,15 +159,14 @@ module Github
|
|
165
159
|
#
|
166
160
|
# = Examples
|
167
161
|
# github = Github.new
|
168
|
-
# github.pull_requests.files 'user-name', 'repo-name', '
|
162
|
+
# github.pull_requests.files 'user-name', 'repo-name', 'number'
|
169
163
|
#
|
170
|
-
def files(user_name, repo_name,
|
164
|
+
def files(user_name, repo_name, number, params={})
|
171
165
|
set :user => user_name, :repo => repo_name
|
172
|
-
assert_presence_of user, repo,
|
166
|
+
assert_presence_of user, repo, number
|
173
167
|
normalize! params
|
174
|
-
# _merge_mime_type(:pull_request, params)
|
175
168
|
|
176
|
-
response = get_request("/repos/#{user}/#{repo}/pulls/#{
|
169
|
+
response = get_request("/repos/#{user}/#{repo}/pulls/#{number}/files", params)
|
177
170
|
return response unless block_given?
|
178
171
|
response.each { |el| yield el }
|
179
172
|
end
|
@@ -182,16 +175,14 @@ module Github
|
|
182
175
|
#
|
183
176
|
# = Examples
|
184
177
|
# github = Github.new
|
185
|
-
# github.pull_requests.merged? 'user-name', 'repo-name', '
|
178
|
+
# github.pull_requests.merged? 'user-name', 'repo-name', 'number'
|
186
179
|
#
|
187
|
-
def merged?(user_name, repo_name,
|
180
|
+
def merged?(user_name, repo_name, number, params={})
|
188
181
|
set :user => user_name, :repo => repo_name
|
189
|
-
assert_presence_of user, repo,
|
190
|
-
|
182
|
+
assert_presence_of user, repo, number
|
191
183
|
normalize! params
|
192
|
-
# _merge_mime_type(:pull_request, params)
|
193
184
|
|
194
|
-
get_request("/repos/#{user}/#{repo}/pulls/#{
|
185
|
+
get_request("/repos/#{user}/#{repo}/pulls/#{number}/merge", params)
|
195
186
|
true
|
196
187
|
rescue Github::Error::NotFound
|
197
188
|
false
|
@@ -200,21 +191,21 @@ module Github
|
|
200
191
|
# Merge a pull request(Merge Button)
|
201
192
|
#
|
202
193
|
# = Inputs
|
203
|
-
# <tt>:commit_message</tt> - Optional string -
|
194
|
+
# <tt>:commit_message</tt> - Optional string -
|
195
|
+
# The message that will be used for the merge commit
|
204
196
|
#
|
205
197
|
# = Examples
|
206
198
|
# github = Github.new
|
207
|
-
# github.pull_requests.merge 'user-name', 'repo-name', '
|
199
|
+
# github.pull_requests.merge 'user-name', 'repo-name', 'number'
|
208
200
|
#
|
209
|
-
def merge(user_name, repo_name,
|
201
|
+
def merge(user_name, repo_name, number, params={})
|
210
202
|
set :user => user_name, :repo => repo_name
|
211
|
-
assert_presence_of user, repo,
|
203
|
+
assert_presence_of user, repo, number
|
212
204
|
|
213
205
|
normalize! params
|
214
|
-
# _merge_mime_type(:pull_request, params)
|
215
206
|
filter! VALID_REQUEST_PARAM_NAMES, params
|
216
207
|
|
217
|
-
put_request("/repos/#{user}/#{repo}/pulls/#{
|
208
|
+
put_request("/repos/#{user}/#{repo}/pulls/#{number}/merge", params)
|
218
209
|
end
|
219
210
|
|
220
211
|
end # PullRequests
|
@@ -3,6 +3,14 @@
|
|
3
3
|
module Github
|
4
4
|
class Repos::Commits < API
|
5
5
|
|
6
|
+
VALID_COMMITS_OPTIONS = %w[
|
7
|
+
sha
|
8
|
+
path
|
9
|
+
author
|
10
|
+
since
|
11
|
+
until
|
12
|
+
].freeze
|
13
|
+
|
6
14
|
# List commits on a repository
|
7
15
|
#
|
8
16
|
# = Parameters
|
@@ -19,7 +27,7 @@ module Github
|
|
19
27
|
set :user => user_name, :repo => repo_name
|
20
28
|
assert_presence_of user, repo
|
21
29
|
normalize! params
|
22
|
-
filter!
|
30
|
+
filter! VALID_COMMITS_OPTIONS, params
|
23
31
|
|
24
32
|
response = get_request("/repos/#{user}/#{repo}/commits", params)
|
25
33
|
return response unless block_given?
|
data/lib/github_api/version.rb
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::PullRequests::Comments, '#list' do
|
6
|
+
let(:repo) { 'github' }
|
7
|
+
let(:user) { 'peter-murach' }
|
8
|
+
let(:number) { 1 }
|
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 'on a pull request' do
|
18
|
+
let(:request_path) { "/repos/#{user}/#{repo}/pulls/#{number}/comments" }
|
19
|
+
let(:body) { fixture('pull_requests/comments.json') }
|
20
|
+
let(:status) { 200 }
|
21
|
+
|
22
|
+
it { should respond_to :all }
|
23
|
+
|
24
|
+
it "throws error if comment id not provided" do
|
25
|
+
expect { subject.list user, nil }.to raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should get the resources" do
|
29
|
+
subject.list user, repo, :request_id => number
|
30
|
+
a_get(request_path).should have_been_made
|
31
|
+
end
|
32
|
+
|
33
|
+
it_should_behave_like 'an array of resources' do
|
34
|
+
let(:requestable) { subject.list user, repo, :request_id => number }
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should get pull request comment information" do
|
38
|
+
comments = subject.list user, repo, :request_id => number
|
39
|
+
comments.first.id.should == number
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should yield to a block" do
|
43
|
+
yielded = []
|
44
|
+
result = subject.list(user, repo, :request_id => number) {|obj| yielded << obj }
|
45
|
+
yielded.should == result
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'in a repository' do
|
50
|
+
let(:request_path) { "/repos/#{user}/#{repo}/pulls/comments" }
|
51
|
+
let(:body) { fixture('pull_requests/comments.json') }
|
52
|
+
let(:status) { 200 }
|
53
|
+
|
54
|
+
it "should get the resources" do
|
55
|
+
subject.list user, repo
|
56
|
+
a_get(request_path).should have_been_made
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should get pull request comment information" do
|
60
|
+
comments = subject.list user, repo
|
61
|
+
comments.first.id.should == number
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should yield to a block" do
|
65
|
+
yielded = []
|
66
|
+
result = subject.list(user, repo) { |obj| yielded << obj }
|
67
|
+
yielded.should == result
|
68
|
+
end
|
69
|
+
|
70
|
+
it_should_behave_like 'request failure' do
|
71
|
+
let(:requestable) { subject.list user, repo }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end # list
|
@@ -11,102 +11,6 @@ describe Github::PullRequests::Comments do
|
|
11
11
|
|
12
12
|
after { reset_authentication_for github }
|
13
13
|
|
14
|
-
describe "#list" do
|
15
|
-
it { github.pull_requests.comments.should respond_to :all }
|
16
|
-
|
17
|
-
context 'on a pull request' do
|
18
|
-
before do
|
19
|
-
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/comments").
|
20
|
-
to_return(:body => fixture('pull_requests/comments.json'),
|
21
|
-
:status => 200,
|
22
|
-
:headers => {:content_type => "application/json; charset=utf-8"})
|
23
|
-
end
|
24
|
-
|
25
|
-
it "throws error if comment id not provided" do
|
26
|
-
expect {
|
27
|
-
github.pull_requests.comments.list user, nil
|
28
|
-
}.to raise_error(ArgumentError)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should get the resources" do
|
32
|
-
github.pull_requests.comments.list user, repo, :request_id => pull_request_id
|
33
|
-
a_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/comments").
|
34
|
-
should have_been_made
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should return array of resources" do
|
38
|
-
comments = github.pull_requests.comments.list user, repo, :request_id => pull_request_id
|
39
|
-
comments.should be_an Array
|
40
|
-
comments.should have(1).items
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should be a mash type" do
|
44
|
-
comments = github.pull_requests.comments.list user, repo, :request_id => pull_request_id
|
45
|
-
comments.first.should be_a Hashie::Mash
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should get pull request comment information" do
|
49
|
-
comments = github.pull_requests.comments.list user, repo, :request_id => pull_request_id
|
50
|
-
comments.first.id.should == pull_request_id
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should yield to a block" do
|
54
|
-
yielded = []
|
55
|
-
result = github.pull_requests.comments.list(user, repo, :request_id => pull_request_id) { |obj| yielded << obj }
|
56
|
-
yielded.should == result
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'in a repository' do
|
61
|
-
before do
|
62
|
-
stub_get("/repos/#{user}/#{repo}/pulls/comments").
|
63
|
-
to_return(:body => fixture('pull_requests/comments.json'),
|
64
|
-
:status => 200,
|
65
|
-
:headers => {:content_type => "application/json; charset=utf-8"})
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should get the resources" do
|
69
|
-
github.pull_requests.comments.list user, repo
|
70
|
-
a_get("/repos/#{user}/#{repo}/pulls/comments").should have_been_made
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should return array of resources" do
|
74
|
-
comments = github.pull_requests.comments.list user, repo
|
75
|
-
comments.should be_an Array
|
76
|
-
comments.should have(1).items
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should be a mash type" do
|
80
|
-
comments = github.pull_requests.comments.list user, repo
|
81
|
-
comments.first.should be_a Hashie::Mash
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should get pull request comment information" do
|
85
|
-
comments = github.pull_requests.comments.list user, repo
|
86
|
-
comments.first.id.should == pull_request_id
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should yield to a block" do
|
90
|
-
yielded = []
|
91
|
-
result = github.pull_requests.comments.list(user, repo) { |obj| yielded << obj }
|
92
|
-
yielded.should == result
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'resource not found' do
|
97
|
-
before do
|
98
|
-
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/comments").
|
99
|
-
to_return(:body => "", :status => [404, "Not Found"])
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should return 404 with a message 'Not Found'" do
|
103
|
-
expect {
|
104
|
-
github.pull_requests.comments.list user, repo, :request_id => pull_request_id
|
105
|
-
}.to raise_error(Github::Error::NotFound)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end # list
|
109
|
-
|
110
14
|
describe "#get" do
|
111
15
|
it { github.pull_requests.comments.should respond_to :find }
|
112
16
|
|