octokit 3.6.1 → 3.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/octokit/client/hooks.rb +282 -0
- data/lib/octokit/client/repositories.rb +0 -134
- data/lib/octokit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f2a4c4a887142b38092500f915ae1e76045a088
|
4
|
+
data.tar.gz: 8b6a457b671dda7b59e4d95a9e21bf02326a0ff1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcca491b69213f7fd2fe9aee6c439c7751b7d77802a2f8328e64456e6f3bc5739eef054e2640294df1c6430d820adef26d1d30aba1243c4b7fe7a377441b8169
|
7
|
+
data.tar.gz: d6e871030302eb322560f7534ff8ea963d616c455e711666a860c784443933a34e89ec6dc4bbf658e55ea6136d8c090e357b37b92743199c0760f508a2c2d34a
|
data/lib/octokit/client/hooks.rb
CHANGED
@@ -4,6 +4,8 @@ module Octokit
|
|
4
4
|
# Methods for the Hooks API
|
5
5
|
module Hooks
|
6
6
|
|
7
|
+
ORG_HOOKS_PREVIEW_MEDIA_TYPE = "application/vnd.github.sersi-preview+json".freeze
|
8
|
+
|
7
9
|
# List all Service Hooks supported by GitHub
|
8
10
|
#
|
9
11
|
# @return [Sawyer::Resource] A list of all hooks on GitHub
|
@@ -13,6 +15,286 @@ module Octokit
|
|
13
15
|
def available_hooks(options = {})
|
14
16
|
get "hooks", options
|
15
17
|
end
|
18
|
+
|
19
|
+
# List repo hooks
|
20
|
+
#
|
21
|
+
# Requires authenticated client.
|
22
|
+
#
|
23
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
24
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing hooks.
|
25
|
+
# @see https://developer.github.com/v3/repos/hooks/#list-hooks
|
26
|
+
# @example
|
27
|
+
# @client.hooks('octokit/octokit.rb')
|
28
|
+
def hooks(repo, options = {})
|
29
|
+
paginate "#{Repository.path repo}/hooks", options
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get single hook
|
33
|
+
#
|
34
|
+
# Requires authenticated client.
|
35
|
+
#
|
36
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
37
|
+
# @param id [Integer] Id of the hook to get.
|
38
|
+
# @return [Sawyer::Resource] Hash representing hook.
|
39
|
+
# @see https://developer.github.com/v3/repos/hooks/#get-single-hook
|
40
|
+
# @example
|
41
|
+
# @client.hook('octokit/octokit.rb', 100000)
|
42
|
+
def hook(repo, id, options = {})
|
43
|
+
get "#{Repository.path repo}/hooks/#{id}", options
|
44
|
+
end
|
45
|
+
|
46
|
+
# Create a hook
|
47
|
+
#
|
48
|
+
# Requires authenticated client.
|
49
|
+
#
|
50
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
51
|
+
# @param name [String] The name of the service that is being called. See
|
52
|
+
# {https://api.github.com/hooks Hooks} for the possible names.
|
53
|
+
# @param config [Hash] A Hash containing key/value pairs to provide
|
54
|
+
# settings for this hook. These settings vary between the services and
|
55
|
+
# are defined in the {https://github.com/github/github-services github-services} repo.
|
56
|
+
# @option options [Array<String>] :events ('["push"]') Determines what
|
57
|
+
# events the hook is triggered for.
|
58
|
+
# @option options [Boolean] :active Determines whether the hook is
|
59
|
+
# actually triggered on pushes.
|
60
|
+
# @return [Sawyer::Resource] Hook info for the new hook
|
61
|
+
# @see https://api.github.com/hooks
|
62
|
+
# @see https://github.com/github/github-services
|
63
|
+
# @see https://developer.github.com/v3/repos/hooks/#create-a-hook
|
64
|
+
# @example
|
65
|
+
# @client.create_hook(
|
66
|
+
# 'octokit/octokit.rb',
|
67
|
+
# 'web',
|
68
|
+
# {
|
69
|
+
# :url => 'http://something.com/webhook',
|
70
|
+
# :content_type => 'json'
|
71
|
+
# },
|
72
|
+
# {
|
73
|
+
# :events => ['push', 'pull_request'],
|
74
|
+
# :active => true
|
75
|
+
# }
|
76
|
+
# )
|
77
|
+
def create_hook(repo, name, config, options = {})
|
78
|
+
options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
|
79
|
+
post "#{Repository.path repo}/hooks", options
|
80
|
+
end
|
81
|
+
|
82
|
+
# Edit a hook
|
83
|
+
#
|
84
|
+
# Requires authenticated client.
|
85
|
+
#
|
86
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
87
|
+
# @param id [Integer] Id of the hook being updated.
|
88
|
+
# @param name [String] The name of the service that is being called. See
|
89
|
+
# {https://api.github.com/hooks Hooks} for the possible names.
|
90
|
+
# @param config [Hash] A Hash containing key/value pairs to provide
|
91
|
+
# settings for this hook. These settings vary between the services and
|
92
|
+
# are defined in the {https://github.com/github/github-services github-services} repo.
|
93
|
+
# @option options [Array<String>] :events ('["push"]') Determines what
|
94
|
+
# events the hook is triggered for.
|
95
|
+
# @option options [Array<String>] :add_events Determines a list of events
|
96
|
+
# to be added to the list of events that the Hook triggers for.
|
97
|
+
# @option options [Array<String>] :remove_events Determines a list of events
|
98
|
+
# to be removed from the list of events that the Hook triggers for.
|
99
|
+
# @option options [Boolean] :active Determines whether the hook is
|
100
|
+
# actually triggered on pushes.
|
101
|
+
# @return [Sawyer::Resource] Hook info for the updated hook
|
102
|
+
# @see https://api.github.com/hooks
|
103
|
+
# @see https://github.com/github/github-services
|
104
|
+
# @see https://developer.github.com/v3/repos/hooks/#edit-a-hook
|
105
|
+
# @example
|
106
|
+
# @client.edit_hook(
|
107
|
+
# 'octokit/octokit.rb',
|
108
|
+
# 100000,
|
109
|
+
# 'web',
|
110
|
+
# {
|
111
|
+
# :url => 'http://something.com/webhook',
|
112
|
+
# :content_type => 'json'
|
113
|
+
# },
|
114
|
+
# {
|
115
|
+
# :add_events => ['status'],
|
116
|
+
# :remove_events => ['pull_request'],
|
117
|
+
# :active => true
|
118
|
+
# }
|
119
|
+
# )
|
120
|
+
def edit_hook(repo, id, name, config, options = {})
|
121
|
+
options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
|
122
|
+
patch "#{Repository.path repo}/hooks/#{id}", options
|
123
|
+
end
|
124
|
+
|
125
|
+
# Delete hook
|
126
|
+
#
|
127
|
+
# Requires authenticated client.
|
128
|
+
#
|
129
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
130
|
+
# @param id [Integer] Id of the hook to remove.
|
131
|
+
# @return [Boolean] True if hook removed, false otherwise.
|
132
|
+
# @see https://developer.github.com/v3/repos/hooks/#delete-a-hook
|
133
|
+
# @example
|
134
|
+
# @client.remove_hook('octokit/octokit.rb', 1000000)
|
135
|
+
def remove_hook(repo, id, options = {})
|
136
|
+
boolean_from_response :delete, "#{Repository.path repo}/hooks/#{id}", options
|
137
|
+
end
|
138
|
+
|
139
|
+
# Test hook
|
140
|
+
#
|
141
|
+
# Requires authenticated client.
|
142
|
+
#
|
143
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
144
|
+
# @param id [Integer] Id of the hook to test.
|
145
|
+
# @return [Boolean] Success
|
146
|
+
# @see https://developer.github.com/v3/repos/hooks/#test-a-push-hook
|
147
|
+
# @example
|
148
|
+
# @client.test_hook('octokit/octokit.rb', 1000000)
|
149
|
+
def test_hook(repo, id, options = {})
|
150
|
+
boolean_from_response :post, "#{Repository.path repo}/hooks/#{id}/tests", options
|
151
|
+
end
|
152
|
+
|
153
|
+
# List org hooks
|
154
|
+
#
|
155
|
+
# Requires client authenticated as admin for the org.
|
156
|
+
#
|
157
|
+
# @param org [String] A GitHub organization login.
|
158
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing hooks.
|
159
|
+
# @see https://developer.github.com/v3/orgs/hooks/#list-hooks
|
160
|
+
# @example
|
161
|
+
# @client.org_hooks('octokit')
|
162
|
+
def org_hooks(org, options = {})
|
163
|
+
options = ensure_org_hooks_api_media_type(options)
|
164
|
+
paginate "orgs/#{org}/hooks", options
|
165
|
+
end
|
166
|
+
alias :list_org_hooks :org_hooks
|
167
|
+
|
168
|
+
# Get an org hook
|
169
|
+
#
|
170
|
+
# Requires client authenticated as admin for the org.
|
171
|
+
#
|
172
|
+
# @param org [String] A GitHub organization login.
|
173
|
+
# @param id [Integer] Id of the hook to get.
|
174
|
+
# @return [Sawyer::Resource] Hash representing hook.
|
175
|
+
# @see https://developer.github.com/v3/orgs/hooks/#get-single-hook
|
176
|
+
# @example
|
177
|
+
# @client.org_hook('octokit', 123)
|
178
|
+
def org_hook(org, id, options = {})
|
179
|
+
options = ensure_org_hooks_api_media_type(options)
|
180
|
+
get "orgs/#{org}/hooks/#{id}", options
|
181
|
+
end
|
182
|
+
|
183
|
+
# Create an org hook
|
184
|
+
#
|
185
|
+
# Requires client authenticated as admin for the org.
|
186
|
+
#
|
187
|
+
# @param org [String] A GitHub organization login.
|
188
|
+
# @param config [Hash] A Hash containing key/value pairs to provide
|
189
|
+
# settings for this hook.
|
190
|
+
# @option options [Array<String>] :events ('["push"]') Determines what
|
191
|
+
# events the hook is triggered for.
|
192
|
+
# @option options [Boolean] :active Determines whether the hook is
|
193
|
+
# actually triggered on pushes.
|
194
|
+
# @return [Sawyer::Resource] Hook info for the new hook
|
195
|
+
# @see https://api.github.com/hooks
|
196
|
+
# @see https://developer.github.com/v3/orgs/hooks/#create-a-hook
|
197
|
+
# @example
|
198
|
+
# @client.create_org_hook(
|
199
|
+
# 'octokit',
|
200
|
+
# {
|
201
|
+
# :url => 'http://something.com/webhook',
|
202
|
+
# :content_type => 'json'
|
203
|
+
# },
|
204
|
+
# {
|
205
|
+
# :events => ['push', 'pull_request'],
|
206
|
+
# :active => true
|
207
|
+
# }
|
208
|
+
# )
|
209
|
+
def create_org_hook(org, config, options = {})
|
210
|
+
options = ensure_org_hooks_api_media_type(options)
|
211
|
+
options = { :name => "web", :config => config }.merge(options)
|
212
|
+
post "orgs/#{org}/hooks", options
|
213
|
+
end
|
214
|
+
|
215
|
+
# Update an org hook
|
216
|
+
#
|
217
|
+
# Requires client authenticated as admin for the org.
|
218
|
+
#
|
219
|
+
# @param org [String] A GitHub organization login.
|
220
|
+
# @param id [Integer] Id of the hook to update.
|
221
|
+
# @param config [Hash] A Hash containing key/value pairs to provide
|
222
|
+
# settings for this hook.
|
223
|
+
# @option options [Array<String>] :events ('["push"]') Determines what
|
224
|
+
# events the hook is triggered for.
|
225
|
+
# @option options [Boolean] :active Determines whether the hook is
|
226
|
+
# actually triggered on pushes.
|
227
|
+
# @return [Sawyer::Resource] Hook info for the new hook
|
228
|
+
# @see https://api.github.com/hooks
|
229
|
+
# @see https://developer.github.com/v3/orgs/hooks/#edit-a-hook
|
230
|
+
# @example
|
231
|
+
# @client.edit_org_hook(
|
232
|
+
# 'octokit',
|
233
|
+
# 123,
|
234
|
+
# {
|
235
|
+
# :url => 'http://something.com/webhook',
|
236
|
+
# :content_type => 'json'
|
237
|
+
# },
|
238
|
+
# {
|
239
|
+
# :events => ['push', 'pull_request'],
|
240
|
+
# :active => true
|
241
|
+
# }
|
242
|
+
# )
|
243
|
+
def edit_org_hook(org, id, config, options = {})
|
244
|
+
options = ensure_org_hooks_api_media_type(options)
|
245
|
+
options = { :config => config }.merge(options)
|
246
|
+
patch "orgs/#{org}/hooks/#{id}", options
|
247
|
+
end
|
248
|
+
alias :update_org_hook :edit_org_hook
|
249
|
+
|
250
|
+
# Ping org hook
|
251
|
+
#
|
252
|
+
# Requires client authenticated as admin for the org.
|
253
|
+
#
|
254
|
+
# @param org [String] A GitHub organization login.
|
255
|
+
# @param id [Integer] Id of the hook to update.
|
256
|
+
# @return [Boolean] Success
|
257
|
+
# @see https://developer.github.com/v3/orgs/hooks/#ping-a-hook
|
258
|
+
# @example
|
259
|
+
# @client.ping_org_hook('octokit', 1000000)
|
260
|
+
def ping_org_hook(org, id, options = {})
|
261
|
+
options = ensure_org_hooks_api_media_type(options)
|
262
|
+
boolean_from_response :post, "orgs/#{org}/hooks/#{id}/pings", options
|
263
|
+
end
|
264
|
+
|
265
|
+
# Remove org hook
|
266
|
+
#
|
267
|
+
# Requires client authenticated as admin for the org.
|
268
|
+
#
|
269
|
+
# @param org [String] A GitHub organization login.
|
270
|
+
# @param id [Integer] Id of the hook to update.
|
271
|
+
# @return [Boolean] True if hook removed, false otherwise.
|
272
|
+
# @see https://developer.github.com/v3/orgs/hooks/#delete-a-hook
|
273
|
+
# @example
|
274
|
+
# @client.remove_org_hook('octokit', 1000000)
|
275
|
+
def remove_org_hook(org, id, options = {})
|
276
|
+
options = ensure_org_hooks_api_media_type(options)
|
277
|
+
boolean_from_response :delete, "orgs/#{org}/hooks/#{id}", options
|
278
|
+
end
|
279
|
+
|
280
|
+
private
|
281
|
+
|
282
|
+
def ensure_org_hooks_api_media_type(options = {})
|
283
|
+
if options[:accept].nil?
|
284
|
+
options[:accept] = ORG_HOOKS_PREVIEW_MEDIA_TYPE
|
285
|
+
warn_org_hooks_preview
|
286
|
+
end
|
287
|
+
|
288
|
+
options
|
289
|
+
end
|
290
|
+
|
291
|
+
def warn_org_hooks_preview
|
292
|
+
octokit_warn <<-EOS
|
293
|
+
WARNING: The preview version of the Org Hooks API is not yet suitable for production use.
|
294
|
+
You can avoid this message by supplying an appropriate media type in the 'Accept' request
|
295
|
+
header. See the blog post for details: http://git.io/<LINK>
|
296
|
+
EOS
|
297
|
+
end
|
16
298
|
end
|
17
299
|
end
|
18
300
|
end
|
@@ -481,140 +481,6 @@ module Octokit
|
|
481
481
|
end
|
482
482
|
alias :get_branch :branch
|
483
483
|
|
484
|
-
# List repo hooks
|
485
|
-
#
|
486
|
-
# Requires authenticated client.
|
487
|
-
#
|
488
|
-
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
489
|
-
# @return [Array<Sawyer::Resource>] Array of hashes representing hooks.
|
490
|
-
# @see https://developer.github.com/v3/repos/hooks/#list-hooks
|
491
|
-
# @example
|
492
|
-
# @client.hooks('octokit/octokit.rb')
|
493
|
-
def hooks(repo, options = {})
|
494
|
-
paginate "#{Repository.path repo}/hooks", options
|
495
|
-
end
|
496
|
-
|
497
|
-
# Get single hook
|
498
|
-
#
|
499
|
-
# Requires authenticated client.
|
500
|
-
#
|
501
|
-
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
502
|
-
# @param id [Integer] Id of the hook to get.
|
503
|
-
# @return [Sawyer::Resource] Hash representing hook.
|
504
|
-
# @see https://developer.github.com/v3/repos/hooks/#get-single-hook
|
505
|
-
# @example
|
506
|
-
# @client.hook('octokit/octokit.rb', 100000)
|
507
|
-
def hook(repo, id, options = {})
|
508
|
-
get "#{Repository.path repo}/hooks/#{id}", options
|
509
|
-
end
|
510
|
-
|
511
|
-
# Create a hook
|
512
|
-
#
|
513
|
-
# Requires authenticated client.
|
514
|
-
#
|
515
|
-
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
516
|
-
# @param name [String] The name of the service that is being called. See
|
517
|
-
# {https://api.github.com/hooks Hooks} for the possible names.
|
518
|
-
# @param config [Hash] A Hash containing key/value pairs to provide
|
519
|
-
# settings for this hook. These settings vary between the services and
|
520
|
-
# are defined in the {https://github.com/github/github-services github-services} repo.
|
521
|
-
# @option options [Array<String>] :events ('["push"]') Determines what
|
522
|
-
# events the hook is triggered for.
|
523
|
-
# @option options [Boolean] :active Determines whether the hook is
|
524
|
-
# actually triggered on pushes.
|
525
|
-
# @return [Sawyer::Resource] Hook info for the new hook
|
526
|
-
# @see https://api.github.com/hooks
|
527
|
-
# @see https://github.com/github/github-services
|
528
|
-
# @see https://developer.github.com/v3/repos/hooks/#create-a-hook
|
529
|
-
# @example
|
530
|
-
# @client.create_hook(
|
531
|
-
# 'octokit/octokit.rb',
|
532
|
-
# 'web',
|
533
|
-
# {
|
534
|
-
# :url => 'http://something.com/webhook',
|
535
|
-
# :content_type => 'json'
|
536
|
-
# },
|
537
|
-
# {
|
538
|
-
# :events => ['push', 'pull_request'],
|
539
|
-
# :active => true
|
540
|
-
# }
|
541
|
-
# )
|
542
|
-
def create_hook(repo, name, config, options = {})
|
543
|
-
options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
|
544
|
-
post "#{Repository.path repo}/hooks", options
|
545
|
-
end
|
546
|
-
|
547
|
-
# Edit a hook
|
548
|
-
#
|
549
|
-
# Requires authenticated client.
|
550
|
-
#
|
551
|
-
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
552
|
-
# @param id [Integer] Id of the hook being updated.
|
553
|
-
# @param name [String] The name of the service that is being called. See
|
554
|
-
# {https://api.github.com/hooks Hooks} for the possible names.
|
555
|
-
# @param config [Hash] A Hash containing key/value pairs to provide
|
556
|
-
# settings for this hook. These settings vary between the services and
|
557
|
-
# are defined in the {https://github.com/github/github-services github-services} repo.
|
558
|
-
# @option options [Array<String>] :events ('["push"]') Determines what
|
559
|
-
# events the hook is triggered for.
|
560
|
-
# @option options [Array<String>] :add_events Determines a list of events
|
561
|
-
# to be added to the list of events that the Hook triggers for.
|
562
|
-
# @option options [Array<String>] :remove_events Determines a list of events
|
563
|
-
# to be removed from the list of events that the Hook triggers for.
|
564
|
-
# @option options [Boolean] :active Determines whether the hook is
|
565
|
-
# actually triggered on pushes.
|
566
|
-
# @return [Sawyer::Resource] Hook info for the updated hook
|
567
|
-
# @see https://api.github.com/hooks
|
568
|
-
# @see https://github.com/github/github-services
|
569
|
-
# @see https://developer.github.com/v3/repos/hooks/#edit-a-hook
|
570
|
-
# @example
|
571
|
-
# @client.edit_hook(
|
572
|
-
# 'octokit/octokit.rb',
|
573
|
-
# 100000,
|
574
|
-
# 'web',
|
575
|
-
# {
|
576
|
-
# :url => 'http://something.com/webhook',
|
577
|
-
# :content_type => 'json'
|
578
|
-
# },
|
579
|
-
# {
|
580
|
-
# :add_events => ['status'],
|
581
|
-
# :remove_events => ['pull_request'],
|
582
|
-
# :active => true
|
583
|
-
# }
|
584
|
-
# )
|
585
|
-
def edit_hook(repo, id, name, config, options = {})
|
586
|
-
options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options)
|
587
|
-
patch "#{Repository.path repo}/hooks/#{id}", options
|
588
|
-
end
|
589
|
-
|
590
|
-
# Delete hook
|
591
|
-
#
|
592
|
-
# Requires authenticated client.
|
593
|
-
#
|
594
|
-
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
595
|
-
# @param id [Integer] Id of the hook to remove.
|
596
|
-
# @return [Boolean] True if hook removed, false otherwise.
|
597
|
-
# @see https://developer.github.com/v3/repos/hooks/#delete-a-hook
|
598
|
-
# @example
|
599
|
-
# @client.remove_hook('octokit/octokit.rb', 1000000)
|
600
|
-
def remove_hook(repo, id, options = {})
|
601
|
-
boolean_from_response :delete, "#{Repository.path repo}/hooks/#{id}", options
|
602
|
-
end
|
603
|
-
|
604
|
-
# Test hook
|
605
|
-
#
|
606
|
-
# Requires authenticated client.
|
607
|
-
#
|
608
|
-
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
609
|
-
# @param id [Integer] Id of the hook to test.
|
610
|
-
# @return [Boolean] Success
|
611
|
-
# @see https://developer.github.com/v3/repos/hooks/#test-a-push-hook
|
612
|
-
# @example
|
613
|
-
# @client.test_hook('octokit/octokit.rb', 1000000)
|
614
|
-
def test_hook(repo, id, options = {})
|
615
|
-
boolean_from_response :post, "#{Repository.path repo}/hooks/#{id}/tests", options
|
616
|
-
end
|
617
|
-
|
618
484
|
# List users available for assigning to issues.
|
619
485
|
#
|
620
486
|
# Requires authenticated client for private repos.
|
data/lib/octokit/version.rb
CHANGED