Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 04ec397

Browse files
committed
support token via file argument, close #25
1 parent 1f9d325 commit 04ec397

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

.token

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a

codecov/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ def upload(url, root, env=None, files=None, dump=False, **query):
215215
(query.get('build') and query.get('service') == 'circleci'),
216216
query.get('token'))), "Missing repository upload token"
217217

218+
# Read token from file
219+
if query.get('token') and query.get('token')[0] == '@':
220+
write(' Reading token from file')
221+
with open(opj(os.getcwd(), query['token'][1:]), 'r') as token:
222+
query['token'] = token.read().strip()
223+
218224
write('==> Reading file network')
219225

220226
# Detect .bowerrc

tests/test.py

+9
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class TestUploader(unittest.TestCase):
8383
maxDiff = None
8484
here = os.path.dirname(__file__)
8585
bowerrc = os.path.join(os.path.dirname(__file__), '../.bowerrc')
86+
token = os.path.join(os.path.dirname(__file__), '../.token')
8687
jacoco = os.path.join(os.path.dirname(__file__), '../jacoco.xml')
8788
filepath = os.path.join(os.path.dirname(__file__), '../coverage.xml')
8889
coverage = os.path.join(os.path.dirname(__file__), '../.coverage')
@@ -197,6 +198,14 @@ def test_required(self):
197198
output = subprocess.check_output('python -m codecov.__init__ --branch=master --commit=sha', stderr=subprocess.STDOUT, shell=True)
198199
self.assertIn('Missing repository upload token', output.decode('utf-8'))
199200

201+
def test_read_token_file(self):
202+
with open(self.token, 'w+') as f:
203+
f.write('a')
204+
with open(self.filepath, 'w+') as f:
205+
f.write('coverage data')
206+
res = self.run_cli(token='@'+self.token, commit='a', branch='b')
207+
self.assertIn('token=a', res['url'])
208+
200209
def test_bowerrc(self):
201210
with open(self.bowerrc, 'w+') as f:
202211
f.write('{"directory": "tests"}')

0 commit comments

Comments
 (0)