github_api_v3 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +159 -50
- data/lib/github_api_v3/client.rb +11 -5
- data/lib/github_api_v3/client/commits.rb +50 -0
- data/lib/github_api_v3/client/contents.rb +146 -0
- data/lib/github_api_v3/client/octocat.rb +19 -0
- data/lib/github_api_v3/version.rb +1 -1
- data/spec/cassettes/GitHub_Client_Commits/_commit/returns_a_commit_as_a_hash.json +1 -0
- data/spec/cassettes/GitHub_Client_Commits/_commits/returns_an_array_of_commits.json +1 -0
- data/spec/cassettes/GitHub_Client_Commits/_compare_commits/returns_a_hash_of_commit_comparison.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_archive/returns_a_string.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_archive/returns_the_correct_string.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_contents/returns_a_404_if_not_found.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_contents/returns_a_hash_for_a_file.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_contents/returns_an_array_for_a_dir.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_contents/returns_the_correct_file_hash.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_create_file/returns_file_info_as_a_hash.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_create_file/returns_the_correct_hash.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_delete_file/deletes_the_file.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_delete_file/returns_a_hash.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_readme/returns_a_readme_hash.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_readme/returns_the_correct_file.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_update_file/returns_file_info_as_a_hash.json +1 -0
- data/spec/cassettes/GitHub_Client_Contents/_update_file/returns_the_correct_hash.json +1 -0
- data/spec/github_api_v3/client/commits_spec.rb +29 -0
- data/spec/github_api_v3/client/contents_spec.rb +111 -0
- metadata +43 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52db0fbe65deb898b9ac054ebb423840cdd288d3
|
4
|
+
data.tar.gz: 5a5d2fb6afbe5d9565d0ebd0863b5caf1fdbce9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93665dbd5f45db99b4ea638e29e9ccb14d16eccf2e805bef95273d3734e9ff8c2aa65b75b0888a499796f5aa021948b19aef93e1ef641fdf4ed18b2efcb982a3
|
7
|
+
data.tar.gz: 96285f9ae94f5d61255a348807605dd90d97a4fc5e286e96be9157e1f81ffe36940a75e179622a1b719e1fab1407314a4e0d58799d80457469d2c024b042c364
|
data/README.md
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/github_api_v3.png)](http://badge.fury.io/rb/github_api_v3)
|
4
4
|
|
5
|
-
This is a simple wrapper for GitHub's v3 API. Knowing a little about [GitHub's API](http://developer.github.com/) will aid in its use, but is not necessary.
|
5
|
+
This is a simple and easy to use wrapper for GitHub's v3 API. Knowing a little about [GitHub's API](http://developer.github.com/) will aid in its use, but is not necessary. Nearly all methods of the API have been implemented, but there are a few left to go.
|
6
6
|
|
7
7
|
## Documentation
|
8
8
|
|
9
|
-
Full documentation for the gem can be found at [rdoc.info/gems/github_api_v3/frames](http://rdoc.info/
|
9
|
+
Full documentation for the gem can be found at [rdoc.info/gems/github_api_v3/frames](http://rdoc.info/gems/github_api_v3/frames). I strongly recommend checking it out, as the library is very well documented.
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
@@ -26,7 +26,6 @@ require 'github_api_v3'
|
|
26
26
|
|
27
27
|
There are multiple different unauthenticated requests to the API. These are performed when no credentials are given, and are shown below starting with `GitHub`. Unauthenticated methods can certainly be called from an authenticated client, and this is recommended as to not reach the hourly [rate limit](http://developer.github.com/v3/#rate-limiting).
|
28
28
|
|
29
|
-
|
30
29
|
### Authenticated Requests
|
31
30
|
|
32
31
|
Some methods, such as retrieving private repos or emails, require authentication. To create one of these requests, you'll need to pass in your login and access token. You can create a personal access token on your [account page](https://github.com/settings/applications).
|
@@ -49,54 +48,57 @@ Anytime a method is shown below starting with `client`, it is an authenticated m
|
|
49
48
|
|
50
49
|
### Sample usage
|
51
50
|
|
51
|
+
The following sections are some sample usages of the library for parts of the API that I consider to be very useful. The methods in this section are not comprehensive, but aim to give a nice overview of some usage of this library.
|
52
|
+
|
52
53
|
#### Users
|
53
54
|
|
54
55
|
The following are some sample usages of the Users module.
|
55
56
|
|
56
57
|
```ruby
|
57
|
-
# Retrieve a single user
|
58
|
+
# Retrieve a single user's information.
|
58
59
|
user = GitHub.user('caseyscarborough')
|
59
60
|
user.login # => "caseyscarborough"
|
60
61
|
user.name # => "Casey Scarborough"
|
61
62
|
user.html_url # => "https://github.com/caseyscarborough"
|
62
63
|
user.following # => 23
|
63
64
|
|
64
|
-
# Retrieve an array of all GitHub users
|
65
|
+
# Retrieve an array of all GitHub users.
|
65
66
|
GitHub.users
|
66
67
|
|
67
|
-
#
|
68
|
+
# Retrieve all emails for an authenticated user.
|
68
69
|
client.emails
|
69
70
|
|
70
|
-
# Follow/unfollow a user
|
71
|
+
# Follow/unfollow a user.
|
71
72
|
client.follow('caseyscarborough')
|
72
73
|
client.unfollow('caseyscarborough')
|
73
74
|
|
74
|
-
# Check if a user follows another user
|
75
|
+
# Check if a user follows another user.
|
75
76
|
GitHub.follows?('caseyscarborough','matz')
|
76
77
|
|
77
|
-
# Get a list of an unauthenticated user's followers
|
78
|
+
# Get a list of an unauthenticated user's followers.
|
78
79
|
GitHub.followers('caseyscarborough')
|
79
80
|
|
80
|
-
# Get a list of an authenticated user's followers
|
81
|
+
# Get a list of an authenticated user's followers.
|
81
82
|
client.followers
|
82
83
|
|
83
|
-
# Get a list of user's a user is following
|
84
|
+
# Get a list of user's a user is following.
|
84
85
|
GitHub.following('caseyscarborough')
|
85
86
|
|
86
|
-
#
|
87
|
+
# Check if authenticated user is following another user.
|
87
88
|
client.following?('caseyscarborough')
|
89
|
+
# => true
|
88
90
|
|
89
|
-
#
|
91
|
+
# Retrieve events for a user.
|
90
92
|
GitHub.events('caseyscarborough')
|
91
93
|
|
92
|
-
#
|
94
|
+
# Retrieve notifications for a user.
|
93
95
|
client.notifications
|
94
96
|
|
95
|
-
#
|
97
|
+
# Retrieve repositories watching/starring for a user.
|
96
98
|
client.watching
|
97
99
|
client.starring
|
98
100
|
|
99
|
-
#
|
101
|
+
# Retrieve a client's rate limit.
|
100
102
|
GitHub.rate_limit
|
101
103
|
client.rate_limit
|
102
104
|
|
@@ -109,37 +111,37 @@ You can find the available attributes [here](http://developer.github.com/v3/user
|
|
109
111
|
The following are some sample usages for the Repos module.
|
110
112
|
|
111
113
|
```ruby
|
112
|
-
#
|
114
|
+
# Retrieve repositories for an unauthenticated/authenticated user.
|
113
115
|
GitHub.repos('caseyscarborough')
|
114
116
|
client.repos
|
115
117
|
|
116
|
-
#
|
118
|
+
# Retrieve all public repositories on GitHub.
|
117
119
|
GitHub.all_repos
|
118
120
|
|
119
|
-
#
|
121
|
+
# Retrieve a specific repository.
|
120
122
|
GitHub.repo('owner','repo-name')
|
121
123
|
|
122
|
-
# Create a
|
124
|
+
# Create a new repository.
|
123
125
|
client.create_repo('new-repo', description: 'New repository.', private: true)
|
124
126
|
|
125
|
-
# Delete a
|
127
|
+
# Delete a repository.
|
126
128
|
client.delete_repo('repo-name')
|
127
129
|
|
128
|
-
#
|
130
|
+
# Retrieve a repository's contributors/languages/tags/branches/collaborators.
|
129
131
|
GitHub.contributors('caseyscarborough','github')
|
130
132
|
GitHub.languages('caseyscarborough','github')
|
131
133
|
GitHub.tags('caseyscarborough','github')
|
132
134
|
GitHub.branches('caseyscarborough','github')
|
133
135
|
GitHub.collaborators('caseyscarborough','github')
|
134
136
|
|
135
|
-
# Get a specific branch
|
137
|
+
# Get a specific branch from a repository (master shown below).
|
136
138
|
GitHub.branch('caseyscarborough','github','master')
|
137
139
|
|
138
|
-
# Add/remove collaborator
|
140
|
+
# Add/remove collaborator from a repository.
|
139
141
|
client.add_collaborator('owner','repo-name','user-to-add')
|
140
142
|
client.remove_collaborator('owner','repo-name','user-to-remove')
|
141
143
|
|
142
|
-
# Subscribe/unsubscribe/star/unstar a repository
|
144
|
+
# Subscribe/unsubscribe/star/unstar a repository.
|
143
145
|
client.subscribe('caseyscarborough','github')
|
144
146
|
client.unsubscribe('caseyscarborough','github')
|
145
147
|
client.star('caseyscarborough','github')
|
@@ -155,47 +157,54 @@ For a full list with descriptions, see the [Repos documentation](http://rdoc.inf
|
|
155
157
|
The following are some sample usages of the Events module.
|
156
158
|
|
157
159
|
```ruby
|
158
|
-
#
|
160
|
+
# Retrieve all events for a user.
|
159
161
|
GitHub.user_events('caseyscarborough')
|
160
162
|
|
161
|
-
#
|
163
|
+
# Retrieve all public events for a user.
|
162
164
|
GitHub.public_user_events('caseyscarborough')
|
163
165
|
|
164
|
-
#
|
166
|
+
# Retrieve all public GitHub events.
|
165
167
|
GitHub.public_events
|
166
168
|
|
167
|
-
#
|
169
|
+
# Retrieve all events for a repository.
|
168
170
|
GitHub.repo_events('owner','repo-name')
|
169
171
|
|
172
|
+
# Retrieve public events for an organization.
|
173
|
+
GitHub.organization_events('ruby')
|
174
|
+
|
170
175
|
# etc...
|
171
176
|
```
|
172
177
|
|
178
|
+
Check out the [Events documentation](http://rdoc.info/gems/github_api_v3/GitHub/Client/Events) for a comprehensive list of methods.
|
179
|
+
|
173
180
|
#### Gists
|
174
181
|
|
175
182
|
The following are sample uses for the Gists module.
|
176
183
|
|
177
184
|
```ruby
|
178
|
-
#
|
185
|
+
# Retrieve all gists for a user.
|
179
186
|
GitHub.gists('caseyscarborough')
|
180
187
|
|
181
|
-
#
|
188
|
+
# Retrieve all gists for the authenticated user.
|
182
189
|
client.gists
|
183
190
|
|
184
|
-
#
|
191
|
+
# Retrieve all public gists.
|
185
192
|
GitHub.gists
|
186
193
|
|
187
|
-
#
|
194
|
+
# Retrieve a gist by it's ID.
|
188
195
|
GitHub.gist(1234567)
|
189
196
|
|
190
|
-
# Create a gist
|
197
|
+
# Create a new gist.
|
191
198
|
client.create_gist(
|
199
|
+
# Hash of files to include.
|
192
200
|
:files => { "file1.txt" => { content: "File contents" } },
|
193
|
-
:description => "Gist description",
|
201
|
+
:description => "Gist description.",
|
194
202
|
:public => "false"
|
195
203
|
)
|
196
204
|
|
197
|
-
# Check if a gist is starred
|
205
|
+
# Check if a gist is starred.
|
198
206
|
client.gist_starred?(1234567)
|
207
|
+
# => true
|
199
208
|
|
200
209
|
# Star/unstar/fork/delete a gist
|
201
210
|
client.star_gist(1234567)
|
@@ -212,10 +221,10 @@ Check out the [Gist documentation](http://rdoc.info/gems/github_api_v3/GitHub/Cl
|
|
212
221
|
You can render any markdown test using the markdown method.
|
213
222
|
|
214
223
|
```ruby
|
215
|
-
# Render a string
|
224
|
+
# Render a string to markdown.
|
216
225
|
GitHub.markdown('# Markdown text!')
|
217
226
|
|
218
|
-
# Render a file
|
227
|
+
# Render a file's contents to markdown.
|
219
228
|
GitHub.markdown(File.read('markdown.md'))
|
220
229
|
```
|
221
230
|
|
@@ -224,41 +233,141 @@ GitHub.markdown(File.read('markdown.md'))
|
|
224
233
|
You can retrieve .gitignore templates using the Gitignore API as well.
|
225
234
|
|
226
235
|
```ruby
|
236
|
+
# Retrieve a list of all available .gitignore templates.
|
227
237
|
GitHub.gitignore_list
|
228
238
|
# => ["Actionscript", "Android", "C", "C++", "CSharp"...]
|
229
239
|
|
230
|
-
# Retrieve a specific template
|
240
|
+
# Retrieve a specific template.
|
231
241
|
GitHub.gitignore("Ruby")
|
232
242
|
# => {"name"=>"Ruby", "source"=>"*.gem\n*.rbc\n.bundle...}
|
233
243
|
```
|
234
244
|
|
235
|
-
|
245
|
+
#### Authorizations
|
236
246
|
|
237
|
-
|
247
|
+
The Authorizations OAuth API requires that a user use _basic authentication_. This means that you'll need to instantiate a client using your username and password, as opposed to the username and access token. You'll then be able to use the Authorizations API methods on that client. See below:
|
238
248
|
|
239
|
-
```
|
240
|
-
|
241
|
-
|
249
|
+
```ruby
|
250
|
+
client = GitHub.client(login: 'username', password: 'password')
|
251
|
+
|
252
|
+
# List your authorizations.
|
253
|
+
client.authorizations
|
254
|
+
|
255
|
+
# Retrieve a single authorization by its ID.
|
256
|
+
client.authorization(123)
|
257
|
+
|
258
|
+
# Create a new authorization.
|
259
|
+
client.create_authorization(
|
260
|
+
:note => 'New authorization',
|
261
|
+
# The authorized applications ID and secret
|
262
|
+
:client_id => 'ab0487b031b18f9286a6',
|
263
|
+
:client_secret => '9d667c2b7fae7a329f32b6df17926154'
|
264
|
+
)
|
265
|
+
|
266
|
+
# Update an existing authorization.
|
267
|
+
client.update_authorization(
|
268
|
+
123, # The authorization's ID.
|
269
|
+
:note => 'Updated authorization',
|
270
|
+
:note_url => 'http://anyrandomurl.com'
|
271
|
+
)
|
272
|
+
|
273
|
+
# Delete an authorization by it's ID.
|
274
|
+
client.delete_authorization(123)
|
242
275
|
```
|
243
276
|
|
244
|
-
|
277
|
+
For a full overview of the Authorizations API check out the [OAuth documentation](http://rdoc.info/gems/github_api_v3/GitHub/Client/OAuth).
|
245
278
|
|
246
|
-
|
279
|
+
#### Contents API
|
247
280
|
|
248
|
-
|
249
|
-
|
281
|
+
The Contents API methods are used to retrieve, create, update, and delete files in a repository. File contents that are retrieved are Base64 encoded. Some example methods are shown below:
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
# Get the contents of the README file.
|
285
|
+
GitHub.contents('caseyscarborough', 'github')
|
286
|
+
|
287
|
+
# Retrieve the contents of a file or directory.
|
288
|
+
GitHub.contents(
|
289
|
+
'caseyscarborough', # Repository owner.
|
290
|
+
'github', # Repository name.
|
291
|
+
'lib', # File/directory path. Defaults to the root of repository.
|
292
|
+
'master' # Reference or branch. Defaults to master.
|
293
|
+
)
|
294
|
+
|
295
|
+
# Create a new file.
|
296
|
+
client.create_file(
|
297
|
+
'caseyscarborough', # Repository owner.
|
298
|
+
'github', # Repository name.
|
299
|
+
:path => 'lib/new_file.txt', # Path to file.
|
300
|
+
:message => 'Add lib/new_file.txt.', # Commit message.
|
301
|
+
:content => 'This is a test file.', # File contents.
|
302
|
+
:committer => { :name => 'Casey Scarborough', :email => 'casey@example.com' }
|
303
|
+
)
|
304
|
+
|
305
|
+
# Update an existing file.
|
306
|
+
client.update_file(
|
307
|
+
'caseyscarborough', # Repository owner.
|
308
|
+
'github', # Repository name.
|
309
|
+
:path => 'lib/update_file.txt', # File path.
|
310
|
+
:message => 'Update lib/update_file.txt.', # Commit message.
|
311
|
+
:content => 'This is a test file.', # New file contents.
|
312
|
+
:sha => '329688480d39049927147c162b9d2deaf885005f', # SHA of file.
|
313
|
+
:committer => { :name => 'Casey Scarborough', :email => 'casey@example.com' }
|
314
|
+
)
|
315
|
+
|
316
|
+
# Delete an existing file.
|
317
|
+
client.delete_file(
|
318
|
+
'caseyscarborough', # Repository owner.
|
319
|
+
'github', # Repository name.
|
320
|
+
:path => 'lib/delete_me.txt', # File path.
|
321
|
+
:message => 'Delete lib/delete_me.txt.', # Commit message.
|
322
|
+
:sha => '329688480d39049927147c162b9d2deaf885005f', # SHA of file.
|
323
|
+
:committer => { :name => 'Casey Scarborough', :email => 'casey@example.com' }
|
324
|
+
)
|
250
325
|
```
|
251
326
|
|
327
|
+
As you can see, the Commits API methods are not as intuitive as the rest of the API, so the [documentation](http://rdoc.info/gems/github_api_v3/GitHub/Client/Contents) is very useful.
|
328
|
+
|
329
|
+
#### Conclusion
|
330
|
+
|
331
|
+
And if you've made it this far, you can check out the last method to get a little piece of random wisdom from GitHub.
|
332
|
+
|
333
|
+
```ruby
|
334
|
+
GitHub.octocat
|
335
|
+
# =>
|
336
|
+
"MMM. .MMM
|
337
|
+
MMMMMMMMMMMMMMMMMMM
|
338
|
+
MMMMMMMMMMMMMMMMMMM _____________________
|
339
|
+
MMMMMMMMMMMMMMMMMMMMM | |
|
340
|
+
MMMMMMMMMMMMMMMMMMMMMMM | Design for failure. |
|
341
|
+
MMMMMMMMMMMMMMMMMMMMMMMM |_ _________________|
|
342
|
+
MMMM::- -:::::::- -::MMMM |/
|
343
|
+
MM~:~ ~:::::~ ~:~MM
|
344
|
+
.. MMMMM::. .:::+:::. .::MMMMM ..
|
345
|
+
.MM::::: ._. :::::MM.
|
346
|
+
MMMM;:::::;MMMM
|
347
|
+
-MM MMMMMMM
|
348
|
+
^ M+ MMMMMMMMM
|
349
|
+
MMMMMMM MM MM MM
|
350
|
+
MM MM MM MM
|
351
|
+
MM MM MM MM
|
352
|
+
.~~MM~MM~MM~MM~~.
|
353
|
+
~~~~MM:~MM~~~MM~:MM~~~~
|
354
|
+
~~~~~~==~==~~~==~==~~~~~~
|
355
|
+
~~~~~~==~==~==~==~~~~~~
|
356
|
+
:~==~==~==~==~~"
|
357
|
+
|
358
|
+
# Or create your own wisdom.
|
359
|
+
GitHub.octocat('Wisdom.')
|
360
|
+
```
|
252
361
|
## To Do
|
253
362
|
|
254
363
|
Any functionality of the API listed at [developer.github.com](http://developer.github.com/) that hasn't currently been implemented.
|
255
364
|
|
256
365
|
Some main missing functionality:
|
257
366
|
* A good bit of the [Repos API](http://developer.github.com/v3/repos/), such as:
|
258
|
-
* Comments
|
259
|
-
* Commits
|
260
367
|
* Hooks
|
261
368
|
* Forks
|
369
|
+
* Keys
|
370
|
+
* Downloads
|
262
371
|
* etc.
|
263
372
|
|
264
373
|
## Contributing
|
data/lib/github_api_v3/client.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require 'json'
|
3
|
+
require 'github_api_v3/client/commits'
|
4
|
+
require 'github_api_v3/client/contents'
|
3
5
|
require 'github_api_v3/client/events'
|
4
6
|
require 'github_api_v3/client/feeds'
|
5
7
|
require 'github_api_v3/client/gists'
|
@@ -8,6 +10,7 @@ require 'github_api_v3/client/issues'
|
|
8
10
|
require 'github_api_v3/client/markdown'
|
9
11
|
require 'github_api_v3/client/milestones'
|
10
12
|
require 'github_api_v3/client/oauth'
|
13
|
+
require 'github_api_v3/client/octocat'
|
11
14
|
require 'github_api_v3/client/orgs'
|
12
15
|
require 'github_api_v3/client/pull_requests'
|
13
16
|
require 'github_api_v3/client/repos'
|
@@ -26,6 +29,8 @@ module GitHub
|
|
26
29
|
# Default base uri for the API functionality.
|
27
30
|
base_uri Default::API_ENDPOINT
|
28
31
|
|
32
|
+
include GitHub::Client::Commits
|
33
|
+
include GitHub::Client::Contents
|
29
34
|
include GitHub::Client::Events
|
30
35
|
include GitHub::Client::Feeds
|
31
36
|
include GitHub::Client::Gitignore
|
@@ -34,6 +39,7 @@ module GitHub
|
|
34
39
|
include GitHub::Client::Markdown
|
35
40
|
include GitHub::Client::Milestones
|
36
41
|
include GitHub::Client::OAuth
|
42
|
+
include GitHub::Client::Octocat
|
37
43
|
include GitHub::Client::Orgs
|
38
44
|
include GitHub::Client::PullRequests
|
39
45
|
include GitHub::Client::Repos
|
@@ -126,14 +132,15 @@ module GitHub
|
|
126
132
|
# @example POST request
|
127
133
|
# request :post, 'http://example.com/users', params: { name: 'Casey' }, body: { example: 'example' }
|
128
134
|
def request(method, url, options={})
|
129
|
-
params
|
130
|
-
headers
|
131
|
-
body
|
135
|
+
params = options[:params] || {}
|
136
|
+
headers = options[:headers] || {}
|
137
|
+
body = options[:body] || {}
|
138
|
+
no_follow = options[:no_follow] || false
|
132
139
|
|
133
140
|
params.merge!(auth_params)
|
134
141
|
headers.merge!(basic_auth_headers) if @login && @password
|
135
142
|
|
136
|
-
self.class.send(method, url, query: params, body: body.to_json, headers: headers)
|
143
|
+
self.class.send(method, url, query: params, body: body.to_json, headers: headers, no_follow: no_follow)
|
137
144
|
end
|
138
145
|
|
139
146
|
# Get a boolean response from an HTTP request.
|
@@ -172,7 +179,6 @@ module GitHub
|
|
172
179
|
raise Forbidden
|
173
180
|
end
|
174
181
|
when 404 then raise NotFound
|
175
|
-
when 400...500 then raise ClientError
|
176
182
|
when 500 then raise InternalServerError
|
177
183
|
when 502 then raise BadGateway
|
178
184
|
when 503 then raise ServiceUnavailable
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module GitHub
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Commits API.
|
5
|
+
#
|
6
|
+
# @see http://developer.github.com/v3/repos/commits/
|
7
|
+
module Commits
|
8
|
+
|
9
|
+
# List commits on a repository.
|
10
|
+
#
|
11
|
+
# @param owner [String] The repository owner.
|
12
|
+
# @param repo [String] The repository name.
|
13
|
+
# @param options [Hash] Optional parameters.
|
14
|
+
# @option options [String] :sha Sha or branch to start listing commits from.
|
15
|
+
# @option options [String] :path Only commits containing this file path will be returned.
|
16
|
+
# @option options [String] :author GitHub login, name, or email by which to filter by commit author.
|
17
|
+
# @option options [String] :since ISO 8601 date to return commits after.
|
18
|
+
# @option options [String] :until ISO 8601 date to return commits before.
|
19
|
+
# @return [Array] A list of commits.
|
20
|
+
# @see http://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
|
21
|
+
def commits(owner, repo, options={})
|
22
|
+
get "/repos/#{owner}/#{repo}/commits", params: options
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get a single commit.
|
26
|
+
#
|
27
|
+
# @param owner [String] The repository owner.
|
28
|
+
# @param repo [String] The repository name.
|
29
|
+
# @param sha [String] The SHA of the commit.
|
30
|
+
# @return [Hash] The commit information.
|
31
|
+
# @see http://developer.github.com/v3/repos/commits/#get-a-single-commit
|
32
|
+
def commit(owner, repo, sha)
|
33
|
+
get "/repos/#{owner}/#{repo}/commits/#{sha}"
|
34
|
+
end
|
35
|
+
|
36
|
+
# Compare two commits.
|
37
|
+
#
|
38
|
+
# @param owner [String] The repository owner.
|
39
|
+
# @param repo [String] The repository name.
|
40
|
+
# @param base [String] The base SHA of the commit.
|
41
|
+
# @param head [String] The head SHA of the commit.
|
42
|
+
# @return [Hash] Comparison information.
|
43
|
+
# @see http://developer.github.com/v3/repos/commits/#compare-two-commits
|
44
|
+
def compare_commits(owner, repo, base, head)
|
45
|
+
get "/repos/#{owner}/#{repo}/compare/#{base}...#{head}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|