Repository: conda-forge/conda-smithy

Issue:
Skip using Travis token
Currently if a Travis token file exists and is empty, `conda-smithy` will use the empty token. As this almost certainly is not intentional, we should skip using this file if it exists and is empty/contains only white space. Possibly should be done with other token files in a similar state.

ref: https://github.com/conda-forge/staged-recipes/pull/6097#pullrequestreview-129042423


Discussion:

Resolving patch:
diff --git a/conda_smithy/ci_register.py b/conda_smithy/ci_register.py
--- a/conda_smithy/ci_register.py
+++ b/conda_smithy/ci_register.py
@@ -19,14 +19,18 @@
     # Create a token at https://circleci.com/account/api. Put it in circle.token
     with open(os.path.expanduser('~/.conda-smithy/circle.token'), 'r') as fh:
         circle_token = fh.read().strip()
-except IOError:
+    if not circle_token:
+        raise ValueError()
+except (IOError, ValueError):
     print('No circle token.  Create a token at https://circleci.com/account/api and\n'
           'put it in ~/.conda-smithy/circle.token')
 
 try:
     with open(os.path.expanduser('~/.conda-smithy/appveyor.token'), 'r') as fh:
         appveyor_token = fh.read().strip()
-except IOError:
+    if not appveyor_token:
+        raise ValueError()
+except (IOError, ValueError):
     print('No appveyor token. Create a token at https://ci.appveyor.com/api-token and\n'
           'Put one in ~/.conda-smithy/appveyor.token')
 
@@ -36,7 +40,9 @@
     try:
         with open(os.path.expanduser('~/.conda-smithy/anaconda.token'), 'r') as fh:
             anaconda_token = fh.read().strip()
-    except IOError:
+        if not anaconda_token:
+            raise ValueError()
+    except (IOError, ValueError):
         print('No anaconda token. Create a token via\n'
               '  anaconda auth --create --name conda-smithy --scopes "repos conda api"\n'
               'and put it in ~/.conda-smithy/anaconda.token')
@@ -52,7 +58,12 @@ def travis_headers():
        'Travis-API-Version': '3'
     }
     travis_token = os.path.expanduser('~/.conda-smithy/travis.token')
-    if not os.path.exists(travis_token):
+    try:
+        with open(travis_token, 'r') as fh:
+            token = fh.read().strip()
+        if not token:
+            raise ValueError
+    except (IOError, ValueError):
         # We generally want the V3 API, but can currently only auth with V2:
         # https://github.com/travis-ci/travis-ci/issues/9273#issuecomment-370474214
         v2_headers = headers.copy()
@@ -68,9 +79,6 @@ def travis_headers():
         with open(travis_token, 'w') as fh:
             fh.write(token)
         # TODO: Set the permissions on the file.
-    else:
-        with open(travis_token, 'r') as fh:
-            token = fh.read().strip()
 
     headers['Authorization'] = 'token {}'.format(token)
     return headers
diff --git a/conda_smithy/github.py b/conda_smithy/github.py
--- a/conda_smithy/github.py
+++ b/conda_smithy/github.py
@@ -17,7 +17,9 @@ def gh_token():
     try:
         with open(os.path.expanduser('~/.conda-smithy/github.token'), 'r') as fh:
             token = fh.read().strip()
-    except IOError:
+        if not token:
+            raise ValueError()
+    except (IOError, ValueError):
         msg = ('No github token. Go to https://github.com/settings/tokens/new and generate\n'
                'a token with repo access. Put it in ~/.conda-smithy/github.token')
         raise RuntimeError(msg)


Test patch: