• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OCA / maintainer-tools / 9820650393

06 Jul 2024 04:32PM UTC coverage: 34.457% (-0.1%) from 34.568%
9820650393

push

github

web-flow
Merge pull request #614 from acsone/imp-gh-login

Improve gh login

1174 of 2459 branches covered (47.74%)

0 of 6 new or added lines in 1 file covered. (0.0%)

2 existing lines in 2 files now uncovered.

644 of 1869 relevant lines covered (34.46%)

3.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/tools/github_login.py
1
# -*- coding: utf-8 -*-
2
# License AGPLv3 (https://www.gnu.org/licenses/agpl-3.0-standalone.html)
3
from __future__ import absolute_import, print_function
×
4

5
import argparse
×
6
import os
×
NEW
7
import subprocess
×
8
from getpass import getpass
×
9
import github3
×
10
from .config import read_config, write_config
×
11

12

13
class GitHubLoginError(RuntimeError):
×
14
    pass
×
15

16

17
def login():
×
18
    if os.environ.get("GITHUB_TOKEN"):
×
19
        token = os.environ["GITHUB_TOKEN"]
×
20
    else:
21
        config = read_config()
×
22
        token = config.get("GitHub", "token")
×
NEW
23
        if not token:
×
NEW
24
            try:
×
25
                # attempt to get token from gh
NEW
26
                token = subprocess.check_output(
×
27
                    ["gh", "auth", "token"], text=True
28
                ).strip()
NEW
29
            except subprocess.SubprocessError:
×
NEW
30
                pass
×
31
    if not token:
×
32
        raise GitHubLoginError(
×
33
            "No token has been generated for this script. "
34
            "Please run 'oca-github-login' or set the GITHUB_TOKEN "
35
            "environment variable."
36
        )
37
    return github3.login(token=token)
×
38

39

40
def store_token():
×
41
    config = read_config()
×
42
    if config.get("GitHub", "token"):
×
43
        print("Note: a token already exists and will be replaced.")
×
44
    token = getpass("Enter Github Client Token: ")
×
45
    auth = github3.login(token=token)
×
46
    config.set("GitHub", "token", token)
×
47
    write_config(config)
×
48
    print("Token stored in configuration file.")
×
49
    return auth
×
50

51

52
def main():
×
53
    parser = argparse.ArgumentParser()
×
54
    parser.add_argument(
×
55
        "--test",
56
        action="store_true",
57
        help="Test the Github authentication.",
58
    )
59
    args = parser.parse_args()
×
60

61
    if args.test:
×
62
        auth = login()
×
63
    else:
64
        auth = store_token()
×
65
    print("Authenticated as %s." % auth.me().login)
×
66

67

68
if __name__ == "__main__":
×
69
    main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc