lingfennan-github_api 0.18.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +741 -0
  4. data/lib/github_api.rb +93 -0
  5. data/lib/github_api/api.rb +398 -0
  6. data/lib/github_api/api/actions.rb +60 -0
  7. data/lib/github_api/api/arguments.rb +253 -0
  8. data/lib/github_api/api/config.rb +105 -0
  9. data/lib/github_api/api/config/property.rb +30 -0
  10. data/lib/github_api/api/config/property_set.rb +120 -0
  11. data/lib/github_api/api/factory.rb +33 -0
  12. data/lib/github_api/authorization.rb +75 -0
  13. data/lib/github_api/client.rb +77 -0
  14. data/lib/github_api/client/activity.rb +31 -0
  15. data/lib/github_api/client/activity/events.rb +233 -0
  16. data/lib/github_api/client/activity/feeds.rb +50 -0
  17. data/lib/github_api/client/activity/notifications.rb +181 -0
  18. data/lib/github_api/client/activity/starring.rb +130 -0
  19. data/lib/github_api/client/activity/watching.rb +176 -0
  20. data/lib/github_api/client/authorizations.rb +142 -0
  21. data/lib/github_api/client/authorizations/app.rb +98 -0
  22. data/lib/github_api/client/emojis.rb +19 -0
  23. data/lib/github_api/client/gists.rb +289 -0
  24. data/lib/github_api/client/gists/comments.rb +100 -0
  25. data/lib/github_api/client/git_data.rb +31 -0
  26. data/lib/github_api/client/git_data/blobs.rb +51 -0
  27. data/lib/github_api/client/git_data/commits.rb +101 -0
  28. data/lib/github_api/client/git_data/references.rb +150 -0
  29. data/lib/github_api/client/git_data/tags.rb +95 -0
  30. data/lib/github_api/client/git_data/trees.rb +113 -0
  31. data/lib/github_api/client/gitignore.rb +57 -0
  32. data/lib/github_api/client/issues.rb +248 -0
  33. data/lib/github_api/client/issues/assignees.rb +77 -0
  34. data/lib/github_api/client/issues/comments.rb +146 -0
  35. data/lib/github_api/client/issues/events.rb +50 -0
  36. data/lib/github_api/client/issues/labels.rb +189 -0
  37. data/lib/github_api/client/issues/milestones.rb +146 -0
  38. data/lib/github_api/client/markdown.rb +62 -0
  39. data/lib/github_api/client/meta.rb +19 -0
  40. data/lib/github_api/client/orgs.rb +127 -0
  41. data/lib/github_api/client/orgs/hooks.rb +182 -0
  42. data/lib/github_api/client/orgs/members.rb +142 -0
  43. data/lib/github_api/client/orgs/memberships.rb +131 -0
  44. data/lib/github_api/client/orgs/projects.rb +57 -0
  45. data/lib/github_api/client/orgs/teams.rb +407 -0
  46. data/lib/github_api/client/projects.rb +83 -0
  47. data/lib/github_api/client/projects/cards.rb +158 -0
  48. data/lib/github_api/client/projects/columns.rb +146 -0
  49. data/lib/github_api/client/pull_requests.rb +195 -0
  50. data/lib/github_api/client/pull_requests/comments.rb +140 -0
  51. data/lib/github_api/client/pull_requests/reviews.rb +158 -0
  52. data/lib/github_api/client/repos.rb +468 -0
  53. data/lib/github_api/client/repos/branches.rb +48 -0
  54. data/lib/github_api/client/repos/branches/protections.rb +75 -0
  55. data/lib/github_api/client/repos/collaborators.rb +84 -0
  56. data/lib/github_api/client/repos/comments.rb +125 -0
  57. data/lib/github_api/client/repos/commits.rb +80 -0
  58. data/lib/github_api/client/repos/contents.rb +246 -0
  59. data/lib/github_api/client/repos/deployments.rb +138 -0
  60. data/lib/github_api/client/repos/downloads.rb +62 -0
  61. data/lib/github_api/client/repos/forks.rb +48 -0
  62. data/lib/github_api/client/repos/hooks.rb +214 -0
  63. data/lib/github_api/client/repos/keys.rb +104 -0
  64. data/lib/github_api/client/repos/merging.rb +47 -0
  65. data/lib/github_api/client/repos/pages.rb +48 -0
  66. data/lib/github_api/client/repos/projects.rb +62 -0
  67. data/lib/github_api/client/repos/pub_sub_hubbub.rb +133 -0
  68. data/lib/github_api/client/repos/releases.rb +189 -0
  69. data/lib/github_api/client/repos/releases/assets.rb +136 -0
  70. data/lib/github_api/client/repos/releases/tags.rb +24 -0
  71. data/lib/github_api/client/repos/statistics.rb +89 -0
  72. data/lib/github_api/client/repos/statuses.rb +91 -0
  73. data/lib/github_api/client/say.rb +25 -0
  74. data/lib/github_api/client/scopes.rb +46 -0
  75. data/lib/github_api/client/search.rb +133 -0
  76. data/lib/github_api/client/search/legacy.rb +111 -0
  77. data/lib/github_api/client/users.rb +117 -0
  78. data/lib/github_api/client/users/emails.rb +65 -0
  79. data/lib/github_api/client/users/followers.rb +115 -0
  80. data/lib/github_api/client/users/keys.rb +104 -0
  81. data/lib/github_api/configuration.rb +70 -0
  82. data/lib/github_api/connection.rb +82 -0
  83. data/lib/github_api/constants.rb +61 -0
  84. data/lib/github_api/core_ext/array.rb +25 -0
  85. data/lib/github_api/core_ext/hash.rb +91 -0
  86. data/lib/github_api/core_ext/ordered_hash.rb +107 -0
  87. data/lib/github_api/deprecation.rb +39 -0
  88. data/lib/github_api/error.rb +32 -0
  89. data/lib/github_api/error/client_error.rb +89 -0
  90. data/lib/github_api/error/service_error.rb +223 -0
  91. data/lib/github_api/ext/faraday.rb +38 -0
  92. data/lib/github_api/mash.rb +7 -0
  93. data/lib/github_api/middleware.rb +37 -0
  94. data/lib/github_api/mime_type.rb +33 -0
  95. data/lib/github_api/normalizer.rb +23 -0
  96. data/lib/github_api/null_encoder.rb +25 -0
  97. data/lib/github_api/page_iterator.rb +138 -0
  98. data/lib/github_api/page_links.rb +63 -0
  99. data/lib/github_api/paged_request.rb +42 -0
  100. data/lib/github_api/pagination.rb +115 -0
  101. data/lib/github_api/parameter_filter.rb +35 -0
  102. data/lib/github_api/params_hash.rb +115 -0
  103. data/lib/github_api/rate_limit.rb +25 -0
  104. data/lib/github_api/request.rb +85 -0
  105. data/lib/github_api/request/basic_auth.rb +36 -0
  106. data/lib/github_api/request/jsonize.rb +54 -0
  107. data/lib/github_api/request/oauth2.rb +44 -0
  108. data/lib/github_api/request/verbs.rb +63 -0
  109. data/lib/github_api/response.rb +48 -0
  110. data/lib/github_api/response/atom_parser.rb +22 -0
  111. data/lib/github_api/response/follow_redirects.rb +140 -0
  112. data/lib/github_api/response/header.rb +87 -0
  113. data/lib/github_api/response/jsonize.rb +28 -0
  114. data/lib/github_api/response/mashify.rb +24 -0
  115. data/lib/github_api/response/raise_error.rb +22 -0
  116. data/lib/github_api/response/xmlize.rb +27 -0
  117. data/lib/github_api/response_wrapper.rb +161 -0
  118. data/lib/github_api/ssl_certs/cacerts.pem +2183 -0
  119. data/lib/github_api/utils/url.rb +63 -0
  120. data/lib/github_api/validations.rb +22 -0
  121. data/lib/github_api/validations/format.rb +26 -0
  122. data/lib/github_api/validations/presence.rb +32 -0
  123. data/lib/github_api/validations/required.rb +21 -0
  124. data/lib/github_api/validations/token.rb +41 -0
  125. data/lib/github_api/version.rb +5 -0
  126. metadata +338 -0
@@ -0,0 +1,131 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::Orgs::Memberships < API
7
+ # List your organization memberships
8
+ #
9
+ # @see List your organization memberships
10
+ #
11
+ # @example
12
+ # github = Github.new
13
+ # github.orgs.memberships.list
14
+ #
15
+ # @api public
16
+ def list(*args)
17
+ arguments(args)
18
+
19
+ response = get_request('/user/memberships/orgs', arguments.params)
20
+ return response unless block_given?
21
+ response.each { |el| yield el }
22
+ end
23
+ alias_method :all, :list
24
+
25
+ # Get organization membership
26
+ #
27
+ # In order to get a user's membership with an organization,
28
+ # the authenticated user must be an organization owner.
29
+ #
30
+ # @see https://developer.github.com/v3/orgs/members/#get-organization-membership
31
+ # @param [String] :org
32
+ # @param [String] :username
33
+ #
34
+ # @example
35
+ # github = Github.new oauth_toke: '...'
36
+ # github.orgs.memberships.get 'orgname', username: 'piotr'
37
+ #
38
+ # Get your organization membership
39
+ #
40
+ # @see https://developer.github.com/v3/orgs/members/#get-your-organization-membership
41
+ #
42
+ # @example
43
+ # github = Github.new oauth_token
44
+ # github.orgs.memberships.get 'orgname'
45
+ #
46
+ # @api public
47
+ def get(*args)
48
+ arguments(args, required: [:org_name])
49
+ params = arguments.params
50
+
51
+ if (username = params.delete('username'))
52
+ get_request("/orgs/#{arguments.org_name}/memberships/#{username}", params)
53
+ else
54
+ get_request("/user/memberships/orgs/#{arguments.org_name}", params)
55
+ end
56
+ end
57
+ alias_method :find, :get
58
+
59
+ # Add/update user's membership with organization
60
+ #
61
+ # In order to create or update a user's membership with an organization,
62
+ # the authenticated user must be an organization owner.
63
+ #
64
+ # @see https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership
65
+ #
66
+ # @param [String] :org
67
+ # @param [String] :username
68
+ # @param [Hash] options
69
+ # @option options [String] :role
70
+ # Required. The role to give the user in the organization. Can be one of:
71
+ # * admin - The user will become an owner of the organization.
72
+ # * member - The user will become a non-owner member of the organization.
73
+ #
74
+ # @example
75
+ # github = Github.new oauth_token: '...'
76
+ # github.orgs.memberships.add 'org-name', 'member-name', role: 'role'
77
+ #
78
+ # @api public
79
+ def create(*args)
80
+ arguments(args, required: [:org_name, :username]) do
81
+ assert_required :role
82
+ end
83
+
84
+ put_request("/orgs/#{arguments.org_name}/memberships/#{arguments.username}",
85
+ arguments.params)
86
+ end
87
+ alias_method :update, :create
88
+ alias_method :add, :create
89
+
90
+ # Edit your organization membership
91
+ #
92
+ # @see https://developer.github.com/v3/orgs/members/#edit-your-organization-membership
93
+ # @param [String] :org
94
+ # @param [Hash] params
95
+ # @option params [String] :state
96
+ # Required. The state that the membership should be in.
97
+ # Only "active" will be accepted.
98
+ #
99
+ # @example
100
+ # github = Github.new oauth_token: '...'
101
+ # github.orgs.memberships.edit 'org-name', state: 'active'
102
+ #
103
+ # @api public
104
+ def edit(*args)
105
+ arguments(args, required: [:org_name]) do
106
+ assert_required :state
107
+ end
108
+
109
+ patch_request("/user/memberships/orgs/#{arguments.org_name}",
110
+ arguments.params)
111
+ end
112
+
113
+ # Remove organization membership
114
+ #
115
+ # @see https://developer.github.com/v3/orgs/members/#remove-organization-membership
116
+ # @param [String] :org
117
+ # @param [String] :username
118
+ #
119
+ # @example
120
+ # github = Github.new oauth_token: '...'
121
+ # github.orgs.memberships.remove 'orgname', 'username'
122
+ #
123
+ # @api public
124
+ def delete(*args)
125
+ arguments(args, required: [:org_name, :username])
126
+
127
+ delete_request("/orgs/#{arguments.org_name}/memberships/#{arguments.username}", arguments.params)
128
+ end
129
+ alias_method :remove, :delete
130
+ end # Client::Orgs::Memberships
131
+ end # Github
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::Orgs::Projects < API
7
+ PREVIEW_MEDIA = "application/vnd.github.inertia-preview+json".freeze # :nodoc:
8
+
9
+ # List your organization projects
10
+ #
11
+ # @see List your organization projects
12
+ #
13
+ # @example
14
+ # github = Github.new 'org-name'
15
+ # github.orgs.projects.list 'org-name' { |project| ... }
16
+ #
17
+ # @example
18
+ # github = Github.new
19
+ # github.orgs.projects.list 'org-name', state: 'closed'
20
+ #
21
+ # @api public
22
+ def list(*args)
23
+ arguments(args, required: [:org_name])
24
+ params = arguments.params
25
+
26
+ params["accept"] ||= PREVIEW_MEDIA
27
+
28
+ response = get_request("/orgs/#{arguments.org_name}/projects", params)
29
+ return response unless block_given?
30
+ response.each { |el| yield el }
31
+ end
32
+ alias_method :all, :list
33
+
34
+ # Create a new project for the specified repo
35
+ #
36
+ # @param [Hash] params
37
+ # @option params [String] :name
38
+ # Required string - The name of the project.
39
+ # @option params [String] :body
40
+ # Optional string - The body of the project.
41
+ #
42
+ # @example
43
+ # github = Github.new
44
+ # github.repos.create 'owner-name', 'repo-name', name: 'project-name'
45
+ # github.repos.create name: 'project-name', body: 'project-body', owner: 'owner-name', repo: 'repo-name'
46
+ def create(*args)
47
+ arguments(args, required: [:org_name]) do
48
+ assert_required %w[ name ]
49
+ end
50
+ params = arguments.params
51
+
52
+ params["accept"] ||= PREVIEW_MEDIA
53
+
54
+ post_request("/orgs/#{arguments.org_name}/projects", params)
55
+ end
56
+ end # Projects
57
+ end # Github
@@ -0,0 +1,407 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ # All actions against teams require at a minimum an authenticated user
7
+ # who is a member of the owner's team in the :org being managed.
8
+ # Api calls that require explicit permissions are noted.
9
+ class Client::Orgs::Teams < API
10
+ # List user teams
11
+ #
12
+ # List all of the teams across all of the organizations
13
+ # to which the authenticated user belongs. This method
14
+ # requires user or repo scope when authenticating via OAuth.
15
+ #
16
+ # @example
17
+ # github = Github.new oauth_token: '...'
18
+ # github.orgs.teams.list
19
+ #
20
+ # List teams
21
+ #
22
+ # @see https://developer.github.com/v3/orgs/teams/#list-teams
23
+ #
24
+ # @example
25
+ # github = Github.new oauth_token: '...'
26
+ # github.orgs.teams.list org: 'org-name'
27
+ #
28
+ # @api public
29
+ def list(*args)
30
+ params = arguments(args).params
31
+
32
+ if (org = params.delete('org'))
33
+ response = get_request("/orgs/#{org}/teams", params)
34
+ else
35
+ response = get_request('/user/teams', params)
36
+ end
37
+ return response unless block_given?
38
+ response.each { |el| yield el }
39
+ end
40
+ alias_method :all, :list
41
+
42
+ # Get a team
43
+ #
44
+ # @see https://developer.github.com/v3/orgs/teams/#get-team
45
+ #
46
+ # @example
47
+ # github = Github.new oauth_token: '...'
48
+ # github.orgs.teams.get 'team-id'
49
+ #
50
+ # @api public
51
+ def get(*args)
52
+ arguments(args, required: [:id])
53
+
54
+ get_request("/teams/#{arguments.id}", arguments.params)
55
+ end
56
+ alias_method :find, :get
57
+
58
+ # Create a team
59
+ #
60
+ # In order to create a team, the authenticated user must be an owner of :org
61
+ #
62
+ # @see https://developer.github.com/v3/orgs/teams/#create-team
63
+ #
64
+ # @param [Hash] params
65
+ # @option params [String] :name
66
+ # Required. The name of the team
67
+ # @option params [String] :description
68
+ # The description of the team.
69
+ # @option params [Array[String]] :repo_names
70
+ # The repositories to add the team to.
71
+ # @option params [String] :privacy
72
+ # The level of privacy this team should have. Can be one of:
73
+ # * secret - only visible to organization owners and
74
+ # members of this team.
75
+ # * closed - visible to all members of this organization.
76
+ # Default: secret
77
+ # @option params [String] :permission
78
+ # The permission to grant the team. Can be one of:
79
+ # * pull - team members can pull, but not push or
80
+ # administor this repositories.
81
+ # * push - team members can pull and push,
82
+ # but not administor this repositores.
83
+ # * admin - team members can pull, push and
84
+ # administor these repositories.
85
+ # Default: pull
86
+ #
87
+ # @example
88
+ # github = Github.new oauth_token: '...'
89
+ # github.orgs.teams.create 'org-name',
90
+ # name: "new team",
91
+ # permission: "push",
92
+ # repo_names: [
93
+ # "github/dotfiles"
94
+ # ]
95
+ #
96
+ # @api public
97
+ def create(*args)
98
+ arguments(args, required: [:org_name]) do
99
+ assert_required %w(name)
100
+ end
101
+
102
+ post_request("/orgs/#{arguments.org_name}/teams", arguments.params)
103
+ end
104
+
105
+ # Edit a team
106
+ #
107
+ # In order to edit a team, the authenticated user must be an owner
108
+ # of the org that the team is associated with.
109
+ #
110
+ # @see https://developer.github.com/v3/orgs/teams/#edit-team
111
+ #
112
+ # @param [Hash] params
113
+ # @option params [String] :name
114
+ # The repositories to add the team to.
115
+ # @option params [String] :description
116
+ # The description of the team.
117
+ # @option params [String] :privacy
118
+ # The level of privacy this team should have. Can be one of:
119
+ # * secret - only visible to organization owners and
120
+ # members of this team.
121
+ # * closed - visible to all members of this organization.
122
+ # Default: secret
123
+ # @option params [String] :permission
124
+ # The permission to grant the team. Can be one of:
125
+ # * pull - team members can pull, but not push or
126
+ # administor this repositories.
127
+ # * push - team members can pull and push,
128
+ # but not administor this repositores.
129
+ # * admin - team members can pull, push and
130
+ # administor these repositories.
131
+ # Default: pull
132
+ #
133
+ # @example
134
+ # github = Github.new oauth_token: '...'
135
+ # github.orgs.teams.edit 'team-id',
136
+ # name: "new team name",
137
+ # permission: "push"
138
+ #
139
+ # @api public
140
+ def edit(*args)
141
+ arguments(args, required: [:id]) do
142
+ assert_required %w(name)
143
+ end
144
+
145
+ patch_request("/teams/#{arguments.id}", arguments.params)
146
+ end
147
+
148
+ # Delete a team
149
+ #
150
+ # @see https://developer.github.com/v3/orgs/teams/#delete-team
151
+ #
152
+ # In order to delete a team, the authenticated user must be an owner
153
+ # of the org that the team is associated with
154
+ #
155
+ # @example
156
+ # github = Github.new oauth_token: '...'
157
+ # github.orgs.teams.delete 'team-id'
158
+ #
159
+ # @api public
160
+ def delete(*args)
161
+ arguments(args, required: [:id])
162
+
163
+ delete_request("/teams/#{arguments.id}", arguments.params)
164
+ end
165
+ alias_method :remove, :delete
166
+
167
+ # List team members
168
+ #
169
+ # In order to list members in a team, the authenticated user
170
+ # must be a member of the team.
171
+ #
172
+ # @see https://developer.github.com/v3/orgs/teams/#list-team-members
173
+ #
174
+ # @param [Integer] :team_id
175
+ #
176
+ # @example
177
+ # github = Github.new oauth_token: '...'
178
+ # github.orgs.teams.list_members 'team-id'
179
+ # github.orgs.teams.list_members 'team-id' { |member| ... }
180
+ #
181
+ # @api public
182
+ def list_members(*args)
183
+ arguments(args, required: [:team_id])
184
+
185
+ response = get_request("/teams/#{arguments.team_id}/members", arguments.params)
186
+ return response unless block_given?
187
+ response.each { |el| yield el }
188
+ end
189
+ alias_method :all_members, :list_members
190
+
191
+ # Check if a user is a member of a team
192
+ #
193
+ # @see https://developer.github.com/v3/orgs/teams/#get-team-member
194
+ #
195
+ # @param [Integer] :team_id
196
+ # @param [String] :username
197
+ #
198
+ # @example
199
+ # github = Github.new oauth_token: '...'
200
+ # github.orgs.teams.team_member? 'team-id', 'user-name'
201
+ #
202
+ # @api public
203
+ def team_member?(*args)
204
+ arguments(args, required: [:team_id, :user])
205
+
206
+ response = get_request("/teams/#{arguments.team_id}/members/#{arguments.user}", arguments.params)
207
+ response.status == 204
208
+ rescue Github::Error::NotFound
209
+ false
210
+ end
211
+
212
+ # Add a team member
213
+ #
214
+ # In order to add a user to a team, the authenticated user must
215
+ # have 'admin' permissions to the team or be an owner of the org
216
+ # that the team is associated with.
217
+ #
218
+ # @example
219
+ # github = Github.new oauth_token: '...'
220
+ # github.orgs.teams.add_member 'team-id', 'user-name'
221
+ #
222
+ # @api public
223
+ def add_member(*args)
224
+ arguments(args, required: [:id, :user])
225
+
226
+ put_request("/teams/#{arguments.id}/members/#{arguments.user}",
227
+ arguments.params)
228
+ end
229
+ alias_method :add_team_member, :add_member
230
+
231
+ # Remove a team member
232
+ #
233
+ # @see https://developer.github.com/v3/orgs/teams/#remove-team-member
234
+ #
235
+ # In order to remove a user from a team, the authenticated user must
236
+ # have 'admin' permissions to the team or be an owner of the org that
237
+ # the team is associated with.
238
+ # note: This does not delete the user, it just remove them from the team.
239
+ #
240
+ # @example
241
+ # github = Github.new oauth_token: '...'
242
+ # github.orgs.teams.remove_member 'team-id', 'user-name'
243
+ #
244
+ # @api public
245
+ def remove_member(*args)
246
+ arguments(args, required: [:id, :user])
247
+
248
+ delete_request("/teams/#{arguments.id}/members/#{arguments.user}",
249
+ arguments.params)
250
+ end
251
+ alias_method :remove_team_member, :remove_member
252
+
253
+ # Get team membership
254
+ #
255
+ # In order to get a user's membership with a team,
256
+ # the team must be visible to the authenticated user.
257
+ #
258
+ # @see https://developer.github.com/v3/orgs/teams/#get-team-membership
259
+ #
260
+ # @param [Integer] :team_id
261
+ # @param [String] :username
262
+ #
263
+ # @example
264
+ # github = Github.new oauth_token: '...'
265
+ # github.orgs.teams.team_membership 'team-id', 'username'
266
+ #
267
+ # @api public
268
+ def team_membership(*args)
269
+ arguments(args, required: [:team_id, :username])
270
+
271
+ get_request("/teams/#{arguments.team_id}/memberships/#{arguments.username}",
272
+ arguments.params)
273
+ end
274
+
275
+ # Add a team membership
276
+ #
277
+ # In order to add a user to a team, the authenticated user must
278
+ # have 'admin' permissions to the team or be an owner of the org
279
+ # that the team is associated with.
280
+ #
281
+ # @see https://developer.github.com/v3/orgs/teams/#add-team-membership
282
+ #
283
+ # @param [Integer] :team_id
284
+ # @param [String] :username
285
+ # @param [Hash] :params
286
+ # @option params [String] :role
287
+ # The role that this user should have in the team. Can be one of:
288
+ # * member - a normal member of the team.
289
+ # * maintainer - a team maintainer. Able to add/remove
290
+ # other team members, promote other team members to
291
+ # team maintainer, and edit the team's name and description.
292
+ # Default: member
293
+ #
294
+ # @example
295
+ # github = Github.new oauth_token: '...'
296
+ # github.orgs.teams.add_membership 'team-id', 'user-name'
297
+ #
298
+ # @api public
299
+ def add_membership(*args)
300
+ arguments(args, required: [:team_id, :user])
301
+
302
+ put_request("/teams/#{arguments.team_id}/memberships/#{arguments.user}",
303
+ arguments.params)
304
+ end
305
+ alias_method :add_team_membership, :add_membership
306
+
307
+ # Remove a team membership
308
+ #
309
+ # In order to remove a user from a team, the authenticated user must
310
+ # have 'admin' permissions to the team or be an owner of the org that
311
+ # the team is associated with.
312
+ # note: This does not delete the user, it just remove them from the team.
313
+ #
314
+ # @see https://developer.github.com/v3/orgs/teams/#remove-team-membership
315
+ #
316
+ # @example
317
+ # github = Github.new oauth_token: '...'
318
+ # github.orgs.teams.remove_membership 'team-id', 'user-name'
319
+ #
320
+ # @api public
321
+ def remove_membership(*args)
322
+ arguments(args, required: [:team_id, :user])
323
+
324
+ delete_request("/teams/#{arguments.team_id}/memberships/#{arguments.user}",
325
+ arguments.params)
326
+ end
327
+ alias_method :remove_team_membership, :remove_membership
328
+
329
+ # List team repositories
330
+ #
331
+ # @see https://developer.github.com/v3/orgs/teams/#list-team-repos
332
+ #
333
+ # @example
334
+ # github = Github.new oauth_token: '...'
335
+ # github.orgs.teams.list_repos 'team-id'
336
+ #
337
+ # @api public
338
+ def list_repos(*args)
339
+ arguments(args, required: [:id])
340
+
341
+ response = get_request("/teams/#{arguments.id}/repos", arguments.params)
342
+ return response unless block_given?
343
+ response.each { |el| yield el }
344
+ end
345
+ alias_method :repos, :list_repos
346
+
347
+ # Check if a repository belongs to a team
348
+ #
349
+ # @see https://developer.github.com/v3/orgs/teams/#get-team-repo
350
+ #
351
+ # @example
352
+ # github = Github.new oauth_token: '...'
353
+ # github.orgs.teams.team_repo? 'team-id', 'user-name', 'repo-name'
354
+ #
355
+ # @api public
356
+ def team_repo?(*args)
357
+ arguments(args, required: [:id, :user, :repo])
358
+
359
+ response = get_request("/teams/#{arguments.id}/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
360
+ response.status == 204
361
+ rescue Github::Error::NotFound
362
+ false
363
+ end
364
+ alias_method :team_repository?, :team_repo?
365
+
366
+ # Add a team repository
367
+ #
368
+ # In order to add a repo to a team, the authenticated user must be
369
+ # an owner of the org that the team is associated with. Also, the repo
370
+ # must be owned by the organization, or a direct for of a repo owned
371
+ # by the organization.
372
+ #
373
+ # @see https://developer.github.com/v3/orgs/teams/#add-team-repo
374
+ #
375
+ # @example
376
+ # github = Github.new oauth_token: '...'
377
+ # github.orgs.teams.add_repo 'team-id', 'user-name', 'repo-name'
378
+ #
379
+ # @api public
380
+ def add_repo(*args)
381
+ arguments(args, required: [:id, :user, :repo])
382
+
383
+ put_request("/teams/#{arguments.id}/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
384
+ end
385
+ alias_method :add_repository, :add_repo
386
+
387
+ # Remove a team repository
388
+ #
389
+ # In order to add a repo to a team, the authenticated user must be
390
+ # an owner of the org that the team is associated with.
391
+ # note: This does not delete the repo, it just removes it from the team.
392
+ #
393
+ # @see https://developer.github.com/v3/orgs/teams/#remove-team-repo
394
+ #
395
+ # @example
396
+ # github = Github.new oauth_token: '...'
397
+ # github.orgs.teams.remove_repo 'team-id', 'user-name', 'repo-name'
398
+ #
399
+ # @api public
400
+ def remove_repo(*args)
401
+ arguments(args, required: [:id, :user, :repo])
402
+
403
+ delete_request("/teams/#{arguments.id}/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
404
+ end
405
+ alias_method :remove_repository, :remove_repo
406
+ end # Client::Orgs::Teams
407
+ end # Github