-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
organizations.rb
434 lines (413 loc) · 16.9 KB
/
organizations.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
module Octokit
class Client
module Organizations
# Get an organization
#
# @param org [String] Organization GitHub username.
# @return [Hashie::Mash] Hash representing GitHub organization.
# @see http://developer.github.com/v3/orgs/#get-an-organization
# @example
# Octokit.organization('github')
# @example
# Octokit.org('github')
def organization(org, options={})
get("orgs/#{org}", options)
end
alias :org :organization
# Update an organization.
#
# Requires authenticated client with proper organization permissions.
#
# @param org [String] Organization GitHub username.
# @param values [Hash] The updated organization attributes.
# @option values [String] :billing_email Billing email address. This address is not publicized.
# @option values [String] :company Company name.
# @option values [String] :email Publicly visible email address.
# @option values [String] :location Location of organization.
# @option values [String] :name GitHub username for organization.
# @return [Hashie::Mash] Hash representing GitHub organization.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/#edit-an-organization
# @example
# @client.update_organization('github', {
# :billing_email => 'support@github.com',
# :company => 'GitHub',
# :email => 'support@github.com',
# :location => 'San Francisco',
# :name => 'github'
# })
# @example
# @client.update_org('github', {:company => 'Unicorns, Inc.'})
def update_organization(org, values, options={})
patch("orgs/#{org}", options.merge({:organization => values}))
end
alias :update_org :update_organization
# Get organizations for a user.
#
# Nonauthenticated calls to this method will return organizations that
# the user is a public member.
#
# Use an authenicated client to get both public and private organizations
# for a user.
#
# Calling this method on a `@client` will return that users organizations.
# Private organizations are included only if the `@client` is authenticated.
#
# @param user [String] Username of the user to get list of organizations.
# @return [Array<Hashie::Mash>] Array of hashes representing organizations.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/#list-user-organizations
# @example
# Octokit.organizations('pengwynn')
# @example
# @client.organizations('pengwynn')
# @example
# Octokit.orgs('pengwynn')
# @example
# Octokit.list_organizations('pengwynn')
# @example
# Octokit.list_orgs('pengwynn')
# @example
# @client.organizations
def organizations(user=nil, options={})
if user
get("users/#{user}/orgs", options)
else
get("user/orgs", options)
end
end
alias :list_organizations :organizations
alias :list_orgs :organizations
alias :orgs :organizations
# List organization repositories
#
# Public repositories are available without authentication. Private repos
# require authenticated organization member.
#
# @param org [String] Organization handle for which to list repos
# @option options [String] :type ('all') Filter by repository type.
# `all`, `public`, `member` or `private`.
#
# @return [Array<Hashie::Mash>] List of repositories
# @see Octokit::Client
# @see http://developer.github.com/v3/repos/#list-organization-repositories
# @example
# Octokit.organization_repositories('github')
# @example
# Octokit.org_repositories('github')
# @example
# Octokit.org_repos('github')
# @example
# @client.org_repos('github', {:type => 'private'})
def organization_repositories(org, options={})
get("orgs/#{org}/repos", options)
end
alias :org_repositories :organization_repositories
alias :org_repos :organization_repositories
# Get organization members
#
# Public members of the organization are returned by default. An
# authenticated client that is a member of the GitHub organization
# is required to get private members.
#
# @param org [String] Organization GitHub username.
# @return [Array<Hashie::Mash>] Array of hashes representing users.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/members/#list-members
# @example
# Octokit.organization_members('github')
# @example
# @client.organization_members('github')
# @example
# Octokit.org_members('github')
def organization_members(org, options={})
get("orgs/#{org}/members", options)
end
alias :org_members :organization_members
# Check if a user is a member of an organization.
#
# Use this to check if another user is a member of an organization that
# you are a member. If you are not in the organization you are checking,
# use .organization_public_member? instead.
#
# @param org [String] Organization GitHub username.
# @param user [String] GitHub username of the user to check.
#
# @return [Boolean] Is a member?
#
# @see http://developer.github.com/v3/orgs/members/#check-membership
#
# @example Check if a user is in your organization
# @client.organization_member?('your_organization', 'pengwynn')
# => false
def organization_member?(org, user, options={})
request(:get, "orgs/#{org}/members/#{user}", options).status == 204
rescue Octokit::NotFound
false
end
alias :org_member? :organization_member?
# Check if a user is a public member of an organization.
#
# If you are checking for membership of a user of an organization that
# you are in, use .organization_member? instead.
#
# @param org [String] Organization GitHub username.
# @param user [String] GitHub username of the user to check.
#
# @return [Boolean] Is a public member?
#
# @see http://developer.github.com/v3/orgs/members/#check-public-membership
#
# @example Check if a user is a hubbernaut
# @client.organization_public_member?('github', 'pengwynn')
# => true
def organization_public_member?(org, user, options={})
request(:get, "orgs/#{org}/public_members/#{user}", options).status == 204
rescue Octokit::NotFound
false
end
alias :org_public_member? :organization_public_member?
# List teams
#
# Requires authenticated organization member.
#
# @param org [String] Organization GitHub username.
# @return [Array<Hashie::Mash>] Array of hashes representing teams.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/teams/#list-teams
# @example
# @client.organization_teams('github')
# @example
# @client.org_teams('github')
def organization_teams(org, options={})
get("orgs/#{org}/teams", options)
end
alias :org_teams :organization_teams
# Create team
#
# Requires authenticated organization owner.
#
# @param org [String] Organization GitHub username.
# @option options [String] :name Team name.
# @option options [Array<String>] :repo_names Repositories for the team.
# @option options [String, optional] :permission ('pull') Permissions the
# team has for team repositories.
#
# `pull` - team members can pull, but not push to or administer these repositories.
# `push` - team members can pull and push, but not administer these repositories.
# `admin` - team members can pull, push and administer these repositories.
# @return [Hashie::Mash] Hash representing new team.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/teams/#create-team
# @example
# @client.create_team('github', {
# :name => 'Designers',
# :repo_names => ['dotcom', 'developer.github.com'],
# :permission => 'push'
# })
def create_team(org, options={})
post("orgs/#{org}/teams", options)
end
# Get team
#
# Requires authenticated organization member.
#
# @param team_id [Integer] Team id.
# @return [Hashie::Mash] Hash representing team.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/teams/#get-team
# @example
# @client.team(100000)
def team(team_id, options={})
get("teams/#{team_id}", options)
end
# Update team
#
# Requires authenticated organization owner.
#
# @param team_id [Integer] Team id.
# @option options [String] :name Team name.
# @option options [String] :permission Permissions the team has for team repositories.
#
# `pull` - team members can pull, but not push to or administer these repositories.
# `push` - team members can pull and push, but not administer these repositories.
# `admin` - team members can pull, push and administer these repositories.
# @return [Hashie::Mash] Hash representing updated team.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/teams/#edit-team
# @example
# @client.update_team(100000, {
# :name => 'Front-end Designers',
# :permission => 'push'
# })
def update_team(team_id, options={})
patch("teams/#{team_id}", options)
end
# Delete team
#
# Requires authenticated organization owner.
#
# @param team_id [Integer] Team id.
# @return [Boolean] True if deletion successful, false otherwise.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/teams/#delete-team
# @example
# @client.delete_team(100000)
def delete_team(team_id, options={})
request(:delete, "teams/#{team_id}", options).status == 204
end
# List team members
#
# Requires authenticated organization member.
#
# @param team_id [Integer] Team id.
# @return [Array<Hashie::Mash>] Array of hashes representing users.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/teams/#list-team-members
# @example
# @client.team_members(100000)
def team_members(team_id, options={})
get("teams/#{team_id}/members", options)
end
# Add team member
#
# Requires authenticated organization owner or member with team
# `admin` permission.
#
# @param team_id [Integer] Team id.
# @param user [String] GitHub username of new team member.
# @return [Boolean] True on successful addition, false otherwise.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/teams/#add-team-member
# @example
# @client.add_team_member(100000, 'pengwynn')
def add_team_member(team_id, user, options={})
# There's a bug in this API call. The docs say to leave the body blank,
# but it fails if the body is both blank and the content-length header
# is not 0.
request(:put, "teams/#{team_id}/members/#{user}", options.merge({:name => user})).status == 204
end
# Remove team member
#
# Requires authenticated organization owner or member with team
# `admin` permission.
#
# @param team_id [Integer] Team id.
# @param user [String] GitHub username of the user to boot.
# @return [Boolean] True if user removed, false otherwise.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/teams/#remove-team-member
# @example
# @client.remove_team_member(100000, 'pengwynn')
def remove_team_member(team_id, user, options={})
request(:delete, "teams/#{team_id}/members/#{user}", options).status == 204
end
# List team repositories
#
# Requires authenticated organization member.
#
# @param team_id [Integer] Team id.
# @return [Array<Hashie::Mash>] Array of hashes representing repositories.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/teams/#list-team-repos
# @example
# @client.team_repositories(100000)
# @example
# @client.team_repos(100000)
def team_repositories(team_id, options={})
get("teams/#{team_id}/repos", options)
end
alias :team_repos :team_repositories
# Add team repository
#
# Requires authenticated user to be an owner of the organization that the
# team is associated with. Also, the repo must be owned by the
# organization, or a direct form of a repo owned by the organization.
#
# @param team_id [Integer] Team id.
# @param repo [String, Hash, Repository] A GitHub repository.
# @return [Boolean] True if successful, false otherwise.
# @see Octokit::Client
# @see Octokit::Repository
# @see http://developer.github.com/v3/orgs/teams/#add-team-repo
# @example
# @client.add_team_repository(100000, 'github/developer.github.com')
# @example
# @client.add_team_repo(100000, 'github/developer.github.com')
def add_team_repository(team_id, repo, options={})
request(:put, "teams/#{team_id}/repos/#{Repository.new(repo)}", options.merge(:name => Repository.new(repo))).status == 204
end
alias :add_team_repo :add_team_repository
# Remove team repository
#
# Removes repository from team. Does not delete the repository.
#
# Requires authenticated organization owner.
#
# @param team_id [Integer] Team id.
# @param repo [String, Hash, Repository] A GitHub repository.
# @return [Boolean] Return true if repo removed from team, false otherwise.
# @see Octokit::Client
# @see Octokit::Repository
# @see http://developer.github.com/v3/orgs/teams/#remove-team-repo
# @example
# @client.remove_team_repository(100000, 'github/developer.github.com')
# @example
# @client.remove_team_repo(100000, 'github/developer.github.com')
def remove_team_repository(team_id, repo, options={})
request(:delete, "teams/#{team_id}/repos/#{Repository.new(repo)}").status == 204
end
alias :remove_team_repo :remove_team_repository
# Remove organization member
#
# Requires authenticated organization owner or member with team `admin` access.
#
# @param org [String] Organization GitHub username.
# @param user [String] GitHub username of user to remove.
# @return [Boolean] True if removal is successful, false otherwise.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/teams/#remove-team-member
# @example
# @client.remove_organization_member('github', 'pengwynn')
# @example
# @client.remove_org_member('github', 'pengwynn')
def remove_organization_member(org, user, options={})
# this is a synonym for: for team in org.teams: remove_team_member(team.id, user)
# provided in the GH API v3
request(:delete, "orgs/#{org}/members/#{user}", options).status == 204
end
alias :remove_org_member :remove_organization_member
# Publicize a user's membership of an organization
#
# Requires authenticated organization owner.
#
# @param org [String] Organization GitHub username.
# @param user [String] GitHub username of user to publicize.
# @return [Boolean] True if publicization successful, false otherwise.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/members/#publicize-a-users-membership
# @example
# @client.publicize_membership('github', 'pengwynn')
def publicize_membership(org, user, options={})
request(:put, "orgs/#{org}/public_members/#{user}", options).status == 204
end
# Conceal a user's membership of an organization.
#
# Requires authenticated organization owner.
#
# @param org [String] Organization GitHub username.
# @param user [String] GitHub username of user to unpublicize.
# @return [Boolean] True of unpublicization successful, false otherwise.
# @see Octokit::Client
# @see http://developer.github.com/v3/orgs/members/#conceal-a-users-membership
# @example
# @client.unpublicize_membership('github', 'pengwynn')
# @example
# @client.conceal_membership('github', 'pengwynn')
def unpublicize_membership(org, user, options={})
request(:delete, "orgs/#{org}/public_members/#{user}", options).status == 204
end
alias :conceal_membership :unpublicize_membership
end
end
end