octodoggy 4.6.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.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/CONTRIBUTING.md +22 -0
  4. data/LICENSE.md +20 -0
  5. data/README.md +714 -0
  6. data/Rakefile +22 -0
  7. data/lib/ext/sawyer/relation.rb +10 -0
  8. data/lib/octokit.rb +59 -0
  9. data/lib/octokit/arguments.rb +14 -0
  10. data/lib/octokit/authentication.rb +82 -0
  11. data/lib/octokit/client.rb +238 -0
  12. data/lib/octokit/client/authorizations.rb +244 -0
  13. data/lib/octokit/client/commit_comments.rb +95 -0
  14. data/lib/octokit/client/commits.rb +239 -0
  15. data/lib/octokit/client/contents.rb +162 -0
  16. data/lib/octokit/client/deployments.rb +62 -0
  17. data/lib/octokit/client/downloads.rb +50 -0
  18. data/lib/octokit/client/emojis.rb +18 -0
  19. data/lib/octokit/client/events.rb +151 -0
  20. data/lib/octokit/client/feeds.rb +33 -0
  21. data/lib/octokit/client/gists.rb +233 -0
  22. data/lib/octokit/client/gitignore.rb +43 -0
  23. data/lib/octokit/client/hooks.rb +297 -0
  24. data/lib/octokit/client/integrations.rb +77 -0
  25. data/lib/octokit/client/issues.rb +321 -0
  26. data/lib/octokit/client/labels.rb +156 -0
  27. data/lib/octokit/client/legacy_search.rb +42 -0
  28. data/lib/octokit/client/licenses.rb +45 -0
  29. data/lib/octokit/client/markdown.rb +27 -0
  30. data/lib/octokit/client/meta.rb +21 -0
  31. data/lib/octokit/client/milestones.rb +87 -0
  32. data/lib/octokit/client/notifications.rb +171 -0
  33. data/lib/octokit/client/objects.rb +141 -0
  34. data/lib/octokit/client/organizations.rb +768 -0
  35. data/lib/octokit/client/pages.rb +63 -0
  36. data/lib/octokit/client/projects.rb +314 -0
  37. data/lib/octokit/client/pub_sub_hubbub.rb +111 -0
  38. data/lib/octokit/client/pull_requests.rb +301 -0
  39. data/lib/octokit/client/rate_limit.rb +54 -0
  40. data/lib/octokit/client/reactions.rb +158 -0
  41. data/lib/octokit/client/refs.rb +118 -0
  42. data/lib/octokit/client/releases.rb +163 -0
  43. data/lib/octokit/client/repositories.rb +654 -0
  44. data/lib/octokit/client/repository_invitations.rb +103 -0
  45. data/lib/octokit/client/reviews.rb +174 -0
  46. data/lib/octokit/client/say.rb +19 -0
  47. data/lib/octokit/client/search.rb +76 -0
  48. data/lib/octokit/client/service_status.rb +38 -0
  49. data/lib/octokit/client/source_import.rb +161 -0
  50. data/lib/octokit/client/stats.rb +105 -0
  51. data/lib/octokit/client/statuses.rb +47 -0
  52. data/lib/octokit/client/traffic.rb +69 -0
  53. data/lib/octokit/client/users.rb +354 -0
  54. data/lib/octokit/configurable.rb +147 -0
  55. data/lib/octokit/connection.rb +199 -0
  56. data/lib/octokit/default.rb +166 -0
  57. data/lib/octokit/enterprise_admin_client.rb +40 -0
  58. data/lib/octokit/enterprise_admin_client/admin_stats.rb +120 -0
  59. data/lib/octokit/enterprise_admin_client/license.rb +18 -0
  60. data/lib/octokit/enterprise_admin_client/orgs.rb +27 -0
  61. data/lib/octokit/enterprise_admin_client/search_indexing.rb +83 -0
  62. data/lib/octokit/enterprise_admin_client/users.rb +128 -0
  63. data/lib/octokit/enterprise_management_console_client.rb +50 -0
  64. data/lib/octokit/enterprise_management_console_client/management_console.rb +176 -0
  65. data/lib/octokit/error.rb +286 -0
  66. data/lib/octokit/gist.rb +36 -0
  67. data/lib/octokit/middleware/follow_redirects.rb +131 -0
  68. data/lib/octokit/organization.rb +17 -0
  69. data/lib/octokit/preview.rb +38 -0
  70. data/lib/octokit/rate_limit.rb +33 -0
  71. data/lib/octokit/repo_arguments.rb +19 -0
  72. data/lib/octokit/repository.rb +93 -0
  73. data/lib/octokit/response/feed_parser.rb +21 -0
  74. data/lib/octokit/response/raise_error.rb +21 -0
  75. data/lib/octokit/user.rb +19 -0
  76. data/lib/octokit/version.rb +17 -0
  77. data/lib/octokit/warnable.rb +17 -0
  78. data/octokit.gemspec +22 -0
  79. metadata +160 -0
@@ -0,0 +1,141 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Git Data API
5
+ #
6
+ # @see https://developer.github.com/v3/git/
7
+ module Objects
8
+
9
+ # Get a single tree, fetching information about its root-level objects
10
+ #
11
+ # Pass <tt>:recursive => true</tt> in <tt>options</tt> to fetch information about all of the tree's objects, including those in subdirectories.
12
+ #
13
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
14
+ # @param tree_sha [String] The SHA of the tree to fetch
15
+ # @return [Sawyer::Resource] A hash representing the fetched tree
16
+ # @see https://developer.github.com/v3/git/trees/#get-a-tree
17
+ # @see https://developer.github.com/v3/git/trees/#get-a-tree-recursively
18
+ # @example Fetch a tree and inspect the path of one of its files
19
+ # tree = Octokit.tree("octocat/Hello-World", "9fb037999f264ba9a7fc6274d15fa3ae2ab98312")
20
+ # tree.tree.first.path # => "file.rb"
21
+ # @example Fetch a tree recursively
22
+ # tree = Octokit.tree("octocat/Hello-World", "fc6274d15fa3ae2ab983129fb037999f264ba9a7", :recursive => true)
23
+ # tree.tree.first.path # => "subdir/file.txt"
24
+ def tree(repo, tree_sha, options = {})
25
+ get "#{Repository.path repo}/git/trees/#{tree_sha}", options
26
+ end
27
+
28
+ # Create a tree
29
+ #
30
+ # Pass <tt>:base_tree => "827efc6..."</tt> in <tt>options</tt> to update an existing tree with new data.
31
+ #
32
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
33
+ # @param tree [Array] An array of hashes representing a tree structure
34
+ # @return [Sawyer::Resource] A hash representing the new tree
35
+ # @see https://developer.github.com/v3/git/trees/#create-a-tree
36
+ # @example Create a tree containing one file
37
+ # tree = Octokit.create_tree("octocat/Hello-World", [ { :path => "file.rb", :mode => "100644", :type => "blob", :sha => "44b4fc6d56897b048c772eb4087f854f46256132" } ])
38
+ # tree.sha # => "cd8274d15fa3ae2ab983129fb037999f264ba9a7"
39
+ # tree.tree.first.path # => "file.rb"
40
+ def create_tree(repo, tree, options = {})
41
+ parameters = { :tree => tree }
42
+ post "#{Repository.path repo}/git/trees", options.merge(parameters)
43
+ end
44
+
45
+ # Get a single blob, fetching its content and encoding
46
+ #
47
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
48
+ # @param blob_sha [String] The SHA of the blob to fetch
49
+ # @return [Sawyer::Resource] A hash representing the fetched blob
50
+ # @see https://developer.github.com/v3/git/blobs/#get-a-blob
51
+ # @example Fetch a blob and inspect its contents
52
+ # blob = Octokit.blob("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132")
53
+ # blob.encoding # => "utf-8"
54
+ # blob.content # => "Foo bar baz"
55
+ # @example Fetch a base64-encoded blob and inspect its contents
56
+ # require "base64"
57
+ # blob = Octokit.blob("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132")
58
+ # blob.encoding # => "base64"
59
+ # blob.content # => "Rm9vIGJhciBiYXo="
60
+ # Base64.decode64(blob.content) # => "Foo bar baz"
61
+ def blob(repo, blob_sha, options = {})
62
+ get "#{Repository.path repo}/git/blobs/#{blob_sha}", options
63
+ end
64
+
65
+ # Create a blob
66
+ #
67
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
68
+ # @param content [String] Content of the blob
69
+ # @param encoding [String] The content's encoding. <tt>utf-8</tt> and <tt>base64</tt> are accepted. If your data cannot be losslessly sent as a UTF-8 string, you can base64 encode it
70
+ # @return [String] The new blob's SHA, e.g. <tt>827efc6d56897b048c772eb4087f854f46256132</tt>
71
+ # @see https://developer.github.com/v3/git/blobs/#create-a-blob
72
+ # @example Create a blob containing <tt>foo bar baz</tt>
73
+ # Octokit.create_blob("octocat/Hello-World", "foo bar baz")
74
+ # @example Create a blob containing <tt>foo bar baz</tt>, encoded using base64
75
+ # require "base64"
76
+ # Octokit.create_blob("octocat/Hello-World", Base64.encode64("foo bar baz"), "base64")
77
+ def create_blob(repo, content, encoding="utf-8", options = {})
78
+ parameters = {
79
+ :content => content,
80
+ :encoding => encoding
81
+ }
82
+ blob = post "#{Repository.path repo}/git/blobs", options.merge(parameters)
83
+
84
+ blob.sha
85
+ end
86
+
87
+ # Get a tag
88
+ #
89
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
90
+ # @param tag_sha [String] The SHA of the tag to fetch.
91
+ # @return [Sawyer::Resource] Hash representing the tag.
92
+ # @see https://developer.github.com/v3/git/tags/#get-a-tag
93
+ # @example Fetch a tag
94
+ # Octokit.tag('octokit/octokit.rb', '23aad20633f4d2981b1c7209a800db3014774e96')
95
+ def tag(repo, tag_sha, options = {})
96
+ get "#{Repository.path repo}/git/tags/#{tag_sha}", options
97
+ end
98
+
99
+ # Create a tag
100
+ #
101
+ # Requires authenticated client.
102
+ #
103
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository.
104
+ # @param tag [String] Tag string.
105
+ # @param message [String] Tag message.
106
+ # @param object_sha [String] SHA of the git object this is tagging.
107
+ # @param type [String] Type of the object we're tagging. Normally this is
108
+ # a `commit` but it can also be a `tree` or a `blob`.
109
+ # @param tagger_name [String] Name of the author of the tag.
110
+ # @param tagger_email [String] Email of the author of the tag.
111
+ # @param tagger_date [string] Timestamp of when this object was tagged.
112
+ # @return [Sawyer::Resource] Hash representing new tag.
113
+ # @see https://developer.github.com/v3/git/tags/#create-a-tag-object
114
+ # @example
115
+ # @client.create_tag(
116
+ # "octokit/octokit.rb",
117
+ # "v9000.0.0",
118
+ # "Version 9000\n",
119
+ # "f4cdf6eb734f32343ce3f27670c17b35f54fd82e",
120
+ # "commit",
121
+ # "Wynn Netherland",
122
+ # "wynn.netherland@gmail.com",
123
+ # "2012-06-03T17:03:11-07:00"
124
+ # )
125
+ def create_tag(repo, tag, message, object_sha, type, tagger_name, tagger_email, tagger_date, options = {})
126
+ options.merge!(
127
+ :tag => tag,
128
+ :message => message,
129
+ :object => object_sha,
130
+ :type => type,
131
+ :tagger => {
132
+ :name => tagger_name,
133
+ :email => tagger_email,
134
+ :date => tagger_date
135
+ }
136
+ )
137
+ post "#{Repository.path repo}/git/tags", options
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,768 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Organizations API
5
+ #
6
+ # @see https://developer.github.com/v3/orgs/
7
+ module Organizations
8
+
9
+ # Get an organization
10
+ #
11
+ # @param org [String, Integer] Organization GitHub login or id.
12
+ # @return [Sawyer::Resource] Hash representing GitHub organization.
13
+ # @see https://developer.github.com/v3/orgs/#get-an-organization
14
+ # @example
15
+ # Octokit.organization('github')
16
+ # @example
17
+ # Octokit.org('github')
18
+ def organization(org, options = {})
19
+ get Organization.path(org), options
20
+ end
21
+ alias :org :organization
22
+
23
+ # Update an organization.
24
+ #
25
+ # Requires authenticated client with proper organization permissions.
26
+ #
27
+ # @param org [String, Integer] Organization GitHub login or id.
28
+ # @param values [Hash] The updated organization attributes.
29
+ # @option values [String] :billing_email Billing email address. This address is not publicized.
30
+ # @option values [String] :company Company name.
31
+ # @option values [String] :email Publicly visible email address.
32
+ # @option values [String] :location Location of organization.
33
+ # @option values [String] :name GitHub username for organization.
34
+ # @option values [String] :default_repository_permission The default permission members have on organization repositories.
35
+ # @option values [Boolean] :members_can_create_repositories Set true to allow members to create repositories on the organization.
36
+ # @return [Sawyer::Resource] Hash representing GitHub organization.
37
+ # @see https://developer.github.com/v3/orgs/#edit-an-organization
38
+ # @example
39
+ # @client.update_organization('github', {
40
+ # :billing_email => 'support@github.com',
41
+ # :company => 'GitHub',
42
+ # :email => 'support@github.com',
43
+ # :location => 'San Francisco',
44
+ # :name => 'github'
45
+ # })
46
+ # @example
47
+ # @client.update_org('github', {:company => 'Unicorns, Inc.'})
48
+ def update_organization(org, values, options = {})
49
+ patch Organization.path(org), options.merge(values)
50
+ end
51
+ alias :update_org :update_organization
52
+
53
+ # Get organizations for a user.
54
+ #
55
+ # Nonauthenticated calls to this method will return organizations that
56
+ # the user is a public member.
57
+ #
58
+ # Use an authenicated client to get both public and private organizations
59
+ # for a user.
60
+ #
61
+ # Calling this method on a `@client` will return that users organizations.
62
+ # Private organizations are included only if the `@client` is authenticated.
63
+ #
64
+ # @param user [Integer, String] GitHub user login or id of the user to get
65
+ # list of organizations.
66
+ # @return [Array<Sawyer::Resource>] Array of hashes representing organizations.
67
+ # @see https://developer.github.com/v3/orgs/#list-your-organizations
68
+ # @see https://developer.github.com/v3/orgs/#list-user-organizations
69
+ # @example
70
+ # Octokit.organizations('pengwynn')
71
+ # @example
72
+ # @client.organizations('pengwynn')
73
+ # @example
74
+ # Octokit.orgs('pengwynn')
75
+ # @example
76
+ # Octokit.list_organizations('pengwynn')
77
+ # @example
78
+ # Octokit.list_orgs('pengwynn')
79
+ # @example
80
+ # @client.organizations
81
+ def organizations(user=nil, options = {})
82
+ paginate "#{User.path user}/orgs", options
83
+ end
84
+ alias :list_organizations :organizations
85
+ alias :list_orgs :organizations
86
+ alias :orgs :organizations
87
+
88
+ # List all GitHub organizations
89
+ #
90
+ # This provides a list of every organization, in the order that they
91
+ # were created.
92
+ #
93
+ # @param options [Hash] Optional options.
94
+ # @option options [Integer] :since The integer ID of the last
95
+ # Organization that you’ve seen.
96
+ #
97
+ # @see https://developer.github.com/v3/orgs/#list-all-organizations
98
+ #
99
+ # @return [Array<Sawyer::Resource>] List of GitHub organizations.
100
+ def all_organizations(options = {})
101
+ paginate "organizations", options
102
+ end
103
+ alias :all_orgs :all_organizations
104
+
105
+ # List organization repositories
106
+ #
107
+ # Public repositories are available without authentication. Private repos
108
+ # require authenticated organization member.
109
+ #
110
+ # @param org [String, Integer] Organization GitHub login or id for which
111
+ # to list repos.
112
+ # @option options [String] :type ('all') Filter by repository type.
113
+ # `all`, `public`, `member`, `sources`, `forks`, or `private`.
114
+ #
115
+ # @return [Array<Sawyer::Resource>] List of repositories
116
+ # @see https://developer.github.com/v3/repos/#list-organization-repositories
117
+ # @example
118
+ # Octokit.organization_repositories('github')
119
+ # @example
120
+ # Octokit.org_repositories('github')
121
+ # @example
122
+ # Octokit.org_repos('github')
123
+ # @example
124
+ # @client.org_repos('github', {:type => 'private'})
125
+ def organization_repositories(org, options = {})
126
+ paginate "#{Organization.path org}/repos", options
127
+ end
128
+ alias :org_repositories :organization_repositories
129
+ alias :org_repos :organization_repositories
130
+
131
+ # Get organization members
132
+ #
133
+ # Public members of the organization are returned by default. An
134
+ # authenticated client that is a member of the GitHub organization
135
+ # is required to get private members.
136
+ #
137
+ # @param org [String, Integer] Organization GitHub login or id.
138
+ # @return [Array<Sawyer::Resource>] Array of hashes representing users.
139
+ # @see https://developer.github.com/v3/orgs/members/#members-list
140
+ # @example
141
+ # Octokit.organization_members('github')
142
+ # @example
143
+ # Octokit.org_members('github')
144
+ def organization_members(org, options = {})
145
+ path = "public_" if options.delete(:public)
146
+ paginate "#{Organization.path org}/#{path}members", options
147
+ end
148
+ alias :org_members :organization_members
149
+
150
+ # Get organization public members
151
+ #
152
+ # Lists the public members of an organization
153
+ #
154
+ # @param org [String] Organization GitHub username.
155
+ # @return [Array<Sawyer::Resource>] Array of hashes representing users.
156
+ # @see https://developer.github.com/v3/orgs/members/#public-members-list
157
+ # @example
158
+ # Octokit.organization_public_members('github')
159
+ # @example
160
+ # Octokit.org_public_members('github')
161
+ def organization_public_members(org, options = {})
162
+ organization_members org, options.merge(:public => true)
163
+ end
164
+ alias :org_public_members :organization_public_members
165
+
166
+ # Check if a user is a member of an organization.
167
+ #
168
+ # Use this to check if another user is a member of an organization that
169
+ # you are a member. If you are not in the organization you are checking,
170
+ # use .organization_public_member? instead.
171
+ #
172
+ # @param org [String, Integer] Organization GitHub login or id.
173
+ # @param user [String] GitHub username of the user to check.
174
+ #
175
+ # @return [Boolean] Is a member?
176
+ #
177
+ # @see https://developer.github.com/v3/orgs/members/#check-membership
178
+ #
179
+ # @example Check if a user is in your organization
180
+ # @client.organization_member?('your_organization', 'pengwynn')
181
+ # => false
182
+ def organization_member?(org, user, options = {})
183
+ result = boolean_from_response(:get, "#{Organization.path org}/members/#{user}", options)
184
+ if !result && last_response && last_response.status == 302
185
+ boolean_from_response :get, last_response.headers['Location']
186
+ else
187
+ result
188
+ end
189
+ end
190
+ alias :org_member? :organization_member?
191
+
192
+ # Check if a user is a public member of an organization.
193
+ #
194
+ # If you are checking for membership of a user of an organization that
195
+ # you are in, use .organization_member? instead.
196
+ #
197
+ # @param org [String, Integer] Organization GitHub login or id.
198
+ # @param user [String] GitHub username of the user to check.
199
+ #
200
+ # @return [Boolean] Is a public member?
201
+ #
202
+ # @see https://developer.github.com/v3/orgs/members/#check-public-membership
203
+ #
204
+ # @example Check if a user is a hubbernaut
205
+ # @client.organization_public_member?('github', 'pengwynn')
206
+ # => true
207
+ def organization_public_member?(org, user, options = {})
208
+ boolean_from_response :get, "#{Organization.path org}/public_members/#{user}", options
209
+ end
210
+ alias :org_public_member? :organization_public_member?
211
+
212
+ # List pending organization invitations
213
+ #
214
+ # Requires authenticated organization member.
215
+ #
216
+ # @param org [String, Integer] Organization GitHub login or id.
217
+ # @return [Array<Sawyer::Resource>] Array of hashes representing invitations.
218
+ # @see https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations
219
+ #
220
+ # @example
221
+ # @client.organization_invitations('github')
222
+ def organization_invitations(org, options = {})
223
+ options = ensure_api_media_type(:org_memberships, options)
224
+ get "#{Organization.path org}/invitations", options
225
+ end
226
+ alias :org_invitations :organization_invitations
227
+
228
+ # List outside collaborators for an organization
229
+ #
230
+ # Requires authenticated organization members.
231
+ #
232
+ # @param org [String, Integer] Organization GitHub login or id.
233
+ # @return [Array<Sawyer::Resource>] Array of hashes representing users.
234
+ # @see https://developer.github.com/v3/orgs/outside-collaborators/#list-outside-collaborators
235
+ #
236
+ # @example
237
+ # @client.outside_collaborators('github')
238
+ def outside_collaborators(org, options={})
239
+ options = ensure_api_media_type(:org_memberships, options)
240
+ get "#{Organization.path org}/outside_collaborators", options
241
+ end
242
+
243
+ # Remove outside collaborator from an organization
244
+ #
245
+ # Requires authenticated organization members.
246
+ #
247
+ # @param org [String, Integer] Organization GitHub login or id.
248
+ # @param user [String] GitHub username to be removed as outside collaborator
249
+ # @return [Boolean] Return true if outside collaborator removed from organization, false otherwise.
250
+ # @see https://developer.github.com/v3/orgs/outside-collaborators/#remove-outside-collaborator
251
+ #
252
+ # @example
253
+ # @client.remove_outside_collaborator('github', 'lizzhale')
254
+ def remove_outside_collaborator(org, user, options={})
255
+ options = ensure_api_media_type(:org_memberships, options)
256
+ boolean_from_response :delete, "#{Organization.path org}/outside_collaborators/#{user}", options
257
+ end
258
+
259
+ # Converts an organization member to an outside collaborator
260
+ #
261
+ # Requires authenticated organization members.
262
+ #
263
+ # @param org [String, Integer] Organization GitHub login or id.
264
+ # @param user [String] GitHub username to be removed as outside collaborator
265
+ # @return [Boolean] Return true if outside collaborator removed from organization, false otherwise.
266
+ # @see https://developer.github.com/v3/orgs/outside-collaborators/#convert-member-to-outside-collaborator
267
+ #
268
+ # @example
269
+ # @client.convert_to_outside_collaborator('github', 'lizzhale')
270
+ def convert_to_outside_collaborator(org, user, options={})
271
+ options = ensure_api_media_type(:org_memberships, options)
272
+ boolean_from_response :put, "#{Organization.path org}/outside_collaborators/#{user}", options
273
+ end
274
+
275
+ # List teams
276
+ #
277
+ # Requires authenticated organization member.
278
+ #
279
+ # @param org [String, Integer] Organization GitHub login or id.
280
+ # @return [Array<Sawyer::Resource>] Array of hashes representing teams.
281
+ # @see https://developer.github.com/v3/orgs/teams/#list-teams
282
+ # @example
283
+ # @client.organization_teams('github')
284
+ # @example
285
+ # @client.org_teams('github')
286
+ def organization_teams(org, options = {})
287
+ paginate "#{Organization.path org}/teams", options
288
+ end
289
+ alias :org_teams :organization_teams
290
+
291
+ # Create team
292
+ #
293
+ # Requires authenticated organization owner.
294
+ #
295
+ # @param org [String, Integer] Organization GitHub login or id.
296
+ # @option options [String] :name Team name.
297
+ # @option options [Array<String>] :repo_names Repositories for the team.
298
+ # @option options [Array<String>] :maintainers Maintainers for the team.
299
+ # @return [Sawyer::Resource] Hash representing new team.
300
+ # @see https://developer.github.com/v3/orgs/teams/#create-team
301
+ # @example
302
+ # @client.create_team('github', {
303
+ # :name => 'Designers',
304
+ # :repo_names => ['github/dotfiles']
305
+ # })
306
+ def create_team(org, options = {})
307
+ if options.key?(:permission)
308
+ octokit_warn "Deprecated: Passing :permission option to #create_team. Assign team repository permission by passing :permission to #add_team_repository instead."
309
+ end
310
+ post "#{Organization.path org}/teams", options
311
+ end
312
+
313
+ # Get team
314
+ #
315
+ # Requires authenticated organization member.
316
+ #
317
+ # @param team_id [Integer] Team id.
318
+ # @return [Sawyer::Resource] Hash representing team.
319
+ # @see https://developer.github.com/v3/orgs/teams/#get-team
320
+ # @example
321
+ # @client.team(100000)
322
+ def team(team_id, options = {})
323
+ get "teams/#{team_id}", options
324
+ end
325
+
326
+ # Update team
327
+ #
328
+ # Requires authenticated organization owner.
329
+ #
330
+ # @param team_id [Integer] Team id.
331
+ # @option options [String] :name Team name.
332
+ # @option options [String] :permission Permissions the team has for team repositories.
333
+ #
334
+ # `pull` - team members can pull, but not push to or administer these repositories.
335
+ # `push` - team members can pull and push, but not administer these repositories.
336
+ # `admin` - team members can pull, push and administer these repositories.
337
+ # @return [Sawyer::Resource] Hash representing updated team.
338
+ # @see https://developer.github.com/v3/orgs/teams/#edit-team
339
+ # @example
340
+ # @client.update_team(100000, {
341
+ # :name => 'Front-end Designers',
342
+ # :permission => 'push'
343
+ # })
344
+ def update_team(team_id, options = {})
345
+ patch "teams/#{team_id}", options
346
+ end
347
+
348
+ # Delete team
349
+ #
350
+ # Requires authenticated organization owner.
351
+ #
352
+ # @param team_id [Integer] Team id.
353
+ # @return [Boolean] True if deletion successful, false otherwise.
354
+ # @see https://developer.github.com/v3/orgs/teams/#delete-team
355
+ # @example
356
+ # @client.delete_team(100000)
357
+ def delete_team(team_id, options = {})
358
+ boolean_from_response :delete, "teams/#{team_id}", options
359
+ end
360
+
361
+ # List team members
362
+ #
363
+ # Requires authenticated organization member.
364
+ #
365
+ # @param team_id [Integer] Team id.
366
+ # @return [Array<Sawyer::Resource>] Array of hashes representing users.
367
+ # @see https://developer.github.com/v3/orgs/teams/#list-team-members
368
+ # @example
369
+ # @client.team_members(100000)
370
+ def team_members(team_id, options = {})
371
+ paginate "teams/#{team_id}/members", options
372
+ end
373
+
374
+ # Add team member
375
+ #
376
+ # Requires authenticated organization owner or member with team
377
+ # `admin` permission.
378
+ #
379
+ # @param team_id [Integer] Team id.
380
+ # @param user [String] GitHub username of new team member.
381
+ # @return [Boolean] True on successful addition, false otherwise.
382
+ # @see https://developer.github.com/v3/orgs/teams/#add-team-member
383
+ # @example
384
+ # @client.add_team_member(100000, 'pengwynn')
385
+ #
386
+ # @example
387
+ # # Opt-in to future behavior for this endpoint. Adds the member to the
388
+ # # team if they're already an org member. If not, the method will return
389
+ # # 422 and indicate the user should call the new Team Membership endpoint.
390
+ # @client.add_team_member \
391
+ # 100000,
392
+ # 'pengwynn',
393
+ # :accept => "application/vnd.github.the-wasp-preview+json"
394
+ # @see https://developer.github.com/changes/2014-08-05-team-memberships-api/
395
+ def add_team_member(team_id, user, options = {})
396
+ # There's a bug in this API call. The docs say to leave the body blank,
397
+ # but it fails if the body is both blank and the content-length header
398
+ # is not 0.
399
+ boolean_from_response :put, "teams/#{team_id}/members/#{user}", options.merge({:name => user})
400
+ end
401
+
402
+ # Remove team member
403
+ #
404
+ # Requires authenticated organization owner or member with team
405
+ # `admin` permission.
406
+ #
407
+ # @param team_id [Integer] Team id.
408
+ # @param user [String] GitHub username of the user to boot.
409
+ # @return [Boolean] True if user removed, false otherwise.
410
+ # @see https://developer.github.com/v3/orgs/teams/#remove-team-member
411
+ # @example
412
+ # @client.remove_team_member(100000, 'pengwynn')
413
+ def remove_team_member(team_id, user, options = {})
414
+ boolean_from_response :delete, "teams/#{team_id}/members/#{user}", options
415
+ end
416
+
417
+ # Check if a user is a member of a team.
418
+ #
419
+ # Use this to check if another user is a member of a team that
420
+ # you are a member.
421
+ #
422
+ # @param team_id [Integer] Team id.
423
+ # @param user [String] GitHub username of the user to check.
424
+ #
425
+ # @return [Boolean] Is a member?
426
+ #
427
+ # @see https://developer.github.com/v3/orgs/teams/#get-team-member
428
+ #
429
+ # @example Check if a user is in your team
430
+ # @client.team_member?(100000, 'pengwynn')
431
+ # => false
432
+ def team_member?(team_id, user, options = {})
433
+ boolean_from_response :get, "teams/#{team_id}/members/#{user}", options
434
+ end
435
+
436
+ # List pending team invitations
437
+ #
438
+ # Requires authenticated organization member.
439
+ #
440
+ # @param team_id [Integer] Team id.
441
+ # @return [Array<Sawyer::Resource>] Array of hashes representing invitations.
442
+ # @see https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations
443
+ #
444
+ # @example
445
+ # @client.team_invitations('github')
446
+ def team_invitations(team_id, options = {})
447
+ options = ensure_api_media_type(:org_memberships, options)
448
+ get "teams/#{team_id}/invitations", options
449
+ end
450
+
451
+ # List team repositories
452
+ #
453
+ # Requires authenticated organization member.
454
+ #
455
+ # @param team_id [Integer] Team id.
456
+ # @return [Array<Sawyer::Resource>] Array of hashes representing repositories.
457
+ # @see https://developer.github.com/v3/orgs/teams/#list-team-repos
458
+ # @example
459
+ # @client.team_repositories(100000)
460
+ # @example
461
+ # @client.team_repos(100000)
462
+ def team_repositories(team_id, options = {})
463
+ paginate "teams/#{team_id}/repos", options
464
+ end
465
+ alias :team_repos :team_repositories
466
+
467
+ # Check if a repo is managed by a specific team
468
+ #
469
+ # @param team_id [Integer] Team ID.
470
+ # @param repo [String, Hash, Repository] A GitHub repository.
471
+ # @return [Boolean] True if managed by a team. False if not managed by
472
+ # the team OR the requesting user does not have authorization to access
473
+ # the team information.
474
+ # @see https://developer.github.com/v3/orgs/teams/#check-if-a-team-manages-a-repository
475
+ # @example
476
+ # @client.team_repository?(8675309, 'octokit/octokit.rb')
477
+ # @example
478
+ # @client.team_repo?(8675309, 'octokit/octokit.rb')
479
+ def team_repository?(team_id, repo, options = {})
480
+ boolean_from_response :get, "teams/#{team_id}/repos/#{Repository.new(repo)}"
481
+ end
482
+ alias :team_repo? :team_repository?
483
+
484
+ # Add team repository
485
+ #
486
+ # This can also be used to update the permission of an existing team
487
+ #
488
+ # Requires authenticated user to be an owner of the organization that the
489
+ # team is associated with. Also, the repo must be owned by the
490
+ # organization, or a direct form of a repo owned by the organization.
491
+ #
492
+ # @param team_id [Integer] Team id.
493
+ # @param repo [String, Hash, Repository] A GitHub repository.
494
+ # @option options [String] :permission The permission to grant the team.
495
+ # Only valid on organization-owned repositories.
496
+ # Can be one of: <tt>pull</tt>, <tt>push</tt>, or <tt>admin</tt>.
497
+ # If not specified, the team's <tt>permission</tt> attribute will be
498
+ # used to determine what permission to grant the team on this repository.
499
+ # @return [Boolean] True if successful, false otherwise.
500
+ # @see Octokit::Repository
501
+ # @see https://developer.github.com/v3/orgs/teams/#add-or-update-team-repository
502
+ # @example
503
+ # @client.add_team_repository(100000, 'github/developer.github.com')
504
+ # @example
505
+ # @client.add_team_repo(100000, 'github/developer.github.com')
506
+ # @example Add a team with admin permissions
507
+ # @client.add_team_repository(100000, 'github/developer.github.com', permission: 'admin')
508
+ def add_team_repository(team_id, repo, options = {})
509
+ boolean_from_response :put, "teams/#{team_id}/repos/#{Repository.new(repo)}", options.merge(:name => Repository.new(repo))
510
+ end
511
+ alias :add_team_repo :add_team_repository
512
+
513
+ # Remove team repository
514
+ #
515
+ # Removes repository from team. Does not delete the repository.
516
+ #
517
+ # Requires authenticated organization owner.
518
+ #
519
+ # @param team_id [Integer] Team id.
520
+ # @param repo [String, Hash, Repository] A GitHub repository.
521
+ # @return [Boolean] Return true if repo removed from team, false otherwise.
522
+ # @see Octokit::Repository
523
+ # @see https://developer.github.com/v3/orgs/teams/#remove-team-repository
524
+ # @example
525
+ # @client.remove_team_repository(100000, 'github/developer.github.com')
526
+ # @example
527
+ # @client.remove_team_repo(100000, 'github/developer.github.com')
528
+ def remove_team_repository(team_id, repo, options = {})
529
+ boolean_from_response :delete, "teams/#{team_id}/repos/#{Repository.new(repo)}"
530
+ end
531
+ alias :remove_team_repo :remove_team_repository
532
+
533
+ # Remove organization member
534
+ #
535
+ # Requires authenticated organization owner or member with team `admin` access.
536
+ #
537
+ # @param org [String, Integer] Organization GitHub login or id.
538
+ # @param user [String] GitHub username of user to remove.
539
+ # @return [Boolean] True if removal is successful, false otherwise.
540
+ # @see https://developer.github.com/v3/orgs/members/#remove-a-member
541
+ # @example
542
+ # @client.remove_organization_member('github', 'pengwynn')
543
+ # @example
544
+ # @client.remove_org_member('github', 'pengwynn')
545
+ def remove_organization_member(org, user, options = {})
546
+ # this is a synonym for: for team in org.teams: remove_team_member(team.id, user)
547
+ # provided in the GH API v3
548
+ boolean_from_response :delete, "#{Organization.path org}/members/#{user}", options
549
+ end
550
+ alias :remove_org_member :remove_organization_member
551
+
552
+ # Publicize a user's membership of an organization
553
+ #
554
+ # Requires authenticated organization owner.
555
+ #
556
+ # @param org [String, Integer] Organization GitHub login or id.
557
+ # @param user [String] GitHub username of user to publicize.
558
+ # @return [Boolean] True if publicization successful, false otherwise.
559
+ # @see https://developer.github.com/v3/orgs/members/#publicize-a-users-membership
560
+ # @example
561
+ # @client.publicize_membership('github', 'pengwynn')
562
+ def publicize_membership(org, user, options = {})
563
+ boolean_from_response :put, "#{Organization.path org}/public_members/#{user}", options
564
+ end
565
+
566
+ # Conceal a user's membership of an organization.
567
+ #
568
+ # Requires authenticated organization owner.
569
+ #
570
+ # @param org [String, Integer] Organization GitHub login or id.
571
+ # @param user [String] GitHub username of user to unpublicize.
572
+ # @return [Boolean] True of unpublicization successful, false otherwise.
573
+ # @see https://developer.github.com/v3/orgs/members/#conceal-a-users-membership
574
+ # @example
575
+ # @client.unpublicize_membership('github', 'pengwynn')
576
+ # @example
577
+ # @client.conceal_membership('github', 'pengwynn')
578
+ def unpublicize_membership(org, user, options = {})
579
+ boolean_from_response :delete, "#{Organization.path org}/public_members/#{user}", options
580
+ end
581
+ alias :conceal_membership :unpublicize_membership
582
+
583
+ # List all teams for the authenticated user across all their orgs
584
+ #
585
+ # @return [Array<Sawyer::Resource>] Array of team resources.
586
+ # @see https://developer.github.com/v3/orgs/teams/#list-user-teams
587
+ def user_teams(options = {})
588
+ paginate "user/teams", options
589
+ end
590
+
591
+ # Check if a user has a team membership.
592
+ #
593
+ # @param team_id [Integer] Team id.
594
+ # @param user [String] GitHub username of the user to check.
595
+ #
596
+ # @return [Sawyer::Resource] Hash of team membership info
597
+ #
598
+ # @see https://developer.github.com/v3/orgs/teams/#get-team-membership
599
+ #
600
+ # @example Check if a user has a membership for a team
601
+ # @client.team_membership(1234, 'pengwynn')
602
+ def team_membership(team_id, user, options = {})
603
+ get "teams/#{team_id}/memberships/#{user}", options
604
+ end
605
+
606
+ # Add or invite a user to a team
607
+ #
608
+ # @param team_id [Integer] Team id.
609
+ # @param user [String] GitHub username of the user to invite.
610
+ #
611
+ # @return [Sawyer::Resource] Hash of team membership info
612
+ #
613
+ # @see https://developer.github.com/v3/orgs/teams/#add-team-membership
614
+ #
615
+ # @example Check if a user has a membership for a team
616
+ # @client.add_team_membership(1234, 'pengwynn')
617
+ def add_team_membership(team_id, user, options = {})
618
+ put "teams/#{team_id}/memberships/#{user}", options
619
+ end
620
+
621
+ # Remove team membership
622
+ #
623
+ # @param team_id [Integer] Team id.
624
+ # @param user [String] GitHub username of the user to boot.
625
+ # @return [Boolean] True if user removed, false otherwise.
626
+ # @see https://developer.github.com/v3/orgs/teams/#remove-team-membership
627
+ # @example
628
+ # @client.remove_team_membership(100000, 'pengwynn')
629
+ def remove_team_membership(team_id, user, options = {})
630
+ boolean_from_response :delete, "teams/#{team_id}/memberships/#{user}", options
631
+ end
632
+
633
+ # List all organizations memberships for the authenticated user
634
+ #
635
+ # @return [Array<Sawyer::Resource>] Array of organizations memberships.
636
+ # @see https://developer.github.com/v3/orgs/members/#list-your-organization-memberships
637
+ def organization_memberships(options = {})
638
+ paginate "user/memberships/orgs", options
639
+ end
640
+ alias :org_memberships :organization_memberships
641
+
642
+ # Get an organization membership
643
+ #
644
+ # @param org [Integer, String] The GitHub Organization.
645
+ # @option options [String] :user The login of the user, otherwise authenticated user.
646
+ # @return [Sawyer::Resource] Hash representing the organization membership.
647
+ # @see https://developer.github.com/v3/orgs/members/#get-your-organization-membership
648
+ # @see https://developer.github.com/v3/orgs/members/#get-organization-membership
649
+ def organization_membership(org, options = {})
650
+ if user = options.delete(:user)
651
+ get "#{Organization.path(org)}/memberships/#{user}", options
652
+ else
653
+ get "user/memberships/orgs/#{org}", options
654
+ end
655
+ end
656
+ alias :org_membership :organization_membership
657
+
658
+ # Edit an organization membership
659
+ #
660
+ # @param org [String] Organization GitHub login.
661
+ # @option options [String] :role The role of the user in the organization.
662
+ # @option options [String] :state The state that the membership should be in.
663
+ # @option options [String] :user The login of the user, otherwise authenticated user.
664
+ # @return [Sawyer::Resource] Hash representing the updated organization membership.
665
+ # @see https://developer.github.com/v3/orgs/members/#edit-your-organization-membership
666
+ # @see https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership
667
+ def update_organization_membership(org, options = {})
668
+ if user = options.delete(:user)
669
+ put "orgs/#{org}/memberships/#{user}", options
670
+ else
671
+ patch "user/memberships/orgs/#{org}", options
672
+ end
673
+ end
674
+ alias :update_org_membership :update_organization_membership
675
+
676
+ # Remove an organization membership
677
+ #
678
+ # @param org [String] Organization GitHub login.
679
+ # @return [Boolean] Success
680
+ # @see https://developer.github.com/v3/orgs/members/#remove-organization-membership
681
+ def remove_organization_membership(org, options = {})
682
+ user = options.delete(:user)
683
+ user && boolean_from_response(:delete, "orgs/#{org}/memberships/#{user}", options)
684
+ end
685
+
686
+ # Initiates the generation of a migration archive.
687
+ #
688
+ # Requires authenticated organization owner.
689
+ #
690
+ # @param org [String, Integer] Organization GitHub login or id.
691
+ # @param repositories [Array<String>] :repositories Repositories for the organization.
692
+ # @option options [Boolean, optional] :lock_repositories Indicates whether repositories should be locked during migration
693
+ # @return [Sawyer::Resource] Hash representing the new migration.
694
+ # @example
695
+ # @client.start_migration('github', ['github/dotfiles'])
696
+ # @see https://developer.github.com/v3/orgs/migrations/#start-a-migration
697
+ def start_migration(org, repositories, options = {})
698
+ options = ensure_api_media_type(:migrations, options)
699
+ options[:repositories] = repositories
700
+ post "orgs/#{org}/migrations", options
701
+ end
702
+
703
+ # Lists the most recent migrations.
704
+ #
705
+ # Requires authenticated organization owner.
706
+ #
707
+ # @param org [String, Integer] Organization GitHub login or id.
708
+ # @return [Array<Sawyer::Resource>] Array of migration resources.
709
+ # @see https://developer.github.com/v3/orgs/migrations/#get-a-list-of-migrations
710
+ def migrations(org, options = {})
711
+ options = ensure_api_media_type(:migrations, options)
712
+ paginate "orgs/#{org}/migrations", options
713
+ end
714
+
715
+ # Fetches the status of a migration.
716
+ #
717
+ # Requires authenticated organization owner.
718
+ #
719
+ # @param org [String, Integer] Organization GitHub login or id.
720
+ # @param id [Integer] ID number of the migration.
721
+ # @see https://developer.github.com/v3/orgs/migrations/#get-the-status-of-a-migration
722
+ def migration_status(org, id, options = {})
723
+ options = ensure_api_media_type(:migrations, options)
724
+ get "orgs/#{org}/migrations/#{id}", options
725
+ end
726
+
727
+ # Fetches the URL to a migration archive.
728
+ #
729
+ # Requires authenticated organization owner.
730
+ #
731
+ # @param org [String, Integer] Organization GitHub login or id.
732
+ # @param id [Integer] ID number of the migration.
733
+ # @see https://developer.github.com/v3/orgs/migrations/#download-a-migration-archive
734
+ def migration_archive_url(org, id, options = {})
735
+ options = ensure_api_media_type(:migrations, options)
736
+ url = "orgs/#{org}/migrations/#{id}/archive"
737
+
738
+ response = client_without_redirects(options).get(url)
739
+ response.headers['location']
740
+ end
741
+
742
+ # Deletes a previous migration archive.
743
+ #
744
+ # Requires authenticated organization owner.
745
+ #
746
+ # @param org [String, Integer] Organization GitHub login or id.
747
+ # @param id [Integer] ID number of the migration.
748
+ # @see https://developer.github.com/v3/orgs/migrations/#delete-a-migration-archive
749
+ def delete_migration_archive(org, id, options = {})
750
+ options = ensure_api_media_type(:migrations, options)
751
+ delete "orgs/#{org}/migrations/#{id}/archive", options
752
+ end
753
+
754
+ # Unlock a previous migration archive.
755
+ #
756
+ # Requires authenticated organization owner.
757
+ #
758
+ # @param org [String, Integer] Organization GitHub login or id.
759
+ # @param id [Integer] ID number of the migration.
760
+ # @param repo [String] Name of the repository.
761
+ # @see https://developer.github.com/v3/orgs/migrations/#unlock-a-repository
762
+ def unlock_repository(org, id, repo, options = {})
763
+ options = ensure_api_media_type(:migrations, options)
764
+ delete "orgs/#{org}/migrations/#{id}/repos/#{repo}/lock", options
765
+ end
766
+ end
767
+ end
768
+ end