Esempio n. 1
0
def create_access_token(username, password, note):
    github_user = Github(username, password).get_user()
    for auth in github_user.get_authorizations():
        if auth.note == note:
            auth.delete()
    return github_user.create_authorization(scopes=['public_repo'],
                                            note=note).token
Esempio n. 2
0
class GithubToken(object):
    def __init__(self, username, password, note, scopes=['public_repo']):
        self.user = Github(username, password).get_user()
        self.note = note
        self.scopes = scopes

    def __enter__(self):
        for auth in self.user.get_authorizations():
            if auth.note == self.note:
                auth.delete()
        self.auth = self.user.create_authorization(scopes=self.scopes,
                                                   note=self.note)
        return self.auth.token

    def __exit__(self, exc_type, exc_value, traceback):
        self.auth.delete()