github_api 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +13 -4
- data/lib/github_api.rb +2 -1
- data/lib/github_api/api.rb +29 -14
- data/lib/github_api/client.rb +10 -7
- data/lib/github_api/configuration.rb +16 -1
- data/lib/github_api/connection.rb +2 -1
- data/lib/github_api/core_ext/array.rb +14 -0
- data/lib/github_api/core_ext/hash.rb +38 -0
- data/lib/github_api/repos.rb +42 -14
- data/lib/github_api/repos/hooks.rb +126 -25
- data/lib/github_api/repos/keys.rb +3 -3
- data/lib/github_api/repos/pub_sub_hubbub.rb +12 -0
- data/lib/github_api/request/basic_auth.rb +26 -0
- data/lib/github_api/request/oauth2.rb +2 -2
- data/lib/github_api/version.rb +1 -1
- data/spec/fixtures/repos/branches.json +9 -0
- data/spec/fixtures/repos/contributors.json +8 -0
- data/spec/fixtures/repos/hook.json +15 -0
- data/spec/fixtures/repos/hooks.json +10 -0
- data/spec/fixtures/repos/languages.json +4 -0
- data/spec/fixtures/repos/repo.json +90 -0
- data/spec/fixtures/repos/repos.json +29 -0
- data/spec/fixtures/repos/tags.json +11 -0
- data/spec/fixtures/repos/teams.json +7 -0
- data/spec/github/client_spec.rb +46 -2
- data/spec/github/core_ext/hash_spec.rb +34 -0
- data/spec/github/repos/hooks_spec.rb +304 -2
- data/spec/github/repos/keys_spec.rb +14 -3
- data/spec/github/repos/watching_spec.rb +7 -3
- data/spec/github/repos_spec.rb +555 -22
- data/spec/github_spec.rb +12 -0
- data/spec/spec_helper.rb +8 -0
- metadata +30 -4
@@ -2,64 +2,165 @@
|
|
2
2
|
|
3
3
|
module Github
|
4
4
|
class Repos
|
5
|
+
# The Repository Hooks API manages the post-receive web and service hooks for a repository.
|
5
6
|
module Hooks
|
6
7
|
|
7
|
-
|
8
|
+
VALID_HOOK_PARAM_NAMES = %w[
|
9
|
+
name
|
10
|
+
config
|
11
|
+
active
|
12
|
+
events
|
13
|
+
add_events
|
14
|
+
remove_events
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
# Active hooks can be configured to trigger for one or more events. The default event is push.
|
18
|
+
# The available events are:
|
19
|
+
VALID_HOOK_PARAM_VALUES = {
|
20
|
+
'events' => %w[
|
21
|
+
push
|
22
|
+
issues
|
23
|
+
issue_comment
|
24
|
+
commit_comment
|
25
|
+
pull_request
|
26
|
+
gollum
|
27
|
+
watch
|
28
|
+
download
|
29
|
+
fork
|
30
|
+
fork_apply
|
31
|
+
member
|
32
|
+
public
|
33
|
+
]
|
34
|
+
}.freeze
|
35
|
+
|
36
|
+
REQUIRED_PARAMS = %w[ name config ].freeze
|
8
37
|
|
9
38
|
# List repository hooks
|
10
|
-
#
|
11
|
-
# GET /repos/:user/:repo/hooks
|
12
39
|
#
|
13
|
-
|
14
|
-
|
40
|
+
# = Examples
|
41
|
+
# @github = Github.new
|
42
|
+
# @github.repos.hooks 'user-name', 'repo-name'
|
43
|
+
# @github.repos.hooks 'user-name', 'repo-name' { |hook| ... }
|
44
|
+
#
|
45
|
+
def hooks(user_name=nil, repo_name=nil, params={})
|
46
|
+
_update_user_repo_params(user_name, repo_name)
|
47
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
48
|
+
_normalize_params_keys(params)
|
49
|
+
|
50
|
+
response = get("/repos/#{user}/#{repo}/hooks", params)
|
51
|
+
return response unless block_given?
|
52
|
+
response.each { |el| yield el }
|
15
53
|
end
|
16
54
|
|
17
|
-
# Get a single hook
|
55
|
+
# Get a single hook
|
18
56
|
#
|
19
|
-
#
|
57
|
+
# = Examples
|
58
|
+
# @github = Github.new
|
59
|
+
# @github.repos.hook 'user-name', 'repo-name'
|
20
60
|
#
|
21
|
-
def
|
22
|
-
|
61
|
+
def hook(user_name, repo_name, hook_id, params={})
|
62
|
+
_update_user_repo_params(user_name, repo_name)
|
63
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
64
|
+
_validate_presence_of hook_id
|
65
|
+
_normalize_params_keys(params)
|
66
|
+
|
67
|
+
get("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
23
68
|
end
|
24
69
|
|
25
70
|
# Create a hook
|
26
71
|
#
|
27
|
-
#
|
72
|
+
# = Inputs
|
73
|
+
# * <tt>:name</tt> - Required string - the name of the service that is being called.
|
74
|
+
# * <tt>:config</tt> - Required hash - A Hash containing key/value pairs to provide settings for this hook.
|
75
|
+
# * <tt>:events</tt> - Optional array - Determines what events the hook is triggered for. Default: ["push"]
|
76
|
+
# * <tt>:active</tt> - Optional boolean - Determines whether the hook is actually triggered on pushes.
|
77
|
+
#
|
78
|
+
# = Examples
|
79
|
+
# @github = Github.new
|
80
|
+
# @github.repos.create_hook 'user-name', 'repo-name',
|
81
|
+
# "name" => "web",
|
82
|
+
# "active" => true,
|
83
|
+
# "config" => {
|
84
|
+
# "url" => "http://something.com/webhook"
|
85
|
+
# }
|
86
|
+
# }
|
28
87
|
#
|
29
|
-
def create_hook(
|
88
|
+
def create_hook(user_name=nil, repo_name=nil, params={})
|
89
|
+
_update_user_repo_params(user_name, repo_name)
|
90
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
91
|
+
|
30
92
|
_normalize_params_keys(params)
|
31
|
-
_filter_params_keys(
|
32
|
-
|
93
|
+
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params)
|
94
|
+
|
95
|
+
raise ArgumentError, "Required parameters are: name, config" unless _validate_inputs(REQUIRED_PARAMS, params)
|
33
96
|
|
34
97
|
post("/repos/#{user}/#{repo}/hooks", params)
|
35
98
|
end
|
36
99
|
|
37
100
|
# Edit a hook
|
38
101
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
|
102
|
+
# = Inputs
|
103
|
+
# * <tt>:name</tt> - Required string - the name of the service that is being called.
|
104
|
+
# * <tt>:config</tt> - Required hash - A Hash containing key/value pairs to provide settings for this hook.
|
105
|
+
# * <tt>:events</tt> - Optional array - Determines what events the hook is triggered for. This replaces the entire array of events. Default: ["push"].
|
106
|
+
# * <tt>:add_events</tt> - Optional array - Determines a list of events to be added to the list of events that the Hook triggers for.
|
107
|
+
# * <tt>:remove_events</tt> - Optional array - Determines a list of events to be removed from the list of events that the Hook triggers for.
|
108
|
+
# * <tt>:active</tt> - Optional boolean - Determines whether the hook is actually triggered on pushes.
|
109
|
+
#
|
110
|
+
# = Examples
|
111
|
+
# @github = Github.new
|
112
|
+
# @github.repos.edit_hook 'user-name', 'repo-name',
|
113
|
+
# "name" => "campfire",
|
114
|
+
# "active" => true,
|
115
|
+
# "config" => {
|
116
|
+
# "subdomain" => "github",
|
117
|
+
# "room" => "Commits",
|
118
|
+
# "token" => "abc123"
|
119
|
+
# }
|
120
|
+
#
|
121
|
+
def edit_hook(user_name, repo_name, hook_id, params={})
|
122
|
+
_update_user_repo_params(user_name, repo_name)
|
123
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
124
|
+
_validate_presence_of hook_id
|
125
|
+
|
42
126
|
_normalize_params_keys(params)
|
43
|
-
_filter_params_keys(
|
44
|
-
raise ArgumentError, "Required parameters are: #{REQUIRED_PARAMS.join(', ')}" unless _validate_inputs(REQUIRED_PARAMS, params)
|
127
|
+
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params)
|
45
128
|
|
46
|
-
|
129
|
+
raise ArgumentError, "Required parameters are: name, config" unless _validate_inputs(REQUIRED_PARAMS, params)
|
130
|
+
|
131
|
+
patch("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
47
132
|
end
|
48
133
|
|
49
134
|
# Test a hook
|
50
135
|
#
|
51
|
-
#
|
136
|
+
# This will trigger the hook with the latest push to the current repository.
|
137
|
+
#
|
138
|
+
# = Examples
|
139
|
+
# @github = Github.new
|
140
|
+
# @github.repos.test_hook 'user-name', 'repo-name', 'hook-id'
|
52
141
|
#
|
53
|
-
def test_hook(
|
54
|
-
|
142
|
+
def test_hook(user_name, repo_name, hook_id, params={})
|
143
|
+
_update_user_repo_params(user_name, repo_name)
|
144
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
145
|
+
_validate_presence_of hook_id
|
146
|
+
_normalize_params_keys(params)
|
147
|
+
|
148
|
+
post("/repos/#{user}/#{repo}/hooks/#{hook_id}/test", params)
|
55
149
|
end
|
56
150
|
|
57
151
|
# Delete a hook
|
58
152
|
#
|
59
|
-
#
|
153
|
+
# = Examples
|
154
|
+
# @github = Github.new
|
155
|
+
# @github.repos.delete_hook 'user-name', 'repo-name', 'hook-id'
|
60
156
|
#
|
61
|
-
def delete_hook(
|
62
|
-
|
157
|
+
def delete_hook(user_name, repo_name, hook_id, params={})
|
158
|
+
_update_user_repo_params(user_name, repo_name)
|
159
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
160
|
+
_validate_presence_of hook_id
|
161
|
+
_normalize_params_keys(params)
|
162
|
+
|
163
|
+
delete("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
63
164
|
end
|
64
165
|
|
65
166
|
end # Hooks
|
@@ -35,7 +35,7 @@ module Github
|
|
35
35
|
_validate_presence_of key_id
|
36
36
|
_normalize_params_keys(params)
|
37
37
|
|
38
|
-
get("/repos/#{user}/#{repo}/keys/#{key_id}")
|
38
|
+
get("/repos/#{user}/#{repo}/keys/#{key_id}", params)
|
39
39
|
end
|
40
40
|
|
41
41
|
# Create a key
|
@@ -81,7 +81,7 @@ module Github
|
|
81
81
|
_normalize_params_keys(params)
|
82
82
|
_filter_params_keys(VALID_KEY_PARAM_NAMES, params)
|
83
83
|
|
84
|
-
patch("/repos/#{user}/#{repo}/keys/#{key_id}")
|
84
|
+
patch("/repos/#{user}/#{repo}/keys/#{key_id}", params)
|
85
85
|
end
|
86
86
|
|
87
87
|
# Delete key
|
@@ -96,7 +96,7 @@ module Github
|
|
96
96
|
_validate_presence_of key_id
|
97
97
|
_normalize_params_keys(params)
|
98
98
|
|
99
|
-
delete("/repos/#{user}/#{repo}/keys/#{key_id}")
|
99
|
+
delete("/repos/#{user}/#{repo}/keys/#{key_id}", params)
|
100
100
|
end
|
101
101
|
|
102
102
|
end # Keys
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
module Github
|
7
|
+
module Request
|
8
|
+
class BasicAuth < Faraday::Middleware
|
9
|
+
dependency 'base64'
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
# puts "BASIC: #{@auth}"
|
13
|
+
env[:request_headers].merge!('Authorization' => "Basic #{@auth}\"")
|
14
|
+
|
15
|
+
@app.call env
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(app, *args)
|
19
|
+
@app = app
|
20
|
+
login, password = args.shift, args.shift
|
21
|
+
@auth = Base64.encode64("#{login}:#{password}")
|
22
|
+
@auth.gsub!("\n", "")
|
23
|
+
end
|
24
|
+
end # BasicAuth
|
25
|
+
end # Request
|
26
|
+
end # Github
|
data/lib/github_api/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/hooks/1",
|
3
|
+
"updated_at": "2011-09-06T20:39:23Z",
|
4
|
+
"created_at": "2011-09-06T17:26:27Z",
|
5
|
+
"name": "web",
|
6
|
+
"events": [
|
7
|
+
"push"
|
8
|
+
],
|
9
|
+
"active": true,
|
10
|
+
"config": {
|
11
|
+
"url": "http://example.com",
|
12
|
+
"content_type": "json"
|
13
|
+
},
|
14
|
+
"id": 1
|
15
|
+
}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
{
|
2
|
+
"url": "https://api.github.com/repos/octocat/Hello-World",
|
3
|
+
"html_url": "https://github.com/octocat/Hello-World",
|
4
|
+
"clone_url": "https://github.com/octocat/Hello-World.git",
|
5
|
+
"git_url": "git://github.com/octocat/Hello-World.git",
|
6
|
+
"ssh_url": "git@github.com:octocat/Hello-World.git",
|
7
|
+
"svn_url": "https://svn.github.com/octocat/Hello-World",
|
8
|
+
"owner": {
|
9
|
+
"login": "octocat",
|
10
|
+
"id": 1,
|
11
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
12
|
+
"url": "https://api.github.com/users/octocat"
|
13
|
+
},
|
14
|
+
"name": "Hello-World",
|
15
|
+
"description": "This your first repo!",
|
16
|
+
"homepage": "https://github.com",
|
17
|
+
"language": null,
|
18
|
+
"private": false,
|
19
|
+
"fork": false,
|
20
|
+
"forks": 9,
|
21
|
+
"watchers": 80,
|
22
|
+
"size": 108,
|
23
|
+
"master_branch": "master",
|
24
|
+
"open_issues": 0,
|
25
|
+
"pushed_at": "2011-01-26T19:06:43Z",
|
26
|
+
"created_at": "2011-01-26T19:01:12Z",
|
27
|
+
"organization": {
|
28
|
+
"login": "octocat",
|
29
|
+
"id": 1,
|
30
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
31
|
+
"url": "https://api.github.com/users/octocat",
|
32
|
+
"type": "Organization"
|
33
|
+
},
|
34
|
+
"parent": {
|
35
|
+
"url": "https://api.github.com/repos/octocat/Hello-World",
|
36
|
+
"html_url": "https://github.com/octocat/Hello-World",
|
37
|
+
"clone_url": "https://github.com/octocat/Hello-World.git",
|
38
|
+
"git_url": "git://github.com/octocat/Hello-World.git",
|
39
|
+
"svn_url": "https://svn.github.com/octocat/Hello-World",
|
40
|
+
"owner": {
|
41
|
+
"login": "octocat",
|
42
|
+
"id": 1,
|
43
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
44
|
+
"url": "https://api.github.com/users/octocat"
|
45
|
+
},
|
46
|
+
"name": "Hello-World",
|
47
|
+
"description": "This your first repo!",
|
48
|
+
"homepage": "https://github.com",
|
49
|
+
"language": null,
|
50
|
+
"private": false,
|
51
|
+
"fork": false,
|
52
|
+
"forks": 9,
|
53
|
+
"watchers": 80,
|
54
|
+
"size": 108,
|
55
|
+
"master_branch": "master",
|
56
|
+
"open_issues": 0,
|
57
|
+
"pushed_at": "2011-01-26T19:06:43Z",
|
58
|
+
"created_at": "2011-01-26T19:01:12Z"
|
59
|
+
},
|
60
|
+
"source": {
|
61
|
+
"url": "https://api.github.com/repos/octocat/Hello-World",
|
62
|
+
"html_url": "https://github.com/octocat/Hello-World",
|
63
|
+
"clone_url": "https://github.com/octocat/Hello-World.git",
|
64
|
+
"git_url": "git://github.com/octocat/Hello-World.git",
|
65
|
+
"ssh_url": "git@github.com:octocat/Hello-World.git",
|
66
|
+
"svn_url": "https://svn.github.com/octocat/Hello-World",
|
67
|
+
"owner": {
|
68
|
+
"login": "octocat",
|
69
|
+
"id": 1,
|
70
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
71
|
+
"url": "https://api.github.com/users/octocat"
|
72
|
+
},
|
73
|
+
"name": "Hello-World",
|
74
|
+
"description": "This your first repo!",
|
75
|
+
"homepage": "https://github.com",
|
76
|
+
"language": null,
|
77
|
+
"private": false,
|
78
|
+
"fork": false,
|
79
|
+
"forks": 9,
|
80
|
+
"watchers": 80,
|
81
|
+
"size": 108,
|
82
|
+
"master_branch": "master",
|
83
|
+
"open_issues": 0,
|
84
|
+
"pushed_at": "2011-01-26T19:06:43Z",
|
85
|
+
"created_at": "2011-01-26T19:01:12Z"
|
86
|
+
},
|
87
|
+
"has_issues": true,
|
88
|
+
"has_wiki": true,
|
89
|
+
"has_downloads": true
|
90
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"url": "https://api.github.com/repos/octocat/Hello-World",
|
4
|
+
"html_url": "https://github.com/octocat/Hello-World",
|
5
|
+
"clone_url": "https://github.com/octocat/Hello-World.git",
|
6
|
+
"git_url": "git://github.com/octocat/Hello-World.git",
|
7
|
+
"ssh_url": "git@github.com:octocat/Hello-World.git",
|
8
|
+
"svn_url": "https://svn.github.com/octocat/Hello-World",
|
9
|
+
"owner": {
|
10
|
+
"login": "octocat",
|
11
|
+
"id": 1,
|
12
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
13
|
+
"url": "https://api.github.com/users/octocat"
|
14
|
+
},
|
15
|
+
"name": "Hello-World",
|
16
|
+
"description": "This your first repo!",
|
17
|
+
"homepage": "https://github.com",
|
18
|
+
"language": null,
|
19
|
+
"private": false,
|
20
|
+
"fork": false,
|
21
|
+
"forks": 9,
|
22
|
+
"watchers": 80,
|
23
|
+
"size": 108,
|
24
|
+
"master_branch": "master",
|
25
|
+
"open_issues": 0,
|
26
|
+
"pushed_at": "2011-01-26T19:06:43Z",
|
27
|
+
"created_at": "2011-01-26T19:01:12Z"
|
28
|
+
}
|
29
|
+
]
|