Organization

This section of the documentation covers:

Organization Objects

class github3.orgs.Organization(org, session=None)

The Organization object.

Two organization instances can be checked like so:

o1 == o2
o1 != o2

And is equivalent to:

o1.id == o2.id
o1.id != o2.id

See also: http://developer.github.com/v3/orgs/

add_member(login, team)

Add login to team and thereby to this organization.

Warning

This method is no longer valid. To add a member to a team, you must now retrieve the team directly, and use the invite method.

Any user that is to be added to an organization, must be added to a team as per the GitHub api.

Note

This method is of complexity O(n). This iterates over all teams in your organization and only adds the user when the team name matches the team parameter above. If you want constant time, you should retrieve the team and call add_member on that team directly.

Parameters:
  • login (str) – (required), login name of the user to be added
  • team (str) – (required), team name
Returns:

bool

add_repo(repo, team)

Add repo to team.

Note

This method is of complexity O(n). This iterates over all teams in your organization and only adds the repo when the team name matches the team parameter above. If you want constant time, you should retrieve the team and call add_repo on that team directly.

Parameters:
  • repo (str) – (required), form: ‘user/repo’
  • team (str) – (required), team name
conceal_member(login)

Conceal login‘s membership in this organization.

Returns:bool
create_repo(name, description=u'', homepage=u'', private=False, has_issues=True, has_wiki=True, has_downloads=True, team_id=0, auto_init=False, gitignore_template=u'')

Create a repository for this organization if the authenticated user is a member.

Parameters:
  • name (str) – (required), name of the repository
  • description (str) – (optional)
  • homepage (str) – (optional)
  • private (bool) – (optional), If True, create a private repository. API default: False
  • has_issues (bool) – (optional), If True, enable issues for this repository. API default: True
  • has_wiki (bool) – (optional), If True, enable the wiki for this repository. API default: True
  • has_downloads (bool) – (optional), If True, enable downloads for this repository. API default: True
  • team_id (int) – (optional), id of the team that will be granted access to this repository
  • auto_init (bool) – (optional), auto initialize the repository.
  • gitignore_template (str) – (optional), name of the template; this is ignored if auto_int = False.
Returns:

Repository

create_team(name, repo_names=[], permission=u'')

Assuming the authenticated user owns this organization, create and return a new team.

Parameters:
  • name (str) – (required), name to be given to the team
  • repo_names (list) – (optional) repositories, e.g. [‘github/dotfiles’]
  • permission (str) –

    (optional), options:

    • pull – (default) members can not push or administer
      repositories accessible by this team
    • push – members can push and pull but not administer
      repositories accessible by this team
    • admin – members can push, pull and administer
      repositories accessible by this team
Returns:

Team

edit(billing_email=None, company=None, email=None, location=None, name=None)

Edit this organization.

Parameters:
  • billing_email (str) – (optional) Billing email address (private)
  • company (str) – (optional)
  • email (str) – (optional) Public email address
  • location (str) – (optional)
  • name (str) – (optional)
Returns:

bool

events_url = None

Events url (not a template)

from_json(json)

Return an instance of cls formed from json.

is_member(login)

Check if the user with login login is a member.

Returns:bool
is_public_member(login)

Check if the user with login login is a public member.

Returns:bool
iter_events(number=-1, etag=None)

Iterate over events for this org.

Parameters:
  • number (int) – (optional), number of events to return. Default: -1 iterates over all events available.
  • etag (str) – (optional), ETag from a previous request to the same endpoint
Returns:

generator of Events

iter_members(number=-1, etag=None)

Iterate over members of this organization.

Parameters:
  • number (int) – (optional), number of members to return. Default: -1 will return all available.
  • etag (str) – (optional), ETag from a previous request to the same endpoint
Returns:

generator of Users

iter_public_members(number=-1, etag=None)

Iterate over public members of this organization.

Parameters:
  • number (int) – (optional), number of members to return. Default: -1 will return all available.
  • etag (str) – (optional), ETag from a previous request to the same endpoint
Returns:

generator of Users

iter_repos(type=u'', number=-1, etag=None)

Iterate over repos for this organization.

Parameters:
  • type (str) – (optional), accepted values: (‘all’, ‘public’, ‘member’, ‘private’, ‘forks’, ‘sources’), API default: ‘all’
  • number (int) – (optional), number of members to return. Default: -1 will return all available.
  • etag (str) – (optional), ETag from a previous request to the same endpoint
Returns:

generator of Repository

iter_teams(number=-1, etag=None)

Iterate over teams that are part of this organization.

Parameters:
  • number (int) – (optional), number of teams to return. Default: -1 returns all available teams.
  • etag (str) – (optional), ETag from a previous request to the same endpoint
Returns:

generator of Teams

members_urlt = None

Members URL Template. Expands with member

private_repos = None

Number of private repositories.

public_members_urlt = None

Public Members URL Template. Expands with member

publicize_member(login)

Make login‘s membership in this organization public.

Returns:bool
ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns:int
refresh(conditional=False)

Re-retrieve the information for this object and returns the refreshed instance.

Parameters:conditional (bool) – If True, then we will search for a stored header (‘Last-Modified’, or ‘ETag’) on the object and send that as described in the Conditional Requests section of the docs
Returns:self

The reasoning for the return value is the following example:

repos = [r.refresh() for r in g.iter_repos('kennethreitz')]

Without the return value, that would be an array of None‘s and you would otherwise have to do:

repos = [r for i in g.iter_repos('kennethreitz')]
[r.refresh() for r in repos]

Which is really an anti-pattern.

Changed in version 0.5.

remove_member(login)

Remove the user with login login from this organization.

Returns:bool
remove_repo(repo, team)

Remove repo from team.

Parameters:
  • repo (str) – (required), form: ‘user/repo’
  • team (str) – (required)
Returns:

bool

repos_url = None

Repositories url (not a template)

team(team_id)

Returns Team object with information about team specified by team_id.

Parameters:team_id (int) – (required), unique id for the team
Returns:Team
to_json()

Return the json representing this object.


class github3.orgs.Team(team, session=None)

The Team object.

Two team instances can be checked like so:

t1 == t2
t1 != t2

And is equivalent to:

t1.id == t2.id
t1.id != t2.id

See also: http://developer.github.com/v3/orgs/teams/

add_member(login)

Add login to this team.

Returns:bool
add_repo(repo)

Add repo to this team.

Parameters:repo (str) – (required), form: ‘user/repo’
Returns:bool
delete()

Delete this team.

Returns:bool
edit(name, permission=u'')

Edit this team.

Parameters:
  • name (str) – (required)
  • permission (str) – (optional), (‘pull’, ‘push’, ‘admin’)
Returns:

bool

from_json(json)

Return an instance of cls formed from json.

has_repo(repo)

Checks if this team has access to repo

Parameters:repo (str) – (required), form: ‘user/repo’
Returns:bool
id = None

Unique ID of the team.

invite(username)

Invite the user to join this team.

This returns a dictionary like so:

{'state': 'pending', 'url': 'https://api.github.com/teams/...'}
Parameters:username (str) – (required), user to invite to join this team.
Returns:dictionary
is_member(login)

Check if login is a member of this team.

Parameters:login (str) – (required), login name of the user
Returns:bool
iter_members(filter=None, number=-1, etag=None)

Iterate over the members of this team.

Parameters:
  • filter (str) – (optional), filter members returned by this method. Can be one of: "2fa_disabled", "all". Default: "all". Filtering by "2fa_disabled" is only available for owners of organizations which have private repositories.
  • number (int) – (optional), number of users to iterate over. Default: -1 iterates over all values
  • etag (str) – (optional), ETag from a previous request to the same endpoint
Returns:

generator of Users

iter_repos(number=-1, etag=None)

Iterate over the repositories this team has access to.

Parameters:
  • number (int) – (optional), number of repos to iterate over. Default: -1 iterates over all values
  • etag (str) – (optional), ETag from a previous request to the same endpoint
Returns:

generator of Repository objects

members_count = None

Number of members in this team.

members_urlt = None

Members URL Template. Expands with member

membership_for(username)

Retrieve the membership information for the user.

Parameters:username (str) – (required), name of the user
Returns:dictionary
name = None

This team’s name.

permission = None

Permission leve of the group

ratelimit_remaining

Number of requests before GitHub imposes a ratelimit.

Returns:int
refresh(conditional=False)

Re-retrieve the information for this object and returns the refreshed instance.

Parameters:conditional (bool) – If True, then we will search for a stored header (‘Last-Modified’, or ‘ETag’) on the object and send that as described in the Conditional Requests section of the docs
Returns:self

The reasoning for the return value is the following example:

repos = [r.refresh() for r in g.iter_repos('kennethreitz')]

Without the return value, that would be an array of None‘s and you would otherwise have to do:

repos = [r for i in g.iter_repos('kennethreitz')]
[r.refresh() for r in repos]

Which is really an anti-pattern.

Changed in version 0.5.

remove_member(login)

Remove login from this team.

Parameters:login (str) – (required), login of the member to remove
Returns:bool
remove_repo(repo)

Remove repo from this team.

Parameters:repo (str) – (required), form: ‘user/repo’
Returns:bool
repos_count = None

Number of repos owned by this team.

repositories_url = None

Repositories url (not a template)

revoke_membership(username)

Revoke this user’s team membership.

Parameters:username (str) – (required), name of the team member
Returns:bool
to_json()

Return the json representing this object.