Module: Octokit::Client::Organizations
- Included in:
- Octokit::Client
- Defined in:
- lib/octokit/client/organizations.rb
Overview
Methods for the Organizations API
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.
-
#all_organizations(options = {}) ⇒ Array<Sawyer::Resource>
(also: #all_orgs)
List all GitHub organizations.
-
#child_teams(team_id, options = {}) ⇒ Sawyer::Resource
List child teams.
-
#convert_to_outside_collaborator(org, user, options = {}) ⇒ Boolean
Converts an organization member to an outside collaborator.
-
#create_team(org, options = {}) ⇒ Sawyer::Resource
Create team.
-
#delete_migration_archive(org, id, options = {}) ⇒ Object
Deletes a previous migration archive.
-
#delete_team(team_id, options = {}) ⇒ Boolean
Delete team.
-
#migration_archive_url(org, id, options = {}) ⇒ Object
Fetches the URL to a migration archive.
-
#migration_status(org, id, options = {}) ⇒ Object
Fetches the status of a migration.
-
#migrations(org, options = {}) ⇒ Array<Sawyer::Resource>
Lists the most recent migrations.
-
#organization(org, options = {}) ⇒ Sawyer::Resource
(also: #org)
Get an organization.
-
#organization_invitations(org, options = {}) ⇒ Array<Sawyer::Resource>
(also: #org_invitations)
List pending organization invitations.
-
#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_membership(org, options = {}) ⇒ Sawyer::Resource
(also: #org_membership)
Get an organization membership.
-
#organization_memberships(options = {}) ⇒ Array<Sawyer::Resource>
(also: #org_memberships)
List all organizations memberships for the authenticated user.
-
#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.
-
#outside_collaborators(org, options = {}) ⇒ Array<Sawyer::Resource>
List outside collaborators for an organization.
-
#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_organization_membership(org, options = {}) ⇒ Boolean
(also: #remove_org_membership)
Remove an organization membership.
-
#remove_outside_collaborator(org, user, options = {}) ⇒ Boolean
Remove outside collaborator from an organization.
-
#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.
-
#start_migration(org, repositories, options = {}) ⇒ Sawyer::Resource
Initiates the generation of a migration archive.
-
#team(team_id, options = {}) ⇒ Sawyer::Resource
Get team.
-
#team_by_name(org, team_slug, options = {}) ⇒ Sawyer::Resource
Get team by name and org.
-
#team_invitations(team_id, options = {}) ⇒ Array<Sawyer::Resource>
List pending team invitations.
-
#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.
-
#unlock_repository(org, id, repo, options = {}) ⇒ Object
Unlock a previous migration archive.
-
#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_organization_membership(org, options = {}) ⇒ Sawyer::Resource
(also: #update_org_membership)
Edit an organization membership.
-
#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.
428 429 430 431 432 433 |
# File 'lib/octokit/client/organizations.rb', line 428 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
649 650 651 |
# File 'lib/octokit/client/organizations.rb', line 649 def add_team_membership(team_id, user, = {}) put "teams/#{team_id}/memberships/#{user}", end |
#add_team_repository(team_id, repo, options = {}) ⇒ Boolean Also known as: add_team_repo
Add team repository
This can also be used to update the permission of an existing team
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.
540 541 542 |
# File 'lib/octokit/client/organizations.rb', line 540 def add_team_repository(team_id, repo, = {}) boolean_from_response :put, "teams/#{team_id}/repos/#{Repository.new(repo)}", end |
#all_organizations(options = {}) ⇒ Array<Sawyer::Resource> Also known as: all_orgs
List all GitHub organizations
This provides a list of every organization, in the order that they were created.
Organization that you’ve seen.
100 101 102 |
# File 'lib/octokit/client/organizations.rb', line 100 def all_organizations( = {}) paginate "organizations", end |
#child_teams(team_id, options = {}) ⇒ Sawyer::Resource
List child teams
Requires authenticated organization member.
350 351 352 353 |
# File 'lib/octokit/client/organizations.rb', line 350 def child_teams(team_id, = {}) = ensure_api_media_type(:nested_teams, ) paginate "teams/#{team_id}/teams", end |
#convert_to_outside_collaborator(org, user, options = {}) ⇒ Boolean
Converts an organization member to an outside collaborator
Requires authenticated organization members.
268 269 270 |
# File 'lib/octokit/client/organizations.rb', line 268 def convert_to_outside_collaborator(org, user, ={}) boolean_from_response :put, "#{Organization.path org}/outside_collaborators/#{user}", end |
#create_team(org, options = {}) ⇒ Sawyer::Resource
Create team
Requires authenticated organization owner.
304 305 306 307 308 309 310 311 312 |
# File 'lib/octokit/client/organizations.rb', line 304 def create_team(org, = {}) if .key?(:permission) octokit_warn "Deprecated: Passing :permission option to #create_team. Assign team repository permission by passing :permission to #add_team_repository instead." end if .key?(:parent_team_id) = ensure_api_media_type(:nested_teams, ) end post "#{Organization.path org}/teams", end |
#delete_migration_archive(org, id, options = {}) ⇒ Object
Deletes a previous migration archive.
Requires authenticated organization owner.
787 788 789 790 |
# File 'lib/octokit/client/organizations.rb', line 787 def delete_migration_archive(org, id, = {}) = ensure_api_media_type(:migrations, ) delete "orgs/#{org}/migrations/#{id}/archive", end |
#delete_team(team_id, options = {}) ⇒ Boolean
Delete team
Requires authenticated organization owner.
390 391 392 |
# File 'lib/octokit/client/organizations.rb', line 390 def delete_team(team_id, = {}) boolean_from_response :delete, "teams/#{team_id}", end |
#migration_archive_url(org, id, options = {}) ⇒ Object
Fetches the URL to a migration archive.
Requires authenticated organization owner.
772 773 774 775 776 777 778 |
# File 'lib/octokit/client/organizations.rb', line 772 def migration_archive_url(org, id, = {}) = ensure_api_media_type(:migrations, ) url = "orgs/#{org}/migrations/#{id}/archive" response = client_without_redirects().get(url) response.headers['location'] end |
#migration_status(org, id, options = {}) ⇒ Object
Fetches the status of a migration.
Requires authenticated organization owner.
760 761 762 763 |
# File 'lib/octokit/client/organizations.rb', line 760 def migration_status(org, id, = {}) = ensure_api_media_type(:migrations, ) get "orgs/#{org}/migrations/#{id}", end |
#migrations(org, options = {}) ⇒ Array<Sawyer::Resource>
Lists the most recent migrations.
Requires authenticated organization owner.
748 749 750 751 |
# File 'lib/octokit/client/organizations.rb', line 748 def migrations(org, = {}) = ensure_api_media_type(:migrations, ) paginate "orgs/#{org}/migrations", end |
#organization(org, options = {}) ⇒ Sawyer::Resource Also known as: org
Get an organization
18 19 20 |
# File 'lib/octokit/client/organizations.rb', line 18 def organization(org, = {}) get Organization.path(org), end |
#organization_invitations(org, options = {}) ⇒ Array<Sawyer::Resource> Also known as: org_invitations
List pending organization invitations
Requires authenticated organization member.
223 224 225 |
# File 'lib/octokit/client/organizations.rb', line 223 def organization_invitations(org, = {}) get "#{Organization.path org}/invitations", 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.
183 184 185 186 187 188 189 190 |
# File 'lib/octokit/client/organizations.rb', line 183 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.
144 145 146 147 148 |
# File 'lib/octokit/client/organizations.rb', line 144 def organization_members(org, = {}) = .dup path = "public_" if .delete(:public) paginate "#{Organization.path org}/#{path}members", end |
#organization_membership(org, options = {}) ⇒ Sawyer::Resource Also known as: org_membership
Get an organization membership
681 682 683 684 685 686 687 688 |
# File 'lib/octokit/client/organizations.rb', line 681 def organization_membership(org, = {}) = .dup if user = .delete(:user) get "#{Organization.path(org)}/memberships/#{user}", else get "user/memberships/orgs/#{org}", end end |
#organization_memberships(options = {}) ⇒ Array<Sawyer::Resource> Also known as: org_memberships
List all organizations memberships for the authenticated user
669 670 671 |
# File 'lib/octokit/client/organizations.rb', line 669 def organization_memberships( = {}) paginate "user/memberships/orgs", 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.
208 209 210 |
# File 'lib/octokit/client/organizations.rb', line 208 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
162 163 164 |
# File 'lib/octokit/client/organizations.rb', line 162 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.
125 126 127 |
# File 'lib/octokit/client/organizations.rb', line 125 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.
283 284 285 |
# File 'lib/octokit/client/organizations.rb', line 283 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.
81 82 83 |
# File 'lib/octokit/client/organizations.rb', line 81 def organizations(user=nil, = {}) paginate "#{User.path user}/orgs", end |
#outside_collaborators(org, options = {}) ⇒ Array<Sawyer::Resource>
List outside collaborators for an organization
Requires authenticated organization members.
238 239 240 |
# File 'lib/octokit/client/organizations.rb', line 238 def outside_collaborators(org, ={}) get "#{Organization.path org}/outside_collaborators", end |
#publicize_membership(org, user, options = {}) ⇒ Boolean
Publicize a user’s membership of an organization
Requires authenticated organization owner.
594 595 596 |
# File 'lib/octokit/client/organizations.rb', line 594 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.
577 578 579 580 581 |
# File 'lib/octokit/client/organizations.rb', line 577 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_organization_membership(org, options = {}) ⇒ Boolean Also known as: remove_org_membership
Remove an organization membership
717 718 719 720 721 |
# File 'lib/octokit/client/organizations.rb', line 717 def remove_organization_membership(org, = {}) = .dup user = .delete(:user) user && boolean_from_response(:delete, "orgs/#{org}/memberships/#{user}", ) end |
#remove_outside_collaborator(org, user, options = {}) ⇒ Boolean
Remove outside collaborator from an organization
Requires authenticated organization members.
253 254 255 |
# File 'lib/octokit/client/organizations.rb', line 253 def remove_outside_collaborator(org, user, ={}) boolean_from_response :delete, "#{Organization.path org}/outside_collaborators/#{user}", end |
#remove_team_member(team_id, user, options = {}) ⇒ Boolean
Remove team member
Requires authenticated organization owner or member with team ‘admin` permission.
446 447 448 |
# File 'lib/octokit/client/organizations.rb', line 446 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
661 662 663 |
# File 'lib/octokit/client/organizations.rb', line 661 def remove_team_membership(team_id, user, = {}) 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.
560 561 562 |
# File 'lib/octokit/client/organizations.rb', line 560 def remove_team_repository(team_id, repo, = {}) boolean_from_response :delete, "teams/#{team_id}/repos/#{Repository.new(repo)}" end |
#start_migration(org, repositories, options = {}) ⇒ Sawyer::Resource
Initiates the generation of a migration archive.
Requires authenticated organization owner.
735 736 737 738 739 |
# File 'lib/octokit/client/organizations.rb', line 735 def start_migration(org, repositories, = {}) = ensure_api_media_type(:migrations, ) [:repositories] = repositories post "orgs/#{org}/migrations", end |
#team(team_id, options = {}) ⇒ Sawyer::Resource
Get team
Requires authenticated organization member.
323 324 325 |
# File 'lib/octokit/client/organizations.rb', line 323 def team(team_id, = {}) get "teams/#{team_id}", end |
#team_by_name(org, team_slug, options = {}) ⇒ Sawyer::Resource
Get team by name and org
Requires authenticated organization member.
337 338 339 |
# File 'lib/octokit/client/organizations.rb', line 337 def team_by_name(org, team_slug, = {}) get "#{Organization.path(org)}/teams/#{team_slug}", end |
#team_invitations(team_id, options = {}) ⇒ Array<Sawyer::Resource>
List pending team invitations
Requires authenticated organization member.
479 480 481 |
# File 'lib/octokit/client/organizations.rb', line 479 def team_invitations(team_id, = {}) get "teams/#{team_id}/invitations", 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.
465 466 467 |
# File 'lib/octokit/client/organizations.rb', line 465 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.
403 404 405 |
# File 'lib/octokit/client/organizations.rb', line 403 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.
634 635 636 |
# File 'lib/octokit/client/organizations.rb', line 634 def team_membership(team_id, user, = {}) 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.
494 495 496 |
# File 'lib/octokit/client/organizations.rb', line 494 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
511 512 513 |
# File 'lib/octokit/client/organizations.rb', line 511 def team_repository?(team_id, repo, = {}) boolean_from_response :get, "teams/#{team_id}/repos/#{Repository.new(repo)}" end |
#unlock_repository(org, id, repo, options = {}) ⇒ Object
Unlock a previous migration archive.
Requires authenticated organization owner.
800 801 802 803 |
# File 'lib/octokit/client/organizations.rb', line 800 def unlock_repository(org, id, repo, = {}) = ensure_api_media_type(:migrations, ) delete "orgs/#{org}/migrations/#{id}/repos/#{repo}/lock", end |
#unpublicize_membership(org, user, options = {}) ⇒ Boolean Also known as: conceal_membership
Conceal a user’s membership of an organization.
Requires authenticated organization owner.
610 611 612 |
# File 'lib/octokit/client/organizations.rb', line 610 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(values) end |
#update_organization_membership(org, options = {}) ⇒ Sawyer::Resource Also known as: update_org_membership
Edit an organization membership
700 701 702 703 704 705 706 707 708 709 |
# File 'lib/octokit/client/organizations.rb', line 700 def update_organization_membership(org, = {}) = .dup if user = .delete(:user) .delete(:state) put "orgs/#{org}/memberships/#{user}", else .delete(:role) patch "user/memberships/orgs/#{org}", end end |
#update_team(team_id, options = {}) ⇒ Sawyer::Resource
Update team
Requires authenticated organization owner.
374 375 376 377 378 379 |
# File 'lib/octokit/client/organizations.rb', line 374 def update_team(team_id, = {}) if .key?(:parent_team_id) = ensure_api_media_type(:nested_teams, ) end patch "teams/#{team_id}", end |
#user_teams(options = {}) ⇒ Array<Sawyer::Resource>
List all teams for the authenticated user across all their orgs
619 620 621 |
# File 'lib/octokit/client/organizations.rb', line 619 def user_teams( = {}) paginate "user/teams", end |