Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve gh login #614

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Set and store the token to be used for Github auth using:

Alternatively, the token can be set on the GITHUB_TOKEN environment variable.

As a third alternative, if you have the [gh](https://cli.github.com/) client installed
and have authenticated with `gh auth login`, maintainer tools will attempt to obtain the
token from it using `gh auth token`.

### Sync team users from community.odoo.com to GitHub teams

Expand Down
9 changes: 9 additions & 0 deletions tools/github_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import argparse
import os
import subprocess
from getpass import getpass
import github3
from .config import read_config, write_config
Expand All @@ -19,6 +20,14 @@ def login():
else:
config = read_config()
token = config.get("GitHub", "token")
if not token:
try:
# attempt to get token from gh
token = subprocess.check_output(
["gh", "auth", "token"], text=True
).strip()
except subprocess.SubprocessError:
pass
if not token:
raise GitHubLoginError(
"No token has been generated for this script. "
Expand Down
Loading