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

OCA / maintainer-tools / 8911974998

01 May 2024 04:24PM UTC coverage: 34.68% (+0.3%) from 34.347%
8911974998

push

github

web-flow
Merge pull request #610 from dreispt/dr-fix-login

[FIX] github_login: token only Github auth

960 of 2068 branches covered (46.42%)

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

1 existing line in 1 file now uncovered.

644 of 1857 relevant lines covered (34.68%)

2.75 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
from getpass import getpass
×
8
import github3
×
9
from .config import read_config, write_config
×
10

11

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

15

16
def login():
×
17
    if os.environ.get("GITHUB_TOKEN"):
×
18
        token = os.environ["GITHUB_TOKEN"]
×
19
    else:
20
        config = read_config()
×
21
        token = config.get("GitHub", "token")
×
22
    if not token:
×
23
        raise GitHubLoginError(
×
24
            "No token has been generated for this script. "
25
            "Please run 'oca-github-login' or set the GITHUB_TOKEN "
26
            "environment variable."
27
        )
28
    return github3.login(token=token)
×
29

30

NEW
31
def store_token():
×
32
    config = read_config()
×
33
    if config.get("GitHub", "token"):
×
NEW
34
        print("Note: a token already exists and will be replaced.")
×
NEW
35
    token = getpass("Enter Github Client Token: ")
×
NEW
36
    auth = github3.login(token=token)
×
NEW
37
    config.set("GitHub", "token", token)
×
38
    write_config(config)
×
NEW
39
    print("Token stored in configuration file.")
×
NEW
40
    return auth
×
41

42

43
def main():
×
44
    parser = argparse.ArgumentParser()
×
NEW
45
    parser.add_argument(
×
46
        "--test",
47
        action="store_true",
48
        help="Test the Github authentication.",
49
    )
UNCOV
50
    args = parser.parse_args()
×
51

NEW
52
    if args.test:
×
NEW
53
        auth = login()
×
54
    else:
NEW
55
        auth = store_token()
×
NEW
56
    print("Authenticated as %s." % auth.me().login)
×
57

58

59
if __name__ == "__main__":
×
60
    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