From 31defe907c905993c985ac89d570429b776d299c Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 6 Aug 2018 15:23:52 -0600 Subject: [PATCH 01/30] Fix the question mark location for one of the doctr configure questions --- doctr/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 86bcbe93..02f5a847 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -391,7 +391,7 @@ def configure(args, parser): while not get_build_repo: try: if default_repo: - build_repo = input("What repo do you want to build the docs for [{default_repo}]? ".format(default_repo=blue(default_repo))) + build_repo = input("What repo do you want to build the docs for? [{default_repo}] ".format(default_repo=blue(default_repo))) if not build_repo: build_repo = default_repo else: From c0bbd9314c50088283f15983cd3cf91618b60250 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 6 Aug 2018 16:27:46 -0600 Subject: [PATCH 02/30] Make check_repo_exists return whether or not the repo is on travis-ci.com --- doctr/local.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/doctr/local.py b/doctr/local.py index 9a6b1fdb..0225f2d4 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -237,7 +237,8 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) Raises ``RuntimeError`` if the repo is not valid. - Returns whether or not the repo is private + Returns whether or not the repo is on travis-ci.com (which requires + authorization to access, regardless of whether or not it is private) """ headers = headers or {} if deploy_repo.count("/") != 1: @@ -247,6 +248,9 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) if service == 'github': REPO_URL = 'https://api.github.com/repos/{user}/{repo}' elif service == 'travis': + REPO_URL = 'https://api.travis-ci.com/repo/{user}%2F{repo}' + headers['Travis-API-Version'] = '3' + elif service == 'travis-org': REPO_URL = 'https://api.travis-ci.org/repo/{user}%2F{repo}' headers['Travis-API-Version'] = '3' else: @@ -261,6 +265,9 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) repo=urllib.parse.quote(repo)), auth=auth, headers=headers) if r.status_code == requests.codes.not_found: + if service == 'travis': + return check_repo_exists(deploy_repo, service='travis-org', + auth=auth, headers=headers) raise RuntimeError('"{user}/{repo}" not found on {service}'.format(user=user, repo=repo, service=service)) @@ -276,7 +283,7 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) raise RuntimeError('Wiki not found. Please create a wiki') return False - return private + return private or (service == 'travis') GIT_URL = re.compile(r'(?:git@|https://|git://)github\.com[:/](.*?)(?:\.git)?') From 4fff48886ee7e78da7d571c25e4d3dbb3c35504b Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 6 Aug 2018 16:28:45 -0600 Subject: [PATCH 03/30] Clarify docstring --- doctr/local.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doctr/local.py b/doctr/local.py index 0225f2d4..517a8841 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -237,8 +237,10 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) Raises ``RuntimeError`` if the repo is not valid. - Returns whether or not the repo is on travis-ci.com (which requires - authorization to access, regardless of whether or not it is private) + Returns whether or not the repo requires authorization to access. Private + repos require authorization, as to repos on travis-ci.com, regardless of + whether or not it is private. + """ headers = headers or {} if deploy_repo.count("/") != 1: From 7ed3640101f0286ddd5d57d105566910a9c6373c Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 6 Aug 2018 16:29:16 -0600 Subject: [PATCH 04/30] Change is_private argument to encrypt_variable to dotcom This is because public repos can now be on travis-ci.com, but they still require authentication. --- doctr/__main__.py | 2 +- doctr/local.py | 33 ++++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 02f5a847..396f61d4 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -423,7 +423,7 @@ def configure(args, parser): if args.token: token = generate_GitHub_token(**login_kwargs)['token'] encrypted_variable = encrypt_variable("GH_TOKEN={token}".format(token=token).encode('utf-8'), - build_repo=build_repo, is_private=is_private, **login_kwargs) + build_repo=build_repo, dotcom=True, **login_kwargs) print(dedent(""" A personal access token for doctr has been created. diff --git a/doctr/local.py b/doctr/local.py index 517a8841..5550e2dc 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -22,7 +22,7 @@ from .common import red -def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, **login_kwargs): +def encrypt_variable(variable, build_repo, *, public_key=None, dotcom=False, **login_kwargs): """ Encrypt an environment variable for ``build_repo`` for Travis @@ -33,6 +33,11 @@ def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, ``public_key`` should be a pem format public key, obtained from Travis if not provided. + + ``dotcom`` should be True if the service is travis-ci.com and False if it + is travis-ci.org. Not that travis-ci.com requires creating a temporary + authentication on GitHub, which is deleted automatically (regardless of + whether or not the repo is private). """ if not isinstance(variable, bytes): raise TypeError("variable should be bytes") @@ -40,30 +45,36 @@ def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, if not b"=" in variable: raise ValueError("variable should be of the form 'VARIABLE=value'") + APIv2 = {'Accept': 'application/vnd.travis-ci.2+json'} + APIv3 = {"Travis-API-Version": "3"} if not public_key: - headers = {'Accept': 'application/vnd.travis-ci.2+json', - 'Content-Type': 'application/json', - 'User-Agent': 'MyClient/1.0.0'} - if is_private: + headers = { + 'Content-Type': 'application/json', + 'User-Agent': 'MyClient/1.0.0', + } + headersv2 = {**headers, **APIv2} + headers = headersv3 = {**headers, **APIv3} + if dotcom: + # /auth/github doesn't seem to exist in the Travis API v3. tok_dict = generate_GitHub_token(scopes=["read:org", "user:email", "repo"], - note="temporary token to auth against travis", + note="temporary token for doctr to auth against travis (delete me)", **login_kwargs) data = {'github_token': tok_dict['token']} token_id = tok_dict['id'] - res = requests.post('https://api.travis-ci.com/auth/github', data=json.dumps(data), headers=headers) + res = requests.post('https://api.travis-ci.com/auth/github', data=json.dumps(data), headers=headersv2) res.raise_for_status() headers['Authorization'] = 'token {}'.format(res.json()['access_token']) tld = 'com' else: tld = 'org' - res = requests.get('https://api.travis-ci.{tld}/repos/{build_repo}/key'.format(build_repo=build_repo, tld=tld), - headers=headers) + res = requests.get('https://api.travis-ci.{tld}/repo/{build_repo}/key_pair/generated'.format(build_repo=urllib.parse.quote(build_repo, + safe=''), tld=tld), headers=headersv3) if res.status_code == requests.codes.not_found: raise RuntimeError('Could not find requested repo on Travis. Is Travis enabled?') res.raise_for_status() - public_key = res.json()['key'] + public_key = res.json()['public_key'] # Remove temporary GH token - if is_private: + if dotcom: delete_GitHub_token(token_id, **login_kwargs) public_key = public_key.replace("RSA PUBLIC KEY", "PUBLIC KEY").encode('utf-8') From de6f84fefb792a6be9a6db90e0fcce496599b4df Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 6 Aug 2018 19:20:55 -0600 Subject: [PATCH 05/30] Better separation of travis.com and travis.org in check_repo_exists() --- doctr/local.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doctr/local.py b/doctr/local.py index 5550e2dc..91499c67 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -260,10 +260,10 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) user, repo = deploy_repo.split('/') if service == 'github': REPO_URL = 'https://api.github.com/repos/{user}/{repo}' - elif service == 'travis': + elif service == 'travis' or service == 'travis.com': REPO_URL = 'https://api.travis-ci.com/repo/{user}%2F{repo}' headers['Travis-API-Version'] = '3' - elif service == 'travis-org': + elif service == 'travis.org': REPO_URL = 'https://api.travis-ci.org/repo/{user}%2F{repo}' headers['Travis-API-Version'] = '3' else: @@ -285,6 +285,9 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) repo=repo, service=service)) + if service == 'travis': + service = 'travis.com' + r.raise_for_status() private = r.json().get('private', False) @@ -296,7 +299,7 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) raise RuntimeError('Wiki not found. Please create a wiki') return False - return private or (service == 'travis') + return private or (service == 'travis.com') GIT_URL = re.compile(r'(?:git@|https://|git://)github\.com[:/](.*?)(?:\.git)?') From f2fc924a56eae956c575d1d021cbcdfb724dd137 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 6 Aug 2018 19:21:21 -0600 Subject: [PATCH 06/30] Fix check_repo_exists() tests --- doctr/tests/test_local.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doctr/tests/test_local.py b/doctr/tests/test_local.py index 368d0f75..7fb95483 100644 --- a/doctr/tests/test_local.py +++ b/doctr/tests/test_local.py @@ -49,7 +49,9 @@ def test_travis_bad_repo(): check_repo_exists('drdoctr/DoCtR', service='travis') def test_travis_repo_exists(): - assert not check_repo_exists('drdoctr/doctr', service='travis') + assert not check_repo_exists('drdoctr/doctr', service='travis.org') + assert check_repo_exists('drdoctr/doctr', service='travis.com') + assert check_repo_exists('drdoctr/doctr', service='travis') def test_GIT_URL(): for url in [ From 3e0b51ea338fab4fdd2e44c12c353d353b03c9de Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 7 Aug 2018 12:07:13 -0600 Subject: [PATCH 07/30] Fix service name to match the actual URL --- doctr/local.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doctr/local.py b/doctr/local.py index 91499c67..e7189aaa 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -260,10 +260,10 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) user, repo = deploy_repo.split('/') if service == 'github': REPO_URL = 'https://api.github.com/repos/{user}/{repo}' - elif service == 'travis' or service == 'travis.com': + elif service == 'travis' or service == 'travis-ci.com': REPO_URL = 'https://api.travis-ci.com/repo/{user}%2F{repo}' headers['Travis-API-Version'] = '3' - elif service == 'travis.org': + elif service == 'travis-ci.org': REPO_URL = 'https://api.travis-ci.org/repo/{user}%2F{repo}' headers['Travis-API-Version'] = '3' else: @@ -279,14 +279,14 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) if r.status_code == requests.codes.not_found: if service == 'travis': - return check_repo_exists(deploy_repo, service='travis-org', + return check_repo_exists(deploy_repo, service='travis-ci.org', auth=auth, headers=headers) raise RuntimeError('"{user}/{repo}" not found on {service}'.format(user=user, repo=repo, service=service)) if service == 'travis': - service = 'travis.com' + service = 'travis-ci.com' r.raise_for_status() private = r.json().get('private', False) @@ -299,7 +299,7 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) raise RuntimeError('Wiki not found. Please create a wiki') return False - return private or (service == 'travis.com') + return private or (service == 'travis-ci.com') GIT_URL = re.compile(r'(?:git@|https://|git://)github\.com[:/](.*?)(?:\.git)?') From 3b0033e0312e78a50cdae7fdd4274694483a752e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 7 Aug 2018 13:11:38 -0600 Subject: [PATCH 08/30] Fix is_private logic in __main__.py --- doctr/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 396f61d4..d9c98bb2 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -397,7 +397,7 @@ def configure(args, parser): else: build_repo = input("What repo do you want to build the docs for (org/reponame, like 'drdoctr/doctr')? ") is_private = check_repo_exists(build_repo, service='github', **login_kwargs) - check_repo_exists(build_repo, service='travis') + is_private = check_repo_exists(build_repo, service='travis', ask=True) or is_private get_build_repo = True except RuntimeError as e: print(red('\n{!s:-^{}}\n'.format(e, 70))) @@ -423,7 +423,7 @@ def configure(args, parser): if args.token: token = generate_GitHub_token(**login_kwargs)['token'] encrypted_variable = encrypt_variable("GH_TOKEN={token}".format(token=token).encode('utf-8'), - build_repo=build_repo, dotcom=True, **login_kwargs) + build_repo=build_repo, is_private=is_private, **login_kwargs) print(dedent(""" A personal access token for doctr has been created. From 17c159c3bda18b09a76b4520a1a31039eafc1887 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 7 Aug 2018 13:12:17 -0600 Subject: [PATCH 09/30] Fix encrypt_variable for both travis-ci.org and .com --- doctr/local.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/doctr/local.py b/doctr/local.py index e7189aaa..04ba9900 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -22,7 +22,7 @@ from .common import red -def encrypt_variable(variable, build_repo, *, public_key=None, dotcom=False, **login_kwargs): +def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, **login_kwargs): """ Encrypt an environment variable for ``build_repo`` for Travis @@ -48,13 +48,13 @@ def encrypt_variable(variable, build_repo, *, public_key=None, dotcom=False, **l APIv2 = {'Accept': 'application/vnd.travis-ci.2+json'} APIv3 = {"Travis-API-Version": "3"} if not public_key: - headers = { + _headers = { 'Content-Type': 'application/json', 'User-Agent': 'MyClient/1.0.0', } - headersv2 = {**headers, **APIv2} - headers = headersv3 = {**headers, **APIv3} - if dotcom: + headersv2 = {**_headers, **APIv2} + headersv3 = {**_headers, **APIv3} + if is_private: # /auth/github doesn't seem to exist in the Travis API v3. tok_dict = generate_GitHub_token(scopes=["read:org", "user:email", "repo"], note="temporary token for doctr to auth against travis (delete me)", @@ -63,18 +63,18 @@ def encrypt_variable(variable, build_repo, *, public_key=None, dotcom=False, **l token_id = tok_dict['id'] res = requests.post('https://api.travis-ci.com/auth/github', data=json.dumps(data), headers=headersv2) res.raise_for_status() - headers['Authorization'] = 'token {}'.format(res.json()['access_token']) - tld = 'com' + headersv3['Authorization'] = 'token {}'.format(res.json()['access_token']) + res = requests.get('https://api.travis-ci.com/repo/{build_repo}/key_pair/generated'.format(build_repo=urllib.parse.quote(build_repo, + safe=''), headers=headersv3)) + public_key = res.json()['public_key'] else: - tld = 'org' - res = requests.get('https://api.travis-ci.{tld}/repo/{build_repo}/key_pair/generated'.format(build_repo=urllib.parse.quote(build_repo, - safe=''), tld=tld), headers=headersv3) + res = requests.get('https://api.travis-ci.org/repos/{build_repo}/key'.format(build_repo=build_repo), headers=headersv2) + public_key = res.json()['key'] if res.status_code == requests.codes.not_found: raise RuntimeError('Could not find requested repo on Travis. Is Travis enabled?') res.raise_for_status() - public_key = res.json()['public_key'] # Remove temporary GH token - if dotcom: + if is_private: delete_GitHub_token(token_id, **login_kwargs) public_key = public_key.replace("RSA PUBLIC KEY", "PUBLIC KEY").encode('utf-8') From 6fcd844ee492ebce4e93752e7a55716d69939631 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 7 Aug 2018 13:13:48 -0600 Subject: [PATCH 10/30] Add ask flag to check_repo_exists --- doctr/local.py | 58 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/doctr/local.py b/doctr/local.py index 04ba9900..9deb9229 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -20,7 +20,7 @@ from cryptography.hazmat.primitives import serialization -from .common import red +from .common import red, blue def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, **login_kwargs): """ @@ -239,7 +239,8 @@ def generate_ssh_key(): return private_key, public_key -def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None): +def check_repo_exists(deploy_repo, service='github', *, auth=None, + headers=None, ask=False): """ Checks that the repository exists on GitHub. @@ -252,6 +253,12 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) repos require authorization, as to repos on travis-ci.com, regardless of whether or not it is private. + For service='travis', if ask=True, it will ask at the command line if both + travis-ci.org and travis-ci.com exist. If ask=False, service='travis' will + check travis-ci.com first and only check travis-ci.org if it doesn't + exist. ask=True does nothing for service='github', + service='travis-ci.com', service='travis-ci.org'. + """ headers = headers or {} if deploy_repo.count("/") != 1: @@ -274,21 +281,48 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None) wiki = True repo = repo[:-5] - r = requests.get(REPO_URL.format(user=urllib.parse.quote(user), - repo=urllib.parse.quote(repo)), auth=auth, headers=headers) + def _try(url): + r = requests.get(url, auth=auth, headers=headers) + + if r.status_code == requests.codes.not_found: + return False + r.raise_for_status() + return r + + r = _try(REPO_URL.format(user=urllib.parse.quote(user), + repo=urllib.parse.quote(repo))) - if r.status_code == requests.codes.not_found: - if service == 'travis': - return check_repo_exists(deploy_repo, service='travis-ci.org', - auth=auth, headers=headers) + if service == 'travis': + REPO_URL = 'https://api.travis-ci.org/repo/{user}%2F{repo}' + r_org = _try(REPO_URL.format(user=urllib.parse.quote(user), + repo=urllib.parse.quote(repo))) + if not r: + r = r_org + else: + if r and r_org: + if ask: + while True: + print("{user}/{repo} appears to exist on both travis-ci.org and travis-ci.com.".format(user=user, repo=repo)) + preferred = input("Which do you want to use? [{default}/travis-ci.org] ".format(default=blue("travis-ci.com"))) + preferred = preferred.lower().strip() + if preferred in ['o', 'org', '.org', 'travis-ci.org']: + r = r_org + service = 'travis-ci.org' + break + elif preferred in ['c', 'com', '.com', 'travis-ci.com']: + service = 'travis-ci.com' + break + else: + print(red("Please type 'travis-ci.com' or 'travis-ci.org'.")) + else: + service = 'travis-ci.com' + + + if not r: raise RuntimeError('"{user}/{repo}" not found on {service}'.format(user=user, repo=repo, service=service)) - if service == 'travis': - service = 'travis-ci.com' - - r.raise_for_status() private = r.json().get('private', False) if wiki and not private: From be03af321562aabfd365581b80a0fe71f6791733 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 7 Aug 2018 14:14:04 -0600 Subject: [PATCH 11/30] Fix error message --- doctr/local.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doctr/local.py b/doctr/local.py index 9deb9229..e58ee534 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -65,7 +65,7 @@ def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, res.raise_for_status() headersv3['Authorization'] = 'token {}'.format(res.json()['access_token']) res = requests.get('https://api.travis-ci.com/repo/{build_repo}/key_pair/generated'.format(build_repo=urllib.parse.quote(build_repo, - safe=''), headers=headersv3)) + safe=''), headers=headersv3)) public_key = res.json()['public_key'] else: res = requests.get('https://api.travis-ci.org/repos/{build_repo}/key'.format(build_repo=build_repo), headers=headersv2) @@ -274,7 +274,7 @@ def check_repo_exists(deploy_repo, service='github', *, auth=None, REPO_URL = 'https://api.travis-ci.org/repo/{user}%2F{repo}' headers['Travis-API-Version'] = '3' else: - raise RuntimeError('Invalid service specified for repo check (neither "travis" nor "github")') + raise RuntimeError('Invalid service specified for repo check (should be one of {"github", "travis", "travis-ci.com", "travis-ci.org"}') wiki = False if repo.endswith('.wiki') and service == 'github': From 486527c2768c8a8dfd1668156bba43ad3d332353 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 7 Aug 2018 14:14:44 -0600 Subject: [PATCH 12/30] Fix check_repo_exists() tests --- doctr/local.py | 1 + doctr/tests/test_local.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doctr/local.py b/doctr/local.py index e58ee534..f0d98438 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -70,6 +70,7 @@ def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, else: res = requests.get('https://api.travis-ci.org/repos/{build_repo}/key'.format(build_repo=build_repo), headers=headersv2) public_key = res.json()['key'] + if res.status_code == requests.codes.not_found: raise RuntimeError('Could not find requested repo on Travis. Is Travis enabled?') res.raise_for_status() diff --git a/doctr/tests/test_local.py b/doctr/tests/test_local.py index 7fb95483..4322d5d8 100644 --- a/doctr/tests/test_local.py +++ b/doctr/tests/test_local.py @@ -49,8 +49,8 @@ def test_travis_bad_repo(): check_repo_exists('drdoctr/DoCtR', service='travis') def test_travis_repo_exists(): - assert not check_repo_exists('drdoctr/doctr', service='travis.org') - assert check_repo_exists('drdoctr/doctr', service='travis.com') + assert not check_repo_exists('drdoctr/doctr', service='travis-ci.org') + assert check_repo_exists('drdoctr/doctr', service='travis-ci.com') assert check_repo_exists('drdoctr/doctr', service='travis') def test_GIT_URL(): From 564c69db7f6f004d07de3a936f6fe168cc7ada7f Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 7 Aug 2018 14:15:55 -0600 Subject: [PATCH 13/30] Add comment about check_repo_exists test --- doctr/tests/test_local.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doctr/tests/test_local.py b/doctr/tests/test_local.py index 4322d5d8..78064556 100644 --- a/doctr/tests/test_local.py +++ b/doctr/tests/test_local.py @@ -48,6 +48,8 @@ def test_travis_bad_repo(): # Travis is case-sensitive check_repo_exists('drdoctr/DoCtR', service='travis') +# This test may need to be adjusted as travis-ci.org gets merged into +# travis-ci.com. Currently drdoctr/doctr is enabled on both. def test_travis_repo_exists(): assert not check_repo_exists('drdoctr/doctr', service='travis-ci.org') assert check_repo_exists('drdoctr/doctr', service='travis-ci.com') From d99639e4a850687d7c3129f10d08bbf0a184ffd2 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 8 Aug 2018 12:22:16 -0600 Subject: [PATCH 14/30] Print a note about the personal access token --- doctr/local.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doctr/local.py b/doctr/local.py index f0d98438..1fd7073b 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -55,6 +55,8 @@ def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, headersv2 = {**_headers, **APIv2} headersv3 = {**_headers, **APIv3} if is_private: + print("I need to generate a temporary token with GitHub to authenticate with Travis.") + print("It will be deleted immediately. If you still see it after this at https://github.com/settings/tokens after please delete it manually.") # /auth/github doesn't seem to exist in the Travis API v3. tok_dict = generate_GitHub_token(scopes=["read:org", "user:email", "repo"], note="temporary token for doctr to auth against travis (delete me)", From 2a12448a7ba339348cf8669a97ca9112f96a2eae Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 27 Aug 2018 14:28:58 -0600 Subject: [PATCH 15/30] Fix getting of the public key on travis-ci.com --- doctr/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctr/local.py b/doctr/local.py index 1fd7073b..b3347bff 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -67,7 +67,7 @@ def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, res.raise_for_status() headersv3['Authorization'] = 'token {}'.format(res.json()['access_token']) res = requests.get('https://api.travis-ci.com/repo/{build_repo}/key_pair/generated'.format(build_repo=urllib.parse.quote(build_repo, - safe=''), headers=headersv3)) + safe='')), headers=headersv3) public_key = res.json()['public_key'] else: res = requests.get('https://api.travis-ci.org/repos/{build_repo}/key'.format(build_repo=build_repo), headers=headersv2) From f917ae560be9e99bf1d442fb30812fcb18e54e57 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 27 Aug 2018 14:29:28 -0600 Subject: [PATCH 16/30] Add error handling if the public key cannot be found on travis-ci.com --- doctr/local.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doctr/local.py b/doctr/local.py index b3347bff..19829245 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -68,6 +68,8 @@ def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, headersv3['Authorization'] = 'token {}'.format(res.json()['access_token']) res = requests.get('https://api.travis-ci.com/repo/{build_repo}/key_pair/generated'.format(build_repo=urllib.parse.quote(build_repo, safe='')), headers=headersv3) + if res.json().get('file') == 'not found': + raise RuntimeError("Could not find the Travis public key for %s" % build_repo) public_key = res.json()['public_key'] else: res = requests.get('https://api.travis-ci.org/repos/{build_repo}/key'.format(build_repo=build_repo), headers=headersv2) From c722773269e607ba01789504b59e47fe9f532d8b Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 27 Aug 2018 14:30:04 -0600 Subject: [PATCH 17/30] Delete the GitHub personal access token in a finally block --- doctr/local.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/doctr/local.py b/doctr/local.py index 19829245..3cca234c 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -75,12 +75,14 @@ def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, res = requests.get('https://api.travis-ci.org/repos/{build_repo}/key'.format(build_repo=build_repo), headers=headersv2) public_key = res.json()['key'] - if res.status_code == requests.codes.not_found: - raise RuntimeError('Could not find requested repo on Travis. Is Travis enabled?') - res.raise_for_status() - # Remove temporary GH token - if is_private: - delete_GitHub_token(token_id, **login_kwargs) + try: + if res.status_code == requests.codes.not_found: + raise RuntimeError('Could not find requested repo on Travis. Is Travis enabled?') + res.raise_for_status() + finally: + # Remove temporary GH token + if is_private: + delete_GitHub_token(token_id, **login_kwargs) public_key = public_key.replace("RSA PUBLIC KEY", "PUBLIC KEY").encode('utf-8') key = serialization.load_pem_public_key(public_key, backend=default_backend()) From b6a391eeb4f699014fbb10ac0034e17fc8ca2f44 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 27 Aug 2018 14:32:37 -0600 Subject: [PATCH 18/30] Move try statement up --- doctr/local.py | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/doctr/local.py b/doctr/local.py index 3cca234c..e96518f8 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -54,34 +54,37 @@ def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, } headersv2 = {**_headers, **APIv2} headersv3 = {**_headers, **APIv3} - if is_private: - print("I need to generate a temporary token with GitHub to authenticate with Travis.") - print("It will be deleted immediately. If you still see it after this at https://github.com/settings/tokens after please delete it manually.") - # /auth/github doesn't seem to exist in the Travis API v3. - tok_dict = generate_GitHub_token(scopes=["read:org", "user:email", "repo"], - note="temporary token for doctr to auth against travis (delete me)", - **login_kwargs) - data = {'github_token': tok_dict['token']} - token_id = tok_dict['id'] - res = requests.post('https://api.travis-ci.com/auth/github', data=json.dumps(data), headers=headersv2) - res.raise_for_status() - headersv3['Authorization'] = 'token {}'.format(res.json()['access_token']) - res = requests.get('https://api.travis-ci.com/repo/{build_repo}/key_pair/generated'.format(build_repo=urllib.parse.quote(build_repo, - safe='')), headers=headersv3) - if res.json().get('file') == 'not found': - raise RuntimeError("Could not find the Travis public key for %s" % build_repo) - public_key = res.json()['public_key'] - else: - res = requests.get('https://api.travis-ci.org/repos/{build_repo}/key'.format(build_repo=build_repo), headers=headersv2) - public_key = res.json()['key'] - + token_id = None try: + if is_private: + print("I need to generate a temporary token with GitHub to authenticate with Travis.") + print("It will be deleted immediately. If you still see it after this at https://github.com/settings/tokens after please delete it manually.") + # /auth/github doesn't seem to exist in the Travis API v3. + tok_dict = generate_GitHub_token(scopes=["read:org", "user:email", "repo"], + note="temporary token for doctr to auth against travis (delete me)", + **login_kwargs) + data = {'github_token': tok_dict['token']} + token_id = tok_dict['id'] + res = requests.post('https://api.travis-ci.com/auth/github', data=json.dumps(data), headers=headersv2) + res.raise_for_status() + headersv3['Authorization'] = 'token {}'.format(res.json()['access_token']) + res = requests.get('https://api.travis-ci.com/repo/{build_repo}/key_pair/generated'.format(build_repo=urllib.parse.quote(build_repo, + safe='')), headers=headersv3) + if res.json().get('file') == 'not found': + print(headersv3) + raise RuntimeError("Could not find the Travis public key for %s" % build_repo) + public_key = res.json()['public_key'] + else: + res = requests.get('https://api.travis-ci.org/repos/{build_repo}/key'.format(build_repo=build_repo), headers=headersv2) + public_key = res.json()['key'] + if res.status_code == requests.codes.not_found: raise RuntimeError('Could not find requested repo on Travis. Is Travis enabled?') res.raise_for_status() + finally: # Remove temporary GH token - if is_private: + if is_private and token_id: delete_GitHub_token(token_id, **login_kwargs) public_key = public_key.replace("RSA PUBLIC KEY", "PUBLIC KEY").encode('utf-8') From 127383dbfe8e8b6f44a34771f99ce017c80842ce Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 27 Aug 2018 14:33:08 -0600 Subject: [PATCH 19/30] Print RuntimeError error messages in red --- doctr/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index d9c98bb2..1218c3de 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -248,7 +248,7 @@ def process_args(parser): try: return args.func(args, parser) except RuntimeError as e: - sys.exit("Error: " + e.args[0]) + sys.exit(red("Error: " + e.args[0])) def on_travis(): return os.environ.get("TRAVIS_JOB_NUMBER", '') From 51be924afa344f4a1551b9bc5f186cd4951227c6 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 28 Aug 2018 11:48:54 -0600 Subject: [PATCH 20/30] Add a function to determine if doctr is running on travis-ci.com or travis-ci.org --- doctr/travis.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doctr/travis.py b/doctr/travis.py index 178032dc..e03fef99 100644 --- a/doctr/travis.py +++ b/doctr/travis.py @@ -14,6 +14,7 @@ import time from cryptography.fernet import Fernet +import requests from .common import red, blue DOCTR_WORKING_BRANCH = '__doctr_working_branch' @@ -575,3 +576,17 @@ def determine_push_rights(*, branch_whitelist, TRAVIS_BRANCH, canpush = False return canpush + +def travis_tld(): + """ + Determines if the job is being run on travis-ci.com or travis-ci.org + + Returns the tld ('.com' or '.org'). For maximum compatibility, if the tld + cannot be determined, it returns '.org'. + """ + # See + # https://github.com/travis-ci/travis-ci/issues/7552#issuecomment-416443383. + # A request on each domain will return 200 on that domain and 401 on the + # other. + r = requests.get('https://api.travis-ci.com/jobs') + return '.com' if r.status_code == 200 else '.org' From f1d40803793ef3d87fce42f041dea1b539272c73 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 28 Aug 2018 11:50:35 -0600 Subject: [PATCH 21/30] Add test print to test travis_tld --- doctr/__main__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 1218c3de..6ddec0ea 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -39,7 +39,7 @@ GitHub_login, guess_github_repo, AuthenticationFailed) from .travis import (setup_GitHub_push, commit_docs, push_docs, get_current_repo, sync_from_log, find_sphinx_build_dir, run, - get_travis_branch, copy_to_tmp, checkout_deploy_branch) + get_travis_branch, copy_to_tmp, checkout_deploy_branch, travis_tld) from .common import red, green, blue, bold_black, BOLD_BLACK, BOLD_MAGENTA, RESET @@ -258,6 +258,8 @@ def deploy(args, parser): parser.error("doctr does not appear to be running on Travis. Use " "doctr deploy --force to run anyway.") + print("We seem to be running on travis-ci{tld}".format(travis_tld)) + config = get_config() if args.tmp_dir: From d40c54577949f8f1bb07468cc31e2ef887aca6c9 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 28 Aug 2018 11:56:10 -0600 Subject: [PATCH 22/30] Fix debug print --- doctr/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 6ddec0ea..5cef3968 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -258,7 +258,7 @@ def deploy(args, parser): parser.error("doctr does not appear to be running on Travis. Use " "doctr deploy --force to run anyway.") - print("We seem to be running on travis-ci{tld}".format(travis_tld)) + print("We seem to be running on travis-ci{tld}".format(tld=travis_tld())) config = get_config() From 26ad4520b170f4fe38ee4433ac7d47ddf3b802ce Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 28 Aug 2018 12:06:23 -0600 Subject: [PATCH 23/30] Some more debug prints --- doctr/travis.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doctr/travis.py b/doctr/travis.py index e03fef99..b930aa6e 100644 --- a/doctr/travis.py +++ b/doctr/travis.py @@ -588,5 +588,8 @@ def travis_tld(): # https://github.com/travis-ci/travis-ci/issues/7552#issuecomment-416443383. # A request on each domain will return 200 on that domain and 401 on the # other. - r = requests.get('https://api.travis-ci.com/jobs') - return '.com' if r.status_code == 200 else '.org' + rcom = requests.get('https://api.travis-ci.com/jobs') + rorg = requests.get('https://api.travis-ci.org/jobs') + print('travis-ci.com status code', rcom.status_code) + print('travis-ci.org status code', rorg.status_code) + return '.com' if rorg.status_code == 200 else '.org' From dc68e51f57b500be05182c63171de3314cd2fa2b Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 27 Nov 2018 16:38:54 -0700 Subject: [PATCH 24/30] Use TRAVIS_JOB_WEB_URL to get the URL for the commit message Also remove travis_tld(), which is no longer needed (and didn't actually work anyway). --- doctr/__main__.py | 4 +--- doctr/travis.py | 24 +++--------------------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 2ac6c983..5dc5e306 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -39,7 +39,7 @@ GitHub_login, guess_github_repo, AuthenticationFailed, GitHubError) from .travis import (setup_GitHub_push, commit_docs, push_docs, get_current_repo, sync_from_log, find_sphinx_build_dir, run, - get_travis_branch, copy_to_tmp, checkout_deploy_branch, travis_tld) + get_travis_branch, copy_to_tmp, checkout_deploy_branch) from .common import red, green, blue, bold_black, BOLD_BLACK, BOLD_MAGENTA, RESET @@ -260,8 +260,6 @@ def deploy(args, parser): parser.error("doctr does not appear to be running on Travis. Use " "doctr deploy --force to run anyway.") - print("We seem to be running on travis-ci{tld}".format(tld=travis_tld())) - config = get_config() if args.tmp_dir: diff --git a/doctr/travis.py b/doctr/travis.py index 1e0cc88f..f0eae740 100644 --- a/doctr/travis.py +++ b/doctr/travis.py @@ -14,7 +14,6 @@ import time from cryptography.fernet import Fernet -import requests from .common import red, blue DOCTR_WORKING_BRANCH = '__doctr_working_branch' @@ -471,7 +470,7 @@ def commit_docs(*, added, removed): TRAVIS_BRANCH = os.environ.get("TRAVIS_BRANCH", "") TRAVIS_COMMIT = os.environ.get("TRAVIS_COMMIT", "") TRAVIS_REPO_SLUG = os.environ.get("TRAVIS_REPO_SLUG", "") - TRAVIS_JOB_ID = os.environ.get("TRAVIS_JOB_ID", "") + TRAVIS_JOB_WEB_URL = os.environ.get("TRAVIS_JOB_WEB_URL", "") TRAVIS_TAG = os.environ.get("TRAVIS_TAG", "") branch = "tag" if TRAVIS_TAG else "branch" @@ -491,7 +490,7 @@ def commit_docs(*, added, removed): {TRAVIS_COMMIT}. The Travis build that generated this commit is at -https://travis-ci.org/{TRAVIS_REPO_SLUG}/jobs/{TRAVIS_JOB_ID}. +{TRAVIS_JOB_WEB_URL}. The doctr command that was run is @@ -502,7 +501,7 @@ def commit_docs(*, added, removed): TRAVIS_BRANCH=TRAVIS_BRANCH, TRAVIS_COMMIT=TRAVIS_COMMIT, TRAVIS_REPO_SLUG=TRAVIS_REPO_SLUG, - TRAVIS_JOB_ID=TRAVIS_JOB_ID, + TRAVIS_JOB_WEB_URL=TRAVIS_JOB_WEB_URL, DOCTR_COMMAND=DOCTR_COMMAND, ) @@ -577,20 +576,3 @@ def determine_push_rights(*, branch_whitelist, TRAVIS_BRANCH, canpush = False return canpush - -def travis_tld(): - """ - Determines if the job is being run on travis-ci.com or travis-ci.org - - Returns the tld ('.com' or '.org'). For maximum compatibility, if the tld - cannot be determined, it returns '.org'. - """ - # See - # https://github.com/travis-ci/travis-ci/issues/7552#issuecomment-416443383. - # A request on each domain will return 200 on that domain and 401 on the - # other. - rcom = requests.get('https://api.travis-ci.com/jobs') - rorg = requests.get('https://api.travis-ci.org/jobs') - print('travis-ci.com status code', rcom.status_code) - print('travis-ci.org status code', rorg.status_code) - return '.com' if rorg.status_code == 200 else '.org' From 63f366964ded3b331d8dfb486a19b82426f460f6 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 27 Nov 2018 16:46:51 -0700 Subject: [PATCH 25/30] Fix travis-ci.com being the default choice in configure --- doctr/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctr/local.py b/doctr/local.py index 4112440f..83f3ee76 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -379,7 +379,7 @@ def _try(url): r = r_org service = 'travis-ci.org' break - elif preferred in ['c', 'com', '.com', 'travis-ci.com']: + elif preferred in ['c', 'com', '.com', 'travis-ci.com', '']: service = 'travis-ci.com' break else: From 648a7deca0a600037b363ac691134fba84d861d3 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 27 Nov 2018 16:50:13 -0700 Subject: [PATCH 26/30] Add color guide to the common.py file --- doctr/common.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doctr/common.py b/doctr/common.py index 7bb23931..6babfc82 100644 --- a/doctr/common.py +++ b/doctr/common.py @@ -2,6 +2,15 @@ Code used for both Travis and local (deploy and configure) """ +# Color guide +# +# - red: Error and warning messages +# - green: Welcome messages (use sparingly) +# - blue: Default values +# - bold_magenta: Action items +# - bold_black: Parts of code to be run or copied that should be modified + + def red(text): return "\033[31m%s\033[0m" % text From 7cd59f6523fb7b4956eae4ddf12041321420106d Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 27 Nov 2018 16:50:26 -0700 Subject: [PATCH 27/30] Add note that GitHub will email you about th personal access token Also print it in green so it is noticeable. --- doctr/local.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doctr/local.py b/doctr/local.py index 83f3ee76..7018504d 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -58,8 +58,8 @@ def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, token_id = None try: if is_private: - print("I need to generate a temporary token with GitHub to authenticate with Travis.") - print("It will be deleted immediately. If you still see it after this at https://github.com/settings/tokens after please delete it manually.") + print(green("I need to generate a temporary token with GitHub to authenticate with Travis. You may get a warning email from GitHub about this.")) + print(green("It will be deleted immediately. If you still see it after this at https://github.com/settings/tokens after please delete it manually.")) # /auth/github doesn't seem to exist in the Travis API v3. tok_dict = generate_GitHub_token(scopes=["read:org", "user:email", "repo"], note="temporary token for doctr to auth against travis (delete me)", From f4e3a7af6bd6c4937aa5ae3238859c9045d3f4b8 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 27 Nov 2018 17:13:31 -0700 Subject: [PATCH 28/30] Add missing import --- doctr/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctr/local.py b/doctr/local.py index 7018504d..a5b68bc9 100644 --- a/doctr/local.py +++ b/doctr/local.py @@ -21,7 +21,7 @@ from cryptography.hazmat.primitives import serialization -from .common import red, blue +from .common import red, blue, green def encrypt_variable(variable, build_repo, *, public_key=None, is_private=False, **login_kwargs): """ From a9e8b792954576a86aac91bc553a3f698baaf923 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 27 Nov 2018 17:13:51 -0700 Subject: [PATCH 29/30] Add --no-authenticate flag to doctr configure --no-authenticate implies --no-upload. --no-upload no longer doesn't ask for authentication (use --no-authenticate instead). This is because authentication is now needed for other things than uploading the key (particularly, making API requests to travis-ci.com). --- doctr/__main__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 5dc5e306..c62e19ce 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -196,9 +196,14 @@ def get_parser(config=None): public repositories for the user. This option is not recommended unless you are using a separate GitHub user for deploying.""") configure_parser.add_argument("--no-upload-key", action="store_false", default=True, - dest="upload_key", help="""Don't automatically upload the deploy key to GitHub. If you select this - option, you will not be prompted for your GitHub credentials, so this option is not compatible with - private repositories.""") + dest="upload_key", help="""Don't automatically upload the deploy key to GitHub. To prevent doctr + configure from asking for your GitHub credentials, use + --no-authenticate.""") + configure_parser.add_argument("--no-authenticate", action="store_false", + default=True, dest="authenticate", help="""Don't authenticate with GitHub. This option implies --no-upload-key. Note: + it is not possible to configure travis-ci.com with this option, only + .org (see https://github.com/travis-ci/travis-ci/issues/9954). This + option is also not compatible with private repositories.""") configure_parser.add_argument('--key-path', default=None, help="""Path to save the encrypted GitHub deploy key. The default is github_deploy_key_+ deploy respository name. The .enc extension is added to the file automatically.""") @@ -370,6 +375,8 @@ def configure(args, parser): parser.error(red("doctr appears to be running on Travis. Use " "doctr configure --force to run anyway.")) + if not args.authenticate: + args.upload_key = False print(green(dedent("""\ Welcome to Doctr. @@ -379,7 +386,8 @@ def configure(args, parser): """))) login_kwargs = {} - if args.upload_key: + + if args.authenticate: while not login_kwargs: try: login_kwargs = GitHub_login() From 4da7d99d11383bc7ae976ba3881e44ea9a9d9926 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 27 Nov 2018 17:15:06 -0700 Subject: [PATCH 30/30] Print an error message when --no-authenticate us used with a private repo or travis-ci.com --- doctr/__main__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index c62e19ce..52073507 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -406,8 +406,15 @@ def configure(args, parser): build_repo = default_repo else: build_repo = input("What repo do you want to build the docs for (org/reponame, like 'drdoctr/doctr')? ") - is_private = check_repo_exists(build_repo, service='github', **login_kwargs) + is_private = check_repo_exists(build_repo, service='github', + **login_kwargs) + if is_private and not args.authenticate: + sys.exit(red("--no-authenticate is not supported for private repositories.")) + is_private = check_repo_exists(build_repo, service='travis', ask=True) or is_private + if is_private and not args.authenticate: + sys.exit(red("--no-authenticate is not supported for travis-ci.com. See https://github.com/travis-ci/travis-ci/issues/9954.")) + get_build_repo = True except GitHubError: raise