Module: Octokit::Client::Organizations

Included in:
Octokit::Client
Defined in:
lib/octokit/client/organizations.rb

Overview

Methods for the Organizations API

See Also:

Constant Summary

ORG_INVITATIONS_PREVIEW_MEDIA_TYPE =
"application/vnd.github.the-wasp-preview+json".freeze

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) add_team_member(team_id, user, options = {})

Add team member

Requires authenticated organization owner or member with team `admin` permission.

Examples:

@client.add_team_member(100000, 'pengwynn')
# Opt-in to future behavior for this endpoint. Adds the member to the
# team if they're already an org member. If not, the method will return
# 422 and indicate the user should call the new Team Membership endpoint.
@client.add_team_member \
  100000,
  'pengwynn',
  :accept => "application/vnd.github.the-wasp-preview+json"

See Also:



317
318
319
320
321
322
# File 'lib/octokit/client/organizations.rb', line 317

def add_team_member(team_id, user, options = {})
  # 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}", options.merge({:name => user})
end

- (Sawyer::Resource) add_team_membership(team_id, user, options = {})

Add or invite a user to a team

Examples:

Check if a user has a membership for a team

@client.add_team_membership(1234, 'pengwynn')

See Also:



516
517
518
519
# File 'lib/octokit/client/organizations.rb', line 516

def add_team_membership(team_id, user, options = {})
  options = ensure_org_invitations_api_media_type(options)
  put "teams/#{team_id}/memberships/#{user}", options
end

- (Boolean) add_team_repository(team_id, repo, options = {}) 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.

Examples:

@client.add_team_repository(100000, 'github/developer.github.com')
@client.add_team_repo(100000, 'github/developer.github.com')

See Also:



406
407
408
# File 'lib/octokit/client/organizations.rb', line 406

def add_team_repository(team_id, repo, options = {})
  boolean_from_response :put, "teams/#{team_id}/repos/#{Repository.new(repo)}", options.merge(:name => Repository.new(repo))
end

- (Sawyer::Resource) create_team(org, options = {})

Create team

Requires authenticated organization owner.

Examples:

@client.create_team('github', {
  :name => 'Designers',
  :repo_names => ['github/dotfiles'],
  :permission => 'push'
})

Options Hash (options):

  • :name (String)

    Team name.

  • :repo_names (Array<String>)

    Repositories for the team.

  • :permission (String, optional) — default: 'pull'

    Permissions the team has for team repositories.

    `pull` - team members can pull, but not push to or administer these repositories. `push` - team members can pull and push, but not administer these repositories. `admin` - team members can pull, push and administer these repositories.

See Also:



231
232
233
# File 'lib/octokit/client/organizations.rb', line 231

def create_team(org, options = {})
  post "#{Organization.path org}/teams", options
end

- (Boolean) delete_team(team_id, options = {})

Delete team

Requires authenticated organization owner.

Examples:

@client.delete_team(100000)

See Also:



279
280
281
# File 'lib/octokit/client/organizations.rb', line 279

def delete_team(team_id, options = {})
  boolean_from_response :delete, "teams/#{team_id}", options
end

- (Sawyer::Resource) organization(org, options = {}) Also known as: org

Get an organization

Examples:

Octokit.organization('github')
Octokit.org('github')

See Also:



20
21
22
# File 'lib/octokit/client/organizations.rb', line 20

def organization(org, options = {})
  get Organization.path(org), options
end

- (Boolean) organization_member?(org, user, options = {}) 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.

Examples:

Check if a user is in your organization

@client.organization_member?('your_organization', 'pengwynn')
=> false

See Also:



164
165
166
167
168
169
170
171
# File 'lib/octokit/client/organizations.rb', line 164

def organization_member?(org, user, options = {})
  result = boolean_from_response(:get, "#{Organization.path org}/members/#{user}", options)
  if !result && last_response && last_response.status == 302
    boolean_from_response :get, last_response.headers['Location']
  else
    result
  end
end

- (Array<Sawyer::Resource>) organization_members(org, options = {}) 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.

Examples:

Octokit.organization_members('github')
Octokit.org_members('github')

See Also:



126
127
128
129
# File 'lib/octokit/client/organizations.rb', line 126

def organization_members(org, options = {})
  path = "public_" if options.delete(:public)
  paginate "#{Organization.path org}/#{path}members", options
end

- (Boolean) organization_public_member?(org, user, options = {}) 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.

Examples:

Check if a user is a hubbernaut

@client.organization_public_member?('github', 'pengwynn')
=> true

See Also:



189
190
191
# File 'lib/octokit/client/organizations.rb', line 189

def organization_public_member?(org, user, options = {})
  boolean_from_response :get, "#{Organization.path org}/public_members/#{user}", options
end

- (Array<Sawyer::Resource>) organization_public_members(org, options = {}) Also known as: org_public_members

Get organization public members

Lists the public members of an organization

Examples:

Octokit.organization_public_members('github')
Octokit.org_public_members('github')

See Also:



143
144
145
# File 'lib/octokit/client/organizations.rb', line 143

def organization_public_members(org, options = {})
  organization_members org, options.merge(:public => true)
end

- (Array<Sawyer::Resource>) organization_repositories(org, options = {}) Also known as: org_repositories, org_repos

List organization repositories

Public repositories are available without authentication. Private repos require authenticated organization member.

Examples:

Octokit.organization_repositories('github')
Octokit.org_repositories('github')
Octokit.org_repos('github')
@client.org_repos('github', {:type => 'private'})

Options Hash (options):

  • :type (String) — default: 'all'

    Filter by repository type. `all`, `public`, `member`, `sources`, `forks`, or `private`.

See Also:



107
108
109
# File 'lib/octokit/client/organizations.rb', line 107

def organization_repositories(org, options = {})
  paginate "#{Organization.path org}/repos", options
end

- (Array<Sawyer::Resource>) organization_teams(org, options = {}) Also known as: org_teams

List teams

Requires authenticated organization member.

Examples:

@client.organization_teams('github')
@client.org_teams('github')

See Also:



205
206
207
# File 'lib/octokit/client/organizations.rb', line 205

def organization_teams(org, options = {})
  paginate "#{Organization.path org}/teams", options
end

- (Array<Sawyer::Resource>) organizations(user = nil, options = {}) 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.

Examples:

Octokit.organizations('pengwynn')
@client.organizations('pengwynn')
Octokit.orgs('pengwynn')
Octokit.list_organizations('pengwynn')
Octokit.list_orgs('pengwynn')
@client.organizations

See Also:



80
81
82
# File 'lib/octokit/client/organizations.rb', line 80

def organizations(user=nil, options = {})
  get "#{User.path user}/orgs", options
end

- (Boolean) publicize_membership(org, user, options = {})

Publicize a user's membership of an organization

Requires authenticated organization owner.

Examples:

@client.publicize_membership('github', 'pengwynn')

See Also:



460
461
462
# File 'lib/octokit/client/organizations.rb', line 460

def publicize_membership(org, user, options = {})
  boolean_from_response :put, "#{Organization.path org}/public_members/#{user}", options
end

- (Boolean) remove_organization_member(org, user, options = {}) Also known as: remove_org_member

Remove organization member

Requires authenticated organization owner or member with team `admin` access.

Examples:

@client.remove_organization_member('github', 'pengwynn')
@client.remove_org_member('github', 'pengwynn')

See Also:



443
444
445
446
447
# File 'lib/octokit/client/organizations.rb', line 443

def remove_organization_member(org, user, options = {})
  # 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}", options
end

- (Boolean) remove_team_member(team_id, user, options = {})

Remove team member

Requires authenticated organization owner or member with team `admin` permission.

Examples:

@client.remove_team_member(100000, 'pengwynn')

See Also:



335
336
337
# File 'lib/octokit/client/organizations.rb', line 335

def remove_team_member(team_id, user, options = {})
  boolean_from_response :delete, "teams/#{team_id}/members/#{user}", options
end

- (Boolean) remove_team_membership(team_id, user, options = {})

Remove team membership

Examples:

@client.remove_team_membership(100000, 'pengwynn')

See Also:



529
530
531
532
# File 'lib/octokit/client/organizations.rb', line 529

def remove_team_membership(team_id, user, options = {})
  options = ensure_org_invitations_api_media_type(options)
  boolean_from_response :delete, "teams/#{team_id}/memberships/#{user}", options
end

- (Boolean) remove_team_repository(team_id, repo, options = {}) Also known as: remove_team_repo

Remove team repository

Removes repository from team. Does not delete the repository.

Requires authenticated organization owner.

Examples:

@client.remove_team_repository(100000, 'github/developer.github.com')
@client.remove_team_repo(100000, 'github/developer.github.com')

See Also:



426
427
428
# File 'lib/octokit/client/organizations.rb', line 426

def remove_team_repository(team_id, repo, options = {})
  boolean_from_response :delete, "teams/#{team_id}/repos/#{Repository.new(repo)}"
end

- (Sawyer::Resource) team(team_id, options = {})

Get team

Requires authenticated organization member.

Examples:

@client.team(100000)

See Also:



244
245
246
# File 'lib/octokit/client/organizations.rb', line 244

def team(team_id, options = {})
  get "teams/#{team_id}", options
end

- (Boolean) team_member?(team_id, user, options = {})

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.

Examples:

Check if a user is in your team

@client.team_member?('your_team', 'pengwynn')
=> false

See Also:



354
355
356
# File 'lib/octokit/client/organizations.rb', line 354

def team_member?(team_id, user, options = {})
  boolean_from_response :get, "teams/#{team_id}/members/#{user}", options
end

- (Array<Sawyer::Resource>) team_members(team_id, options = {})

List team members

Requires authenticated organization member.

Examples:

@client.team_members(100000)

See Also:



292
293
294
# File 'lib/octokit/client/organizations.rb', line 292

def team_members(team_id, options = {})
  paginate "teams/#{team_id}/members", options
end

- (Sawyer::Resource) team_membership(team_id, user, options = {})

Check if a user has a team membership.

Examples:

Check if a user has a membership for a team

@client.team_membership(1234, 'pengwynn')

See Also:



500
501
502
503
# File 'lib/octokit/client/organizations.rb', line 500

def team_membership(team_id, user, options = {})
  options = ensure_org_invitations_api_media_type(options)
  get "teams/#{team_id}/memberships/#{user}", options
end

- (Array<Sawyer::Resource>) team_repositories(team_id, options = {}) Also known as: team_repos

List team repositories

Requires authenticated organization member.

Examples:

@client.team_repositories(100000)
@client.team_repos(100000)

See Also:



369
370
371
# File 'lib/octokit/client/organizations.rb', line 369

def team_repositories(team_id, options = {})
  paginate "teams/#{team_id}/repos", options
end

- (Boolean) team_repository?(team_id, repo, options = {}) Also known as: team_repo?

Check if a repo is managed by a specific team

Examples:

@client.team_repository?(8675309, 'octokit/octokit.rb')
@client.team_repo?(8675309, 'octokit/octokit.rb')

See Also:



386
387
388
# File 'lib/octokit/client/organizations.rb', line 386

def team_repository?(team_id, repo, options = {})
  boolean_from_response :get, "teams/#{team_id}/repos/#{Repository.new(repo)}"
end

- (Boolean) unpublicize_membership(org, user, options = {}) Also known as: conceal_membership

Conceal a user's membership of an organization.

Requires authenticated organization owner.

Examples:

@client.unpublicize_membership('github', 'pengwynn')
@client.conceal_membership('github', 'pengwynn')

See Also:



476
477
478
# File 'lib/octokit/client/organizations.rb', line 476

def unpublicize_membership(org, user, options = {})
  boolean_from_response :delete, "#{Organization.path org}/public_members/#{user}", options
end

- (Sawyer::Resource) update_organization(org, values, options = {}) Also known as: update_org

Update an organization.

Requires authenticated client with proper organization permissions.

Examples:

@client.update_organization('github', {
  :billing_email => 'support@github.com',
  :company => 'GitHub',
  :email => 'support@github.com',
  :location => 'San Francisco',
  :name => 'github'
})
@client.update_org('github', {:company => 'Unicorns, Inc.'})

Options Hash (values):

  • :billing_email (String)

    Billing email address. This address is not publicized.

  • :company (String)

    Company name.

  • :email (String)

    Publicly visible email address.

  • :location (String)

    Location of organization.

  • :name (String)

    GitHub username for organization.

See Also:



48
49
50
# File 'lib/octokit/client/organizations.rb', line 48

def update_organization(org, values, options = {})
  patch Organization.path(org), options.merge({:organization => values})
end

- (Sawyer::Resource) update_team(team_id, options = {})

Update team

Requires authenticated organization owner.

Examples:

@client.update_team(100000, {
  :name => 'Front-end Designers',
  :permission => 'push'
})

Options Hash (options):

  • :name (String)

    Team name.

  • :permission (String)

    Permissions the team has for team repositories.

    `pull` - team members can pull, but not push to or administer these repositories. `push` - team members can pull and push, but not administer these repositories. `admin` - team members can pull, push and administer these repositories.

See Also:



266
267
268
# File 'lib/octokit/client/organizations.rb', line 266

def update_team(team_id, options = {})
  patch "teams/#{team_id}", options
end

- (Array<Sawyer::Resource>) user_teams(options = {})

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(options = {})
  paginate "/user/teams", options
end