Repository: drdoctr/doctr

Issue:
Check for travis repo before generating keys.
Otherwise it will just fail and you'll have to regenerate. 

It's a small optimisation though, that will mostly affect users that make typos.

Note that github is not case sensitive for usernames, travis is so for example, I regularly get into trouble when I write my username lowercase and it involves travis.


Comments:

Patch:
diff --git a/doctr/__main__.py b/doctr/__main__.py
index 25889d4c..a50c3236 100644
--- a/doctr/__main__.py
+++ b/doctr/__main__.py
@@ -182,14 +182,15 @@ def configure(args, parser):
         login_kwargs = {'auth': None, 'headers': None}
 
     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, **login_kwargs)
+    is_private = check_repo_exists(build_repo, service='github', **login_kwargs)
+    check_repo_exists(build_repo, service='travis')
 
     deploy_repo = input("What repo do you want to deploy the docs to? [{build_repo}] ".format(build_repo=build_repo))
     if not deploy_repo:
         deploy_repo = build_repo
 
     if deploy_repo != build_repo:
-        check_repo_exists(deploy_repo, **login_kwargs)
+        check_repo_exists(deploy_repo, service='github', **login_kwargs)
 
     N = IncrementingInt(1)
 
diff --git a/doctr/local.py b/doctr/local.py
index 7fbf9004..8fe0b6ef 100644
--- a/doctr/local.py
+++ b/doctr/local.py
@@ -212,7 +212,7 @@ def generate_ssh_key(note, keypath='github_deploy_key'):
     with open(keypath + ".pub") as f:
         return f.read()
 
-def check_repo_exists(deploy_repo, *, auth=None, headers=None):
+def check_repo_exists(deploy_repo, service='github', *, auth=None, headers=None):
     """
     Checks that the repository exists on GitHub.
 
@@ -227,11 +227,19 @@ def check_repo_exists(deploy_repo, *, auth=None, headers=None):
         raise RuntimeError('"{deploy_repo}" should be in the form username/repo'.format(deploy_repo=deploy_repo))
 
     user, repo = deploy_repo.split('/')
-    REPO_URL = 'https://api.github.com/repos/{user}/{repo}'
+    if service == 'github':
+        REPO_URL = 'https://api.github.com/repos/{user}/{repo}'
+    elif service == 'travis':
+        REPO_URL = 'https://api.travis-ci.org/repos/{user}/{repo}'
+    else:
+        raise RuntimeError('Invalid service specified for repo check (neither "travis" nor "github")')
+
     r = requests.get(REPO_URL.format(user=user, repo=repo), auth=auth, headers=headers)
 
     if r.status_code == requests.codes.not_found:
-        raise RuntimeError('"{user}/{repo}" not found on GitHub. Exiting'.format(user=user, repo=repo))
+        raise RuntimeError('"{user}/{repo}" not found on {service}. Exiting'.format(user=user,
+                                                                                    repo=repo,
+                                                                                    service=service))
 
     r.raise_for_status()
 


Test patch:
diff --git a/doctr/tests/test_local.py b/doctr/tests/test_local.py
index ba07bb4b..897cfa27 100644
--- a/doctr/tests/test_local.py
+++ b/doctr/tests/test_local.py
@@ -11,20 +11,33 @@ else:
     HEADERS = None
 
 
-def test_bad_user():
+def test_github_bad_user():
     with raises(RuntimeError):
         check_repo_exists('---/invaliduser', headers=HEADERS)
 
-def test_bad_repo():
+def test_github_bad_repo():
     with raises(RuntimeError):
         check_repo_exists('drdoctr/---', headers=HEADERS)
 
-def test_repo_exists():
+def test_github_repo_exists():
     assert not check_repo_exists('drdoctr/doctr', headers=HEADERS)
 
-def test_invalid_repo():
+def test_github_invalid_repo():
     with raises(RuntimeError):
         check_repo_exists('fdsf', headers=HEADERS)
 
     with raises(RuntimeError):
         check_repo_exists('fdsf/fdfs/fd', headers=HEADERS)
+
+def test_travis_bad_user():
+    with raises(RuntimeError):
+        # Travis is case-sensitive
+        check_repo_exists('dRdoctr/doctr', service='travis')
+
+def test_travis_bad_repo():
+    with raises(RuntimeError):
+        # Travis is case-sensitive
+        check_repo_exists('drdoctr/DoCtR', service='travis')
+
+def test_travis_repo_exists():
+    assert not check_repo_exists('drdoctr/doctr', service='travis')