Python github3.py() Examples

The following are 4 code examples of github3.py(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module github3 , or try the search function .
Example #1
Source File: file_fetcher.py    From boundary-layer with Apache License 2.0 6 votes vote down vote up
def _get_github(self):
        try:
            import github3
        except ImportError:
            raise Exception("""
            ERROR: github3.py not installed!  Please install via
              pip install boundary-layer[github]
            and try again.""")

        if self.github_url:
            return github3.GitHubEnterprise(
                url=self.github_url,
                username=self.github_username,
                password=self.github_password,
                token=self.github_token)

        return github3.GitHub(
            username=self.github_username,
            password=self.github_password,
            token=self.github_token) 
Example #2
Source File: __init__.py    From scraper with MIT License 6 votes vote down vote up
def create_session(token=None):
    """
    Create a github3.py session connected to GitHub.com

    If token is not provided, will attempt to use the GITHUB_API_TOKEN
    environment variable if present.
    """
    if token is None:
        token = os.environ.get("GITHUB_API_TOKEN", None)

    gh_session = github3.login(token=token)

    if gh_session is None:
        raise RuntimeError("Invalid or missing GITHUB_API_TOKEN")

    return gh_session 
Example #3
Source File: __init__.py    From scraper with MIT License 5 votes vote down vote up
def create_enterprise_session(url, token=None):
    """
    Create a github3.py session for a GitHub Enterprise instance

    If token is not provided, will attempt to use the GITHUB_API_TOKEN
    environment variable if present.
    """

    gh_session = github3.enterprise_login(url=url, token=token)

    if gh_session is None:
        msg = "Unable to connect to GitHub Enterprise (%s) with provided token."
        raise RuntimeError(msg, url)

    return gh_session 
Example #4
Source File: __init__.py    From scraper with MIT License 5 votes vote down vote up
def query_repos(gh_session, orgs=None, repos=None, public_only=True):
    """
    Yields GitHub3.py repo objects for provided orgs and repo names

    If orgs and repos are BOTH empty, execute special mode of getting ALL
    repositories from the GitHub Server.

    If public_only is True, will return only those repos that are marked as
    public. Set this to false to return all organizations that the session has
    permissions to access.
    """

    if orgs is None:
        orgs = []
    if repos is None:
        repos = []
    if public_only:
        privacy = "public"
    else:
        privacy = "all"

    _check_api_limits(gh_session, 10)

    for org_name in orgs:
        org = gh_session.organization(org_name)
        num_repos = org.public_repos_count

        _check_api_limits(gh_session, _num_requests_needed(num_repos))

        for repo in org.repositories(type=privacy):
            _check_api_limits(gh_session, 10)
            yield repo

    for repo_name in repos:
        _check_api_limits(gh_session, 10)
        org, name = repo_name.split("/")
        yield gh_session.repository(org, name)

    if not (orgs or repos):
        for repo in gh_session.all_repositories():
            yield repo