Class: Github::Client::Orgs::Teams

Inherits:
API
  • Object
show all
Defined in:
lib/github_api/client/orgs/teams.rb

Overview

All actions against teams require at a minimum an authenticated user who is a member of the owner's team in the :org being managed. Api calls that require explicit permissions are noted.

Constant Summary

Constants included from MimeType

MimeType::MEDIA_LOOKUP

Constants included from Github::Constants

Github::Constants::ACCEPT, Github::Constants::ACCEPTED_OAUTH_SCOPES, Github::Constants::ACCEPT_CHARSET, Github::Constants::CACHE_CONTROL, Github::Constants::CONTENT_LENGTH, Github::Constants::CONTENT_TYPE, Github::Constants::DATE, Github::Constants::ETAG, Github::Constants::HEADER_LAST, Github::Constants::HEADER_LINK, Github::Constants::HEADER_NEXT, Github::Constants::LOCATION, Github::Constants::META_FIRST, Github::Constants::META_LAST, Github::Constants::META_NEXT, Github::Constants::META_PREV, Github::Constants::META_REL, Github::Constants::OAUTH_SCOPES, Github::Constants::PARAM_PAGE, Github::Constants::PARAM_PER_PAGE, Github::Constants::PARAM_START_PAGE, Github::Constants::RATELIMIT_LIMIT, Github::Constants::RATELIMIT_REMAINING, Github::Constants::RATELIMIT_RESET, Github::Constants::SERVER, Github::Constants::USER_AGENT

Instance Attribute Summary

Attributes inherited from API

#current_options

Instance Method Summary collapse

Methods inherited from API

after_callbacks, after_request, #api_methods_in, #arguments, before_callbacks, before_request, clear_request_methods!, #execute, extend_with_actions, extra_methods, #extract_basic_auth, extract_class_name, #filter_callbacks, inherited, #initialize, internal_methods, method_added, #method_missing, #module_methods_in, namespace, request_methods, root!, #run_callbacks, #set, #yield_or_eval

Methods included from Github::ClassMethods

#configuration, #configure, #require_all

Methods included from RateLimit

#ratelimit, #ratelimit_remaining, #ratelimit_reset

Methods included from Request::Verbs

#delete_request, #get_request, #head_request, #options_request, #patch_request, #post_request, #put_request

Methods included from MimeType

#lookup_media, #parse

Methods included from Authorization

#auth_code, #authenticated?, #authentication, #authorize_url, #basic_authed?, #client, #get_token

Constructor Details

This class inherits a constructor from Github::API

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Github::API

Instance Method Details

#add_member(*args) ⇒ Object Also known as: add_team_member

Add a team member

In order to add a user to a team, the authenticated user must have 'admin' permissions to the team or be an owner of the org that the team is associated with.

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.add_member 'team-id', 'user-name'

221
222
223
224
225
226
# File 'lib/github_api/client/orgs/teams.rb', line 221

def add_member(*args)
  arguments(args, required: [:id, :user])

  put_request("/teams/#{arguments.id}/members/#{arguments.user}",
              arguments.params)
end

#add_membership(*args) ⇒ Object Also known as: add_team_membership

Add a team membership

In order to add a user to a team, the authenticated user must have 'admin' permissions to the team or be an owner of the org that the team is associated with.

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.add_membership 'team-id', 'user-name'

See Also:


297
298
299
300
301
302
# File 'lib/github_api/client/orgs/teams.rb', line 297

def add_membership(*args)
  arguments(args, required: [:team_id, :user])

  put_request("/teams/#{arguments.team_id}/memberships/#{arguments.user}",
              arguments.params)
end

#add_repo(*args) ⇒ Object Also known as: add_repository

Add a team repository

In order to add a repo to a team, the authenticated user must be an owner of the org that the team is associated with. Also, the repo must be owned by the organization, or a direct for of a repo owned by the organization.

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.add_repo 'team-id', 'user-name', 'repo-name'

See Also:


378
379
380
381
382
# File 'lib/github_api/client/orgs/teams.rb', line 378

def add_repo(*args)
  arguments(args, required: [:id, :user, :repo])

  put_request("/teams/#{arguments.id}/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
end

#create(*args) ⇒ Object

Create a team

In order to create a team, the authenticated user must be an owner of :org

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.create 'org-name',
  name: "new team",
  permission: "push",
  repo_names: [
    "github/dotfiles"
  ]

See Also:


95
96
97
98
99
100
101
# File 'lib/github_api/client/orgs/teams.rb', line 95

def create(*args)
  arguments(args, required: [:org_name]) do
    assert_required %w(name)
  end

  post_request("/orgs/#{arguments.org_name}/teams", arguments.params)
end

#delete(*args) ⇒ Object Also known as: remove

Delete a team

In order to delete a team, the authenticated user must be an owner of the org that the team is associated with

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.delete 'team-id'

See Also:


158
159
160
161
162
# File 'lib/github_api/client/orgs/teams.rb', line 158

def delete(*args)
  arguments(args, required: [:id])

  delete_request("/teams/#{arguments.id}", arguments.params)
end

#edit(*args) ⇒ Object

Edit a team

In order to edit a team, the authenticated user must be an owner of the org that the team is associated with.

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.edit 'team-id',
  name: "new team name",
  permission: "push"

See Also:


138
139
140
141
142
143
144
# File 'lib/github_api/client/orgs/teams.rb', line 138

def edit(*args)
  arguments(args, required: [:id]) do
    assert_required %w(name)
  end

  patch_request("/teams/#{arguments.id}", arguments.params)
end

#get(*args) ⇒ Object Also known as: find

Get a team

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.get 'team-id'

See Also:


49
50
51
52
53
# File 'lib/github_api/client/orgs/teams.rb', line 49

def get(*args)
  arguments(args, required: [:id])

  get_request("/teams/#{arguments.id}", arguments.params)
end

#list(*args) ⇒ Object Also known as: all

List user teams

List all of the teams across all of the organizations to which the authenticated user belongs. This method requires user or repo scope when authenticating via OAuth.

List teams

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.list
github = Github.new oauth_token: '...'
github.orgs.teams.list org: 'org-name'

See Also:


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/github_api/client/orgs/teams.rb', line 27

def list(*args)
  params = arguments(args).params

  if (org = params.delete('org'))
    response = get_request("/orgs/#{org}/teams", params)
  else
    response = get_request('/user/teams', params)
  end
  return response unless block_given?
  response.each { |el| yield el }
end

#list_members(*args) ⇒ Object Also known as: all_members

List team members

In order to list members in a team, the authenticated user must be a member of the team.

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.list_members 'team-id'
github.orgs.teams.list_members 'team-id' { |member| ... }

See Also:


180
181
182
183
184
185
186
# File 'lib/github_api/client/orgs/teams.rb', line 180

def list_members(*args)
  arguments(args, required: [:team_id])

  response = get_request("/teams/#{arguments.team_id}/members", arguments.params)
  return response unless block_given?
  response.each { |el| yield el }
end

#list_repos(*args) ⇒ Object Also known as: repos

List team repositories

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.list_repos 'team-id'

See Also:


336
337
338
339
340
341
342
# File 'lib/github_api/client/orgs/teams.rb', line 336

def list_repos(*args)
  arguments(args, required: [:id])

  response = get_request("/teams/#{arguments.id}/repos", arguments.params)
  return response unless block_given?
  response.each { |el| yield el }
end

#remove_member(*args) ⇒ Object Also known as: remove_team_member

Remove a team member

In order to remove a user from a team, the authenticated user must have 'admin' permissions to the team or be an owner of the org that the team is associated with. note: This does not delete the user, it just remove them from the team.

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.remove_member 'team-id', 'user-name'

See Also:


243
244
245
246
247
248
# File 'lib/github_api/client/orgs/teams.rb', line 243

def remove_member(*args)
  arguments(args, required: [:id, :user])

  delete_request("/teams/#{arguments.id}/members/#{arguments.user}",
                 arguments.params)
end

#remove_membership(*args) ⇒ Object Also known as: remove_team_membership

Remove a team membership

In order to remove a user from a team, the authenticated user must have 'admin' permissions to the team or be an owner of the org that the team is associated with. note: This does not delete the user, it just remove them from the team.

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.remove_membership 'team-id', 'user-name'

See Also:


319
320
321
322
323
324
# File 'lib/github_api/client/orgs/teams.rb', line 319

def remove_membership(*args)
  arguments(args, required: [:team_id, :user])

  delete_request("/teams/#{arguments.team_id}/memberships/#{arguments.user}",
                 arguments.params)
end

#remove_repo(*args) ⇒ Object Also known as: remove_repository

Remove a team repository

In order to add a repo to a team, the authenticated user must be an owner of the org that the team is associated with. note: This does not delete the repo, it just removes it from the team.

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.remove_repo 'team-id', 'user-name', 'repo-name'

See Also:


398
399
400
401
402
# File 'lib/github_api/client/orgs/teams.rb', line 398

def remove_repo(*args)
  arguments(args, required: [:id, :user, :repo])

  delete_request("/teams/#{arguments.id}/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
end

#team_member?(*args) ⇒ Boolean

Check if a user is a member of a team

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.team_member? 'team-id', 'user-name'

See Also:


201
202
203
204
205
206
207
208
# File 'lib/github_api/client/orgs/teams.rb', line 201

def team_member?(*args)
  arguments(args, required: [:team_id, :user])

  response = get_request("/teams/#{arguments.team_id}/members/#{arguments.user}", arguments.params)
  response.status == 204
rescue Github::Error::NotFound
  false
end

#team_membership(*args) ⇒ Object

Get team membership

In order to get a user's membership with a team, the team must be visible to the authenticated user.

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.team_membership 'team-id', 'username'

See Also:


266
267
268
269
270
271
# File 'lib/github_api/client/orgs/teams.rb', line 266

def team_membership(*args)
  arguments(args, required: [:team_id, :username])

  get_request("/teams/#{arguments.team_id}/memberships/#{arguments.username}",
              arguments.params)
end

#team_repo?(*args) ⇒ Boolean Also known as: team_repository?

Check if a repository belongs to a team

Examples:

github = Github.new oauth_token: '...'
github.orgs.teams.team_repo? 'team-id', 'user-name', 'repo-name'

See Also:


354
355
356
357
358
359
360
361
# File 'lib/github_api/client/orgs/teams.rb', line 354

def team_repo?(*args)
  arguments(args, required: [:id, :user, :repo])

  response = get_request("/teams/#{arguments.id}/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
  response.status == 204
rescue Github::Error::NotFound
  false
end