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

OCA / maintainer-tools / 11427496596

20 Oct 2024 03:26PM UTC coverage: 34.584% (+0.1%) from 34.457%
11427496596

push

github

web-flow
Merge pull request #634 from acsone/add-ruff

Add basic ruff config

437 of 1197 branches covered (36.51%)

7 of 28 new or added lines in 14 files covered. (25.0%)

10 existing lines in 9 files now uncovered.

645 of 1865 relevant lines covered (34.58%)

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
×
7
import subprocess
×
8
from getpass import getpass
×
9

10
import github3
×
11

UNCOV
12
from .config import read_config, write_config
×
13

14

15
class GitHubLoginError(RuntimeError):
×
16
    pass
×
17

18

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

41

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

53

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

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

69

70
if __name__ == "__main__":
×
71
    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

© 2025 Coveralls, Inc