-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switches to poetry for package management, adds user management, adds…
… command to delete a repository, updates version to 0.1.5
- Loading branch information
1 parent
f23da89
commit 842812b
Showing
24 changed files
with
968 additions
and
616 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,5 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
.vscode/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from autorepo.commands import autorepo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import getpass | ||
|
||
import click | ||
from github import BadCredentialsException, Github | ||
|
||
from autorepo.utils import (add_user, delete_auth_token, get_current_user, | ||
remove_user, set_auth_token, set_current_user, | ||
token_exists) | ||
|
||
|
||
@click.command( | ||
name="login", | ||
help="Log in to GitHub using a Personal Access Token" | ||
) | ||
def login_cmd(): | ||
click.echo("Please enter your GitHub Personal Access Token") | ||
token = getpass.getpass(prompt="Token: ") | ||
|
||
try: | ||
gh = Github(token) | ||
username = gh.get_user().login | ||
except BadCredentialsException: | ||
click.echo("Invalid token", err=True) | ||
|
||
return | ||
|
||
set_auth_token(username, token) | ||
|
||
click.echo(f"Logged in as {username}") | ||
|
||
add_user(username) | ||
set_current_user(username) | ||
|
||
click.echo(f"{username} is now the current user") | ||
|
||
|
||
@click.command( | ||
name="logout", | ||
help="Log the current user out of GitHub" | ||
) | ||
def logout_cmd(): | ||
current_user = get_current_user() | ||
if not current_user: | ||
click.echo("You are not logged in to any GitHub account", err=True) | ||
|
||
return | ||
|
||
delete_auth_token(current_user) | ||
remove_user(current_user) | ||
|
||
click.echo(f"Logged out of {current_user}") | ||
|
||
|
||
@click.command( | ||
name="current-user", | ||
help="Show the current GitHub user" | ||
) | ||
def current_user_cmd(): | ||
current_user = get_current_user() | ||
if not current_user: | ||
click.echo("You are not logged in to any GitHub account", err=True) | ||
|
||
return | ||
|
||
click.echo(current_user) | ||
|
||
|
||
@click.command( | ||
name="switch-user", | ||
help="Switch the current GitHub user" | ||
) | ||
@click.argument("username", required=True) | ||
def switch_user_cmd(username): | ||
if not token_exists(username): | ||
click.echo( | ||
f"Please enter your GitHub Personal Access Token for {username}" | ||
) | ||
token = getpass.getpass(prompt="Token: ") | ||
|
||
try: | ||
gh = Github(token) | ||
username = gh.get_user().login | ||
except BadCredentialsException: | ||
click.echo("Invalid token", err=True) | ||
|
||
return | ||
|
||
set_auth_token(username, token) | ||
add_user(username) | ||
|
||
click.echo(f"Logged in as {username}") | ||
|
||
set_current_user(username) | ||
|
||
click.echo(f"Switched to {username} as the current user") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from autorepo.utils.auth import (add_user, delete_auth_token, get_auth_token, | ||
get_current_user, list_users, remove_user, | ||
set_auth_token, set_current_user, | ||
token_exists) | ||
from autorepo.utils.list import (list_gitignore_templates, list_licenses, | ||
list_repositories) | ||
from autorepo.utils.repo import (add_remote, clone_repo, create_repo, | ||
delete_repo, init_repo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import keyring | ||
|
||
|
||
def get_auth_token(username): | ||
return keyring.get_password("autorepo", f"gh_token_{username}") | ||
|
||
|
||
def set_auth_token(username, token): | ||
keyring.set_password("autorepo", f"gh_token_{username}", token) | ||
|
||
|
||
def delete_auth_token(username): | ||
keyring.delete_password("autorepo", f"gh_token_{username}") | ||
|
||
|
||
def set_current_user(username): | ||
keyring.set_password("autorepo", "current_user", username) | ||
|
||
|
||
def get_current_user(): | ||
return keyring.get_password("autorepo", "current_user") | ||
|
||
|
||
def token_exists(username): | ||
return get_auth_token(username) is not None | ||
|
||
|
||
def list_users(): | ||
users = keyring.get_password("autorepo", "all_users") | ||
if users is None: | ||
return [] | ||
|
||
return users.split(";") | ||
|
||
|
||
def add_user(username): | ||
users = list_users() | ||
if username in users: | ||
return | ||
|
||
users.append(username) | ||
|
||
keyring.set_password("autorepo", "all_users", ";".join(users)) | ||
|
||
|
||
def remove_user(username): | ||
users = list_users() | ||
if username not in users: | ||
return | ||
|
||
users.remove(username) | ||
|
||
keyring.set_password("autorepo", "all_users", ";".join(users)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.