Skip to content
Snippets Groups Projects
Commit fcc591f1 authored by Tulir Asokan's avatar Tulir Asokan :cat2:
Browse files

Make scopes configurable in login command

parent 48226cab
No related branches found
Tags v0.1.0
No related merge requests found
Pipeline #1763 passed
...@@ -100,12 +100,18 @@ class Commands: ...@@ -100,12 +100,18 @@ class Commands:
pass pass
@github.subcommand("login", help="Log into GitHub.") @github.subcommand("login", help="Log into GitHub.")
@command.argument("flags", required=False, pass_raw=True)
@authenticated(required=False) @authenticated(required=False)
async def login(self, evt: MessageEvent, client: Optional[GitHubClient]) -> None: async def login(self, evt: MessageEvent, flags: str, client: Optional[GitHubClient]) -> None:
redirect_url = (self.bot.webapp_url / "auth").with_query({"user_id": evt.sender}) redirect_url = (self.bot.webapp_url / "auth").with_query({"user_id": evt.sender})
flags = flags.lower()
scopes = ["user:user", "public_repo", "admin:repo_hook"]
if "--no-hook" in flags:
scopes.remove("admin:repo_hook")
if "--private" in flags:
scopes.append("repo")
login_url = str(self.bot.clients.get(evt.sender, create=True).get_login_url( login_url = str(self.bot.clients.get(evt.sender, create=True).get_login_url(
redirect_uri=redirect_url, redirect_uri=redirect_url, scope=" ".join(scopes)))
scope="user:user public_repo repo admin:repo_hook"))
if client: if client:
username = await client.query("viewer { login }", path="viewer.login") username = await client.query("viewer { login }", path="viewer.login")
await evt.reply(f"You're already logged in as @{username}, but you can " await evt.reply(f"You're already logged in as @{username}, but you can "
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment