Ejemplo n.º 1
0
def load_github() -> Github:
    """ Create Github API object """
    if isfile(join(root, 'token.txt')):
        # Get token from file
        with open(join(root, 'token.txt')) as f:
            token = f.read().strip()
        register_git_injector(token, '')
        return Github(token)
    elif os.environ.get('GITHUB_TOKEN'):
        # Get token from environment variable
        token = os.environ['GITHUB_TOKEN']
        register_git_injector(token, '')
        return Github(token)
    elif github_username and github_password:
        # Use credentials entered above
        github = Github(github_username, github_password)
        github.get_user().login
        register_git_injector(github_username, github_password)
        return github
    elif isatty(sys.stdout.fileno()):
        # Interactive
        return ask_for_github_credentials()
    else:
        print('Warning: No authentication. May exceed GitHub rate limit')
        return Github()
Ejemplo n.º 2
0
class GlobalContext:
    lang = Lazy(unset)  # type: str
    msm = Lazy(unset)  # type: MycroftSkillsManager
    use_token = Lazy(unset)  # type: bool
    github = Lazy(
        lambda s: ask_for_github_credentials(s.use_token))  # type: Github
    user = Lazy(lambda s: s.github.get_user())  # type: AuthenticatedUser
Ejemplo n.º 3
0
def load_github() -> Github:
    """Creates Github api object from token.txt, GITHUB_TOKEN variable, or by asking the user"""
    if isfile(join(root, 'token.txt')):
        with open(join(root, 'token.txt')) as f:
            token = f.read().strip()
        register_git_injector(token, '')
        return Github(token)
    elif os.environ.get('GITHUB_TOKEN'):
        token = os.environ['GITHUB_TOKEN']
        register_git_injector(token, '')
        return Github(token)
    elif isatty(sys.stdout.fileno()):
        return ask_for_github_credentials()
    else:
        print('Warning: No authentication. May exceed GitHub rate limit')
        return Github()