Module: Octokit::Client::Organizations

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

Instance Method Summary collapse

Instance Method Details

#add_team_member(team_id, user, options = {}) ⇒ Boolean

Add team member

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

Examples:

@client.add_team_member(100000, 'pengwynn')

Parameters:

  • team_id (Integer)

    Team id.

  • user (String)

    GitHub username of new team member.

Returns:

  • (Boolean)

    True on successful addition, false otherwise.

See Also:



252
253
254
255
256
257
# File 'lib/octokit/client/organizations.rb', line 252

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.
  put("teams/#{team_id}/members/#{user}", options.merge({:name => user}), 3, true, raw=true).status == 204
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.

Examples:

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

Parameters:

  • team_id (Integer)

    Team id.

  • repo (String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Boolean)

    True if successful, false otherwise.

See Also:



308
309
310
# File 'lib/octokit/client/organizations.rb', line 308

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

#create_team(org, options = {}) ⇒ Hashie::Mash

Create team

Requires authenticated organization owner.

Examples:

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

Parameters:

  • org (String)

    Organization GitHub username.

  • options (Hash) (defaults to: {})

    a customizable set of options

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.

Returns:

  • (Hashie::Mash)

    Hash representing new team.

See Also:



171
172
173
# File 'lib/octokit/client/organizations.rb', line 171

def create_team(org, options={})
  post("orgs/#{org}/teams", options, 3)
end

#delete_team(team_id, options = {}) ⇒ Boolean

Delete team

Requires authenticated organization owner.

Examples:

@client.delete_team(100000)

Parameters:

  • team_id (Integer)

    Team id.

Returns:

  • (Boolean)

    True if deletion successful, false otherwise.

See Also:



222
223
224
# File 'lib/octokit/client/organizations.rb', line 222

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

#organization(org, options = {}) ⇒ Hashie::Mash Also known as: org

Get an organization

Examples:

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

Parameters:

  • org (String)

    Organization GitHub username.

Returns:

  • (Hashie::Mash)

    Hash representing GitHub organization.

See Also:



13
14
15
# File 'lib/octokit/client/organizations.rb', line 13

def organization(org, options={})
  get("orgs/#{org}", options, 3)
end

#organization_members(org, options = {}) ⇒ Array<Hashie::Mash> 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')
@client.organization_members('github')
Octokit.org_members('github')

Parameters:

  • org (String)

    Organization GitHub username.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing users.

See Also:



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

def organization_members(org, options={})
  get("orgs/#{org}/members", options, 3)
end

#organization_repositories(org, options = {}) ⇒ Array<Hashie::Mash> 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'})

Parameters:

  • org (String)

    Organization handle for which to list repos

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

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

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

Returns:

  • (Array<Hashie::Mash>)

    List of repositories

See Also:



105
106
107
# File 'lib/octokit/client/organizations.rb', line 105

def organization_repositories(org, options={})
  get("orgs/#{org}/repos", options, 3)
end

#organization_teams(org, options = {}) ⇒ Array<Hashie::Mash> Also known as: org_teams

List teams

Requires authenticated organization member.

Examples:

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

Parameters:

  • org (String)

    Organization GitHub username.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing teams.

See Also:



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

def organization_teams(org, options={})
  get("orgs/#{org}/teams", options, 3)
end

#organizations(user = nil, options = {}) ⇒ Array<Hashie::Mash> 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

Parameters:

  • user (String) (defaults to: nil)

    Username of the user to get list of organizations.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing organizations.

See Also:



74
75
76
77
78
79
80
# File 'lib/octokit/client/organizations.rb', line 74

def organizations(user=nil, options={})
  if user
    get("users/#{user}/orgs", options, 3)
  else
    get("user/orgs", options, 3)
  end
end

#publicize_membership(org, user, options = {}) ⇒ Boolean

Publicize a user’s membership of an organization

Requires authenticated organization owner.

Examples:

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

Parameters:

  • org (String)

    Organization GitHub username.

  • user (String)

    GitHub username of user to publicize.

Returns:

  • (Boolean)

    True if publicization successful, false otherwise.

See Also:



365
366
367
# File 'lib/octokit/client/organizations.rb', line 365

def publicize_membership(org, user, options={})
  put("orgs/#{org}/public_members/#{user}", options, 3, true, raw=true).status == 204
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.

Examples:

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

Parameters:

  • org (String)

    Organization GitHub username.

  • user (String)

    GitHub username of user to remove.

Returns:

  • (Boolean)

    True if removal is successful, false otherwise.

See Also:



347
348
349
350
351
# File 'lib/octokit/client/organizations.rb', line 347

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
  delete("orgs/#{org}/members/#{user}", options, 3, true, raw=true).status == 204
end

#remove_team_member(team_id, user, options = {}) ⇒ Boolean

Remove team member

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

Examples:

@client.remove_team_member(100000, 'pengwynn')

Parameters:

  • team_id (Integer)

    Team id.

  • user (String)

    GitHub username of the user to boot.

Returns:

  • (Boolean)

    True if user removed, false otherwise.

See Also:



271
272
273
# File 'lib/octokit/client/organizations.rb', line 271

def remove_team_member(team_id, user, options={})
  delete("teams/#{team_id}/members/#{user}", options, 3, true, raw=true).status == 204
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.

Examples:

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

Parameters:

  • team_id (Integer)

    Team id.

  • repo (String, Hash, Repository)

    A GitHub repository.

Returns:

  • (Boolean)

    Return true if repo removed from team, false otherwise.

See Also:



329
330
331
# File 'lib/octokit/client/organizations.rb', line 329

def remove_team_repository(team_id, repo, options={})
  delete("teams/#{team_id}/repos/#{Repository.new(repo)}", options, 3, true, raw=true).status == 204
end

#team(team_id, options = {}) ⇒ Hashie::Mash

Get team

Requires authenticated organization member.

Examples:

@client.team(100000)

Parameters:

  • team_id (Integer)

    Team id.

Returns:

  • (Hashie::Mash)

    Hash representing team.

See Also:



185
186
187
# File 'lib/octokit/client/organizations.rb', line 185

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

#team_members(team_id, options = {}) ⇒ Array<Hashie::Mash>

List team members

Requires authenticated organization member.

Examples:

@client.team_members(100000)

Parameters:

  • team_id (Integer)

    Team id.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing users.

See Also:



236
237
238
# File 'lib/octokit/client/organizations.rb', line 236

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

#team_repositories(team_id, options = {}) ⇒ Array<Hashie::Mash> Also known as: team_repos

List team repositories

Requires authenticated organization member.

Examples:

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

Parameters:

  • team_id (Integer)

    Team id.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing repositories.

See Also:



287
288
289
# File 'lib/octokit/client/organizations.rb', line 287

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

#unpublicize_membership(org, user, options = {}) ⇒ Boolean 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')

Parameters:

  • org (String)

    Organization GitHub username.

  • user (String)

    GitHub username of user to unpublicize.

Returns:

  • (Boolean)

    True of unpublicization successful, false otherwise.

See Also:



382
383
384
# File 'lib/octokit/client/organizations.rb', line 382

def unpublicize_membership(org, user, options={})
  delete("orgs/#{org}/public_members/#{user}", options, 3, true, raw=true).status == 204
end

#update_organization(org, values, options = {}) ⇒ Hashie::Mash Also known as: update_org

Update an organization.

Requires authenticated client with proper organization permissions.

Examples:

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

Parameters:

  • org (String)

    Organization GitHub username.

  • values (Hash)

    The updated organization attributes.

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.

Returns:

  • (Hashie::Mash)

    Hash representing GitHub organization.

See Also:



42
43
44
# File 'lib/octokit/client/organizations.rb', line 42

def update_organization(org, values, options={})
  patch("orgs/#{org}", options.merge({:organization => values}), 3)
end

#update_team(team_id, options = {}) ⇒ Hashie::Mash

Update team

Requires authenticated organization owner.

Examples:

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

Parameters:

  • team_id (Integer)

    Team id.

  • options (Hash) (defaults to: {})

    a customizable set of options

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.

Returns:

  • (Hashie::Mash)

    Hash representing updated team.

See Also:



208
209
210
# File 'lib/octokit/client/organizations.rb', line 208

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