Skip to content

Commit 591dbe6

Browse files
committed
Merge branch 'master' of github.com:peter-murach/github
2 parents a7b1118 + 57b504d commit 591dbe6

15 files changed

Lines changed: 503 additions & 11 deletions

File tree

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ Supports all the API methods. It's built in a modular way. You can either instan
2020

2121
## Features
2222

23-
* Intuitive GitHub API interface navigation. [usage](#usage)
24-
* Modular design allows for working with parts of API. [api](#api)
25-
* Fully customizable including advanced middleware stack construction. [config](#advanced-configuration)
23+
* Intuitive GitHub API interface navigation. [usage](#1-usage)
24+
* Modular design allows for working with parts of API. [api](#12-api-navigation)
25+
* Fully customizable including advanced middleware stack construction. [config](#3-advanced-configuration)
2626
* It's comprehensive. You can request all GitHub API resources.
27-
* Supports OAuth2 authorization. [oauth](#oauth)
28-
* Flexible argument parsing. You can write expressive and natural queries. [params](#arguments--parameters)
29-
* Requests pagination with convenient DSL and automatic options. [pagination](#pagination)
30-
* Easy error handling split for client and server type errors. [error](#error-handling)
27+
* Supports OAuth2 authorization. [oauth](#42-application-oauth-access)
28+
* Flexible argument parsing. You can write expressive and natural queries. [params](#2-arguments--parameters)
29+
* Requests pagination with convenient DSL and automatic options. [pagination](#10-pagination)
30+
* Easy error handling split for client and server type errors. [error](#13-error-handling)
3131
* Supports multithreaded environment.
32-
* Custom media type specification through the 'media' parameter. [media](#media-types)
32+
* Custom media type specification through the 'media' parameter. [media](#7-media-types)
3333
* Request results caching (Status: TODO)
34-
* Fully tested with test coverage above 90% with over 1,700 specs and 1000 features. [testing](#testing)
34+
* Fully tested with test coverage above 90% with over 1,700 specs and 1000 features. [testing](#16-testing)
3535

3636
## Installation
3737

@@ -308,7 +308,7 @@ Furthermore, to create auth token for an application you need to pass `:app` arg
308308

309309
```ruby
310310
github = Github.new basic_auth: 'login:password'
311-
github.oauth.app.create 'clinet-id', scopes: ['repo']
311+
github.oauth.app.create 'client-id', scopes: ['repo']
312312
```
313313

314314
In order to revoke auth token(s) for an application you must use basic authentication with `client_id` as login and `client_secret` as password.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions":[{"request":{"method":"get","uri":"https://<BASIC_AUTH>@api.github.com/rate_limit?access_token=<TOKEN>","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1"],"Accept-Charset":["utf-8"],"User-Agent":["Github Ruby Gem 0.11.3"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["GitHub.com"],"Date":["Mon, 21 Apr 2014 15:24:09 GMT"],"Content-Type":["application/json; charset=utf-8"],"Transfer-Encoding":["chunked"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4886"],"X-Ratelimit-Reset":["1398097303"],"Cache-Control":["no-cache"],"X-Github-Media-Type":["github.v3; format=json"],"X-Xss-Protection":["1; mode=block"],"X-Frame-Options":["deny"],"Content-Security-Policy":["default-src 'none'"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"X-Github-Request-Id":["4D649864:1929:5A9FF41:53553819"],"Strict-Transport-Security":["max-age=31536000"],"X-Content-Type-Options":["nosniff"],"Vary":["Accept-Encoding"],"X-Served-By":["971af40390ac4398fcdd45c8dab0fbe7"]},"body":{"encoding":"UTF-8","base64_string":"eyJyZXNvdXJjZXMiOnsiY29yZSI6eyJsaW1pdCI6NTAwMCwicmVtYWluaW5n\nIjo0ODg2LCJyZXNldCI6MTM5ODA5NzMwM30sInNlYXJjaCI6eyJsaW1pdCI6\nMzAsInJlbWFpbmluZyI6MzAsInJlc2V0IjoxMzk4MDkzOTA5fX0sInJhdGUi\nOnsibGltaXQiOjUwMDAsInJlbWFpbmluZyI6NDg4NiwicmVzZXQiOjEzOTgw\nOTczMDN9fQ==\n"},"http_version":null},"recorded_at":"Mon, 21 Apr 2014 15:24:09 GMT"}],"recorded_with":"VCR 2.6.0"}

features/rate_limit.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ Feature: Ratelimit API
1414
Given I want to ratelimit_remaining resource
1515
When I make request within a cassette named "ratelimit/get_remaining"
1616
Then the response should be 4886
17+
18+
Scenario: Get ratelimit reset time
19+
20+
Given I want to ratelimit_reset resource
21+
When I make request within a cassette named "ratelimit/get_reset"
22+
Then the response should be 1398097303

lib/github_api/client/issues.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Client::Issues < API
3030

3131
VALID_ISSUE_PARAM_VALUES = {
3232
'filter' => %w[ assigned created mentioned subscribed all ],
33-
'state' => %w[ open closed ],
33+
'state' => %w[ open closed all ],
3434
'sort' => %w[ created updated comments ],
3535
'direction' => %w[ desc asc ],
3636
'since' => %r{\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z}

lib/github_api/client/repos.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Client::Repos < API
88
'comments',
99
'commits',
1010
'contents',
11+
'deployments',
1112
'downloads',
1213
'forks',
1314
'hooks',
@@ -57,6 +58,9 @@ class Client::Repos < API
5758
# Access to Repos::Contents API
5859
namespace :contents
5960

61+
# Access to Repos::Deployments API
62+
namespace :deployments
63+
6064
# Access to Repos::Downloads API
6165
namespace :downloads
6266

lib/github_api/client/repos/deployments.rb

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,107 @@
33
module Github
44
class Client::Repos::Deployments < API
55

6+
VALID_DEPLOYMENTS_OPTIONS = %w[
7+
ref
8+
force
9+
payload
10+
auto_merge
11+
description
12+
]
13+
14+
PREVIEW_MEDIA = 'application/vnd.github.cannonball-preview+json'.freeze # :nodoc:
15+
16+
# List deployments on a repository
17+
#
18+
# = Examples
19+
# github = Github.new
20+
# github.repos.deployments.list 'user-name', 'repo-name'
21+
# github.repos.deployments.list 'user-name', 'repo-name' { |deployment| ... }
22+
#
23+
def list(*args)
24+
arguments(args, :required => [:user, :repo])
25+
params = arguments.params
26+
params['accept'] ||= PREVIEW_MEDIA
27+
28+
response = get_request("repos/#{user}/#{repo}/deployments", params)
29+
return response unless block_given?
30+
31+
response.each { |el| yield el }
32+
end
33+
alias :all :list
34+
35+
# Create a deployment
36+
#
37+
# = Parameters
38+
# * <tt>:ref</tt> Required string. Sha or branch to start listing commits from.
39+
# * <tt>:force</tt> Optional boolean. Ignore commit status checks.
40+
# * <tt>:payload</tt> Optional string. Optional json payload with information about the deployment.
41+
# * <tt>:auto_merge</tt> Optional boolean. Merge the default branch into the requested deployment branch if necessary.
42+
# * <tt>:description</tt> Optional string. Optional short description.
43+
# = Examples
44+
# github = Github.new
45+
# github.repos.deployments.create 'user-name', 'repo-name', :ref => '...'
46+
# github.repos.deployments.create
47+
# 'user-name',
48+
# 'repo-name',
49+
# ref: '...',
50+
# description: 'New deploy',
51+
# force: true
52+
#
53+
def create(*args)
54+
arguments(args, :required => [:user, :repo]) do
55+
sift VALID_DEPLOYMENTS_OPTIONS
56+
assert_required %w[ ref ]
57+
end
58+
59+
params = arguments.params
60+
params['accept'] ||= PREVIEW_MEDIA
61+
62+
post_request("repos/#{user}/#{repo}/deployments", params)
63+
end
64+
65+
# List the statuses of a deployment.
66+
#
67+
# = Parameters
68+
# * <tt>:id</tt> Required string. Id of the deployment being queried.
69+
# = Examples
70+
# github = Github.new
71+
# github.repos.deployments.statuses 'user-name', 'repo-name', DEPLOYMENT_ID
72+
# github.repos.deployments.statuses 'user-name', 'repo-name', DEPLOYMENT_ID { |status| ... }
73+
#
74+
def statuses(*args)
75+
arguments(args, :required => [:user, :repo, :id])
76+
77+
params = arguments.params
78+
params['accept'] ||= PREVIEW_MEDIA
79+
80+
statuses = get_request("repos/#{user}/#{repo}/deployments/#{id}/statuses", params)
81+
return statuses unless block_given?
82+
83+
statuses.each { |status| yield status }
84+
end
85+
86+
# Create a deployment status
87+
#
88+
# = Parameters
89+
# * <tt>:id</tt> Required string. Id of the deployment being referenced.
90+
# * <tt>:state</tt> Required string. State of the deployment. Can be one of: pending, success, error, or failure.
91+
# * <tt>:target_url</tt> Optional string. The URL associated with the status.
92+
# * <tt>:description</tt> Optional string. A short description of the status.
93+
# = Examples
94+
# github = Github.new
95+
# github.repos.deployments.create_status 'user-name', 'repo-name', DEPLOYMENT_ID, :state => '...'
96+
#
97+
def create_status(*args)
98+
arguments(args, :required => [:user, :repo, :id]) do
99+
assert_required %w[ state ]
100+
end
101+
102+
params = arguments.params
103+
params['accept'] ||= PREVIEW_MEDIA
104+
105+
post_request("repos/#{user}/#{repo}/deployments/#{id}/statuses", params)
106+
end
107+
6108
end # Client::Repos::Deployments
7109
end

lib/github_api/rate_limit.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,11 @@ def ratelimit_remaining(*args)
1515
get_request("/rate_limit", arguments.params).rate.remaining
1616
end
1717

18+
def ratelimit_reset(*args)
19+
arguments(args)
20+
21+
get_request("/rate_limit", arguments.params).rate.reset
22+
end
23+
1824
end # RateLimit
1925
end # Github
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"url": "https://api.github.com/repos/nahiluhmot/github/deployments/10949",
3+
"id": 10949,
4+
"sha": "a9a5ad01cf26b646e6f95bf9e2d13a2a155b5c9b",
5+
"ref": "a9a5ad01cf26b646e6f95bf9e2d13a2a155b5c9b",
6+
"payload": {},
7+
"environment": "production",
8+
"description": "Test deploy",
9+
"creator": {
10+
"login": "nahiluhmot",
11+
"id": 1449846,
12+
"avatar_url": "https://avatars.githubusercontent.com/u/1449846?",
13+
"gravatar_id": "bf94307804fd07054f5c3c7cbd2112fb",
14+
"url": "https://api.github.com/users/nahiluhmot",
15+
"html_url": "https://github.com/nahiluhmot",
16+
"followers_url": "https://api.github.com/users/nahiluhmot/followers",
17+
"following_url": "https://api.github.com/users/nahiluhmot/following{/other_user}",
18+
"gists_url": "https://api.github.com/users/nahiluhmot/gists{/gist_id}",
19+
"starred_url": "https://api.github.com/users/nahiluhmot/starred{/owner}{/repo}",
20+
"subscriptions_url": "https://api.github.com/users/nahiluhmot/subscriptions",
21+
"organizations_url": "https://api.github.com/users/nahiluhmot/orgs",
22+
"repos_url": "https://api.github.com/users/nahiluhmot/repos",
23+
"events_url": "https://api.github.com/users/nahiluhmot/events{/privacy}",
24+
"received_events_url": "https://api.github.com/users/nahiluhmot/received_events",
25+
"type": "User",
26+
"site_admin": false
27+
},
28+
"created_at": "2014-05-09T20:40:54Z",
29+
"updated_at": "2014-05-09T20:40:54Z",
30+
"statuses_url": "https://api.github.com/repos/nahiluhmot/github/deployments/10949/statuses"
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"url": "https://api.github.com/repos/nahiluhmot/github/deployments/10952/statuses/12147",
3+
"id": 12147,
4+
"sha": "a9a5ad01cf26b646e6f95bf9e2d13a2a155b5c9b",
5+
"ref": "a9a5ad01cf26b646e6f95bf9e2d13a2a155b5c9b",
6+
"state": "success",
7+
"payload": {},
8+
"environment": "production",
9+
"description": null,
10+
"target_url": null,
11+
"creator": {
12+
"login": "nahiluhmot",
13+
"id": 1449846,
14+
"avatar_url": "https://avatars.githubusercontent.com/u/1449846?",
15+
"gravatar_id": "bf94307804fd07054f5c3c7cbd2112fb",
16+
"url": "https://api.github.com/users/nahiluhmot",
17+
"html_url": "https://github.com/nahiluhmot",
18+
"followers_url": "https://api.github.com/users/nahiluhmot/followers",
19+
"following_url": "https://api.github.com/users/nahiluhmot/following{/other_user}",
20+
"gists_url": "https://api.github.com/users/nahiluhmot/gists{/gist_id}",
21+
"starred_url": "https://api.github.com/users/nahiluhmot/starred{/owner}{/repo}",
22+
"subscriptions_url": "https://api.github.com/users/nahiluhmot/subscriptions",
23+
"organizations_url": "https://api.github.com/users/nahiluhmot/orgs",
24+
"repos_url": "https://api.github.com/users/nahiluhmot/repos",
25+
"events_url": "https://api.github.com/users/nahiluhmot/events{/privacy}",
26+
"received_events_url": "https://api.github.com/users/nahiluhmot/received_events",
27+
"type": "User",
28+
"site_admin": false
29+
},
30+
"created_at": "2014-05-09T21:26:46Z",
31+
"updated_at": "2014-05-09T21:26:46Z",
32+
"deployment_url": "https://api.github.com/repos/nahiluhmot/github/deployments/10952"
33+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[
2+
{
3+
"url": "https://api.github.com/repos/nahiluhmot/github/deployments/10952/statuses/12148",
4+
"id": 12148,
5+
"sha": "a9a5ad01cf26b646e6f95bf9e2d13a2a155b5c9b",
6+
"ref": "a9a5ad01cf26b646e6f95bf9e2d13a2a155b5c9b",
7+
"state": "success",
8+
"payload": {},
9+
"environment": "production",
10+
"description": null,
11+
"target_url": null,
12+
"creator": {
13+
"login":"nahiluhmot",
14+
"id": 1449846,
15+
"avatar_url": "https://avatars.githubusercontent.com/u/1449846?",
16+
"gravatar_id": "bf94307804fd07054f5c3c7cbd2112fb",
17+
"url": "https://api.github.com/users/nahiluhmot",
18+
"html_url": "https://github.com/nahiluhmot",
19+
"followers_url": "https://api.github.com/users/nahiluhmot/followers",
20+
"following_url": "https://api.github.com/users/nahiluhmot/following{/other_user}",
21+
"gists_url": "https://api.github.com/users/nahiluhmot/gists{/gist_id}",
22+
"starred_url": "https://api.github.com/users/nahiluhmot/starred{/owner}{/repo}",
23+
"subscriptions_url": "https://api.github.com/users/nahiluhmot/subscriptions",
24+
"organizations_url": "https://api.github.com/users/nahiluhmot/orgs",
25+
"repos_url": "https://api.github.com/users/nahiluhmot/repos",
26+
"events_url": "https://api.github.com/users/nahiluhmot/events{/privacy}",
27+
"received_events_url": "https://api.github.com/users/nahiluhmot/received_events",
28+
"type": "User",
29+
"site_admin": false
30+
},
31+
"created_at": "2014-05-09T21:30:28Z",
32+
"updated_at": "2014-05-09T21:30:28Z",
33+
"deployment_url": "https://api.github.com/repos/nahiluhmot/github/deployments/10952"
34+
},
35+
{
36+
"url": "https://api.github.com/repos/nahiluhmot/github/deployments/10952/statuses/12147",
37+
"id": 12147,
38+
"sha": "a9a5ad01cf26b646e6f95bf9e2d13a2a155b5c9b",
39+
"ref": "a9a5ad01cf26b646e6f95bf9e2d13a2a155b5c9b",
40+
"state": "success",
41+
"payload": {},
42+
"environment": "production",
43+
"description": null,
44+
"target_url": null,
45+
"creator": {
46+
"login":"nahiluhmot",
47+
"id": 1449846,
48+
"avatar_url": "https://avatars.githubusercontent.com/u/1449846?",
49+
"gravatar_id": "bf94307804fd07054f5c3c7cbd2112fb",
50+
"url": "https://api.github.com/users/nahiluhmot",
51+
"html_url": "https://github.com/nahiluhmot",
52+
"followers_url": "https://api.github.com/users/nahiluhmot/followers",
53+
"following_url": "https://api.github.com/users/nahiluhmot/following{/other_user}",
54+
"gists_url": "https://api.github.com/users/nahiluhmot/gists{/gist_id}",
55+
"starred_url": "https://api.github.com/users/nahiluhmot/starred{/owner}{/repo}",
56+
"subscriptions_url": "https://api.github.com/users/nahiluhmot/subscriptions",
57+
"organizations_url": "https://api.github.com/users/nahiluhmot/orgs",
58+
"repos_url": "https://api.github.com/users/nahiluhmot/repos",
59+
"events_url": "https://api.github.com/users/nahiluhmot/events{/privacy}",
60+
"received_events_url": "https://api.github.com/users/nahiluhmot/received_events",
61+
"type": "User",
62+
"site_admin": false
63+
},
64+
"created_at": "2014-05-09T21:26:46Z",
65+
"updated_at": "2014-05-09T21:26:46Z",
66+
"deployment_url": "https://api.github.com/repos/nahiluhmot/github/deployments/10952"
67+
}
68+
]

0 commit comments

Comments
 (0)