Module: Octokit::Client::Organizations
- Included in:
- Octokit::Client
- Defined in:
- lib/octokit/client/organizations.rb
Overview
Methods for the Organizations API
Constant Summary collapse
- ORG_INVITATIONS_PREVIEW_MEDIA_TYPE =
"application/vnd.github.the-wasp-preview+json".freeze
Instance Method Summary collapse
-
#add_team_member(team_id, user, options = {}) ⇒ Boolean
Add team member.
-
#add_team_membership(team_id, user, options = {}) ⇒ Sawyer::Resource
Add or invite a user to a team.
-
#add_team_repository(team_id, repo, options = {}) ⇒ Boolean
(also: #add_team_repo)
Add team repository.
-
#create_team(org, options = {}) ⇒ Sawyer::Resource
Create team.
-
#delete_team(team_id, options = {}) ⇒ Boolean
Delete team.
-
#organization(org, options = {}) ⇒ Sawyer::Resource
(also: #org)
Get an organization.
-
#organization_member?(org, user, options = {}) ⇒ Boolean
(also: #org_member?)
Check if a user is a member of an organization.
-
#organization_members(org, options = {}) ⇒ Array<Sawyer::Resource>
(also: #org_members)
Get organization members.
-
#organization_public_member?(org, user, options = {}) ⇒ Boolean
(also: #org_public_member?)
Check if a user is a public member of an organization.
-
#organization_public_members(org, options = {}) ⇒ Array<Sawyer::Resource>
(also: #org_public_members)
Get organization public members.
-
#organization_repositories(org, options = {}) ⇒ Array<Sawyer::Resource>
(also: #org_repositories, #org_repos)
List organization repositories.
-
#organization_teams(org, options = {}) ⇒ Array<Sawyer::Resource>
(also: #org_teams)
List teams.
-
#organizations(user = nil, options = {}) ⇒ Array<Sawyer::Resource>
(also: #list_organizations, #list_orgs, #orgs)
Get organizations for a user.
-
#publicize_membership(org, user, options = {}) ⇒ Boolean
Publicize a user’s membership of an organization.
-
#remove_organization_member(org, user, options = {}) ⇒ Boolean
(also: #remove_org_member)
Remove organization member.
-
#remove_team_member(team_id, user, options = {}) ⇒ Boolean
Remove team member.
-
#remove_team_membership(team_id, user, options = {}) ⇒ Boolean
Remove team membership.
-
#remove_team_repository(team_id, repo, options = {}) ⇒ Boolean
(also: #remove_team_repo)
Remove team repository.
-
#team(team_id, options = {}) ⇒ Sawyer::Resource
Get team.
-
#team_member?(team_id, user, options = {}) ⇒ Boolean
Check if a user is a member of a team.
-
#team_members(team_id, options = {}) ⇒ Array<Sawyer::Resource>
List team members.
-
#team_membership(team_id, user, options = {}) ⇒ Sawyer::Resource
Check if a user has a team membership.
-
#team_repositories(team_id, options = {}) ⇒ Array<Sawyer::Resource>
(also: #team_repos)
List team repositories.
-
#team_repository?(team_id, repo, options = {}) ⇒ Boolean
(also: #team_repo?)
Check if a repo is managed by a specific team.
-
#unpublicize_membership(org, user, options = {}) ⇒ Boolean
(also: #conceal_membership)
Conceal a user’s membership of an organization.
-
#update_organization(org, values, options = {}) ⇒ Sawyer::Resource
(also: #update_org)
Update an organization.
-
#update_team(team_id, options = {}) ⇒ Sawyer::Resource
Update team.
-
#user_teams(options = {}) ⇒ Array<Sawyer::Resource>
List all teams for the authenticated user across all their orgs.
Instance Method Details
#add_team_member(team_id, user, options = {}) ⇒ Boolean
Add team member
Requires authenticated organization owner or member with team ‘admin` permission.
317 318 319 320 321 322 |
# File 'lib/octokit/client/organizations.rb', line 317 def add_team_member(team_id, user, = {}) # 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. boolean_from_response :put, "teams/#{team_id}/members/#{user}", .merge({:name => user}) end |
#add_team_membership(team_id, user, options = {}) ⇒ Sawyer::Resource
Add or invite a user to a team
516 517 518 519 |
# File 'lib/octokit/client/organizations.rb', line 516 def add_team_membership(team_id, user, = {}) = ensure_org_invitations_api_media_type() put "teams/#{team_id}/memberships/#{user}", end |
#add_team_repository(team_id, repo, options = {}) ⇒ Boolean Also known as: add_team_repo
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.
406 407 408 |
# File 'lib/octokit/client/organizations.rb', line 406 def add_team_repository(team_id, repo, = {}) boolean_from_response :put, "teams/#{team_id}/repos/#{Repository.new(repo)}", .merge(:name => Repository.new(repo)) end |
#create_team(org, options = {}) ⇒ Sawyer::Resource
Create team
Requires authenticated organization owner.
231 232 233 |
# File 'lib/octokit/client/organizations.rb', line 231 def create_team(org, = {}) post "#{Organization.path org}/teams", end |
#delete_team(team_id, options = {}) ⇒ Boolean
Delete team
Requires authenticated organization owner.
279 280 281 |
# File 'lib/octokit/client/organizations.rb', line 279 def delete_team(team_id, = {}) boolean_from_response :delete, "teams/#{team_id}", end |
#organization(org, options = {}) ⇒ Sawyer::Resource Also known as: org
Get an organization
20 21 22 |
# File 'lib/octokit/client/organizations.rb', line 20 def organization(org, = {}) get Organization.path(org), end |
#organization_member?(org, user, options = {}) ⇒ Boolean Also known as: org_member?
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.
164 165 166 167 168 169 170 171 |
# File 'lib/octokit/client/organizations.rb', line 164 def organization_member?(org, user, = {}) result = boolean_from_response(:get, "#{Organization.path org}/members/#{user}", ) if !result && last_response && last_response.status == 302 boolean_from_response :get, last_response.headers['Location'] else result end end |
#organization_members(org, options = {}) ⇒ Array<Sawyer::Resource> Also known as: org_members
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.
126 127 128 129 |
# File 'lib/octokit/client/organizations.rb', line 126 def organization_members(org, = {}) path = "public_" if .delete(:public) paginate "#{Organization.path org}/#{path}members", end |
#organization_public_member?(org, user, options = {}) ⇒ Boolean Also known as: org_public_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.
189 190 191 |
# File 'lib/octokit/client/organizations.rb', line 189 def organization_public_member?(org, user, = {}) boolean_from_response :get, "#{Organization.path org}/public_members/#{user}", end |
#organization_public_members(org, options = {}) ⇒ Array<Sawyer::Resource> Also known as: org_public_members
Get organization public members
Lists the public members of an organization
143 144 145 |
# File 'lib/octokit/client/organizations.rb', line 143 def organization_public_members(org, = {}) organization_members org, .merge(:public => true) end |
#organization_repositories(org, options = {}) ⇒ Array<Sawyer::Resource> Also known as: org_repositories, org_repos
List organization repositories
Public repositories are available without authentication. Private repos require authenticated organization member.
107 108 109 |
# File 'lib/octokit/client/organizations.rb', line 107 def organization_repositories(org, = {}) paginate "#{Organization.path org}/repos", end |
#organization_teams(org, options = {}) ⇒ Array<Sawyer::Resource> Also known as: org_teams
List teams
Requires authenticated organization member.
205 206 207 |
# File 'lib/octokit/client/organizations.rb', line 205 def organization_teams(org, = {}) paginate "#{Organization.path org}/teams", end |
#organizations(user = nil, options = {}) ⇒ Array<Sawyer::Resource> Also known as: list_organizations, list_orgs, orgs
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.
80 81 82 |
# File 'lib/octokit/client/organizations.rb', line 80 def organizations(user=nil, = {}) get "#{User.path user}/orgs", end |
#publicize_membership(org, user, options = {}) ⇒ Boolean
Publicize a user’s membership of an organization
Requires authenticated organization owner.
460 461 462 |
# File 'lib/octokit/client/organizations.rb', line 460 def publicize_membership(org, user, = {}) boolean_from_response :put, "#{Organization.path org}/public_members/#{user}", end |
#remove_organization_member(org, user, options = {}) ⇒ Boolean Also known as: remove_org_member
Remove organization member
Requires authenticated organization owner or member with team ‘admin` access.
443 444 445 446 447 |
# File 'lib/octokit/client/organizations.rb', line 443 def remove_organization_member(org, user, = {}) # this is a synonym for: for team in org.teams: remove_team_member(team.id, user) # provided in the GH API v3 boolean_from_response :delete, "#{Organization.path org}/members/#{user}", end |
#remove_team_member(team_id, user, options = {}) ⇒ Boolean
Remove team member
Requires authenticated organization owner or member with team ‘admin` permission.
335 336 337 |
# File 'lib/octokit/client/organizations.rb', line 335 def remove_team_member(team_id, user, = {}) boolean_from_response :delete, "teams/#{team_id}/members/#{user}", end |
#remove_team_membership(team_id, user, options = {}) ⇒ Boolean
Remove team membership
529 530 531 532 |
# File 'lib/octokit/client/organizations.rb', line 529 def remove_team_membership(team_id, user, = {}) = ensure_org_invitations_api_media_type() boolean_from_response :delete, "teams/#{team_id}/memberships/#{user}", end |
#remove_team_repository(team_id, repo, options = {}) ⇒ Boolean Also known as: remove_team_repo
Remove team repository
Removes repository from team. Does not delete the repository.
Requires authenticated organization owner.
426 427 428 |
# File 'lib/octokit/client/organizations.rb', line 426 def remove_team_repository(team_id, repo, = {}) boolean_from_response :delete, "teams/#{team_id}/repos/#{Repository.new(repo)}" end |
#team(team_id, options = {}) ⇒ Sawyer::Resource
Get team
Requires authenticated organization member.
244 245 246 |
# File 'lib/octokit/client/organizations.rb', line 244 def team(team_id, = {}) get "teams/#{team_id}", end |
#team_member?(team_id, user, options = {}) ⇒ Boolean
Check if a user is a member of a team.
Use this to check if another user is a member of a team that you are a member.
354 355 356 |
# File 'lib/octokit/client/organizations.rb', line 354 def team_member?(team_id, user, = {}) boolean_from_response :get, "teams/#{team_id}/members/#{user}", end |
#team_members(team_id, options = {}) ⇒ Array<Sawyer::Resource>
List team members
Requires authenticated organization member.
292 293 294 |
# File 'lib/octokit/client/organizations.rb', line 292 def team_members(team_id, = {}) paginate "teams/#{team_id}/members", end |
#team_membership(team_id, user, options = {}) ⇒ Sawyer::Resource
Check if a user has a team membership.
500 501 502 503 |
# File 'lib/octokit/client/organizations.rb', line 500 def team_membership(team_id, user, = {}) = ensure_org_invitations_api_media_type() get "teams/#{team_id}/memberships/#{user}", end |
#team_repositories(team_id, options = {}) ⇒ Array<Sawyer::Resource> Also known as: team_repos
List team repositories
Requires authenticated organization member.
369 370 371 |
# File 'lib/octokit/client/organizations.rb', line 369 def team_repositories(team_id, = {}) paginate "teams/#{team_id}/repos", end |
#team_repository?(team_id, repo, options = {}) ⇒ Boolean Also known as: team_repo?
Check if a repo is managed by a specific team
386 387 388 |
# File 'lib/octokit/client/organizations.rb', line 386 def team_repository?(team_id, repo, = {}) boolean_from_response :get, "teams/#{team_id}/repos/#{Repository.new(repo)}" end |
#unpublicize_membership(org, user, options = {}) ⇒ Boolean Also known as: conceal_membership
Conceal a user’s membership of an organization.
Requires authenticated organization owner.
476 477 478 |
# File 'lib/octokit/client/organizations.rb', line 476 def unpublicize_membership(org, user, = {}) boolean_from_response :delete, "#{Organization.path org}/public_members/#{user}", end |
#update_organization(org, values, options = {}) ⇒ Sawyer::Resource Also known as: update_org
Update an organization.
Requires authenticated client with proper organization permissions.
48 49 50 |
# File 'lib/octokit/client/organizations.rb', line 48 def update_organization(org, values, = {}) patch Organization.path(org), .merge({:organization => values}) end |
#update_team(team_id, options = {}) ⇒ Sawyer::Resource
Update team
Requires authenticated organization owner.
266 267 268 |
# File 'lib/octokit/client/organizations.rb', line 266 def update_team(team_id, = {}) patch "teams/#{team_id}", end |
#user_teams(options = {}) ⇒ Array<Sawyer::Resource>
List all teams for the authenticated user across all their orgs
485 486 487 |
# File 'lib/octokit/client/organizations.rb', line 485 def user_teams( = {}) paginate "/user/teams", end |