Skip to content

Commit

Permalink
Merge pull request #8 from jayvdb/private_repo
Browse files Browse the repository at this point in the history
Add support for Travis CI Pro and enterprise travis installations
  • Loading branch information
jayvdb committed Nov 11, 2015
2 parents b11315a + 2c2b94e commit 922b753
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion travis_log_fetch/_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def download_job_log(base_dir, job, log_filename_format=None):
# FIXME(upstream): https://github.com/menegazzo/travispy/pull/27
if not text:
__logs__.info('fetching job {0} log directly'.format(job.id))
r = requests.get('https://api.travis-ci.org/jobs/%s/log' % job.id,
r = requests.get('%s/jobs/%s/log' % (job._session.uri, job.id),
headers=_HEADERS)
text = r.content.decode('utf-8')

Expand Down
15 changes: 12 additions & 3 deletions travis_log_fetch/_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import sys

if sys.version_info[0] == 2:
from urlparse import urlparse
else:
from urllib.parse import urlparse

from travispy import Build, Job, Repo


Expand Down Expand Up @@ -153,9 +160,11 @@ def from_extended_slug(cls, slug):
@classmethod
def from_url(cls, url):
"""Create an Target from a travis url."""
_, _, path = url.partition('//travis-ci.org/')
assert path
path, _, line_no = path.partition('#')
parsed_url = urlparse(url)
assert parsed_url.path
assert len(parsed_url.path) > 1

path = parsed_url.path[1:]

parts = path.split('/')

Expand Down
10 changes: 8 additions & 2 deletions travis_log_fetch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def get_parser():
default='~/.travis')
parser.add('--access-token', required=False, help='Github access token',
env_var='GITHUB_ACCESS_TOKEN')
parser.add('--api', required=False,
help='Travis API CI URL; use "pro" for Travis CI Pro',
default=travispy.travispy.PUBLIC)
parser.add('-v', '--verbose', help='verbose', action='store_true')
parser.add('-r', '--refresh', help='refresh', action='store_true')
parser.add('--forks', help='fetch forks', action='store_true')
Expand Down Expand Up @@ -72,6 +75,8 @@ def get_options():

try:
_options = parser.parse_args(args=args)
if _options.api == 'pro':
_options.api = travispy.travispy.PRIVATE
__logs__.debug('config options: {0}'.format(_options))
except SystemExit:
if pytest:
Expand All @@ -92,10 +97,11 @@ def _get_travispy():
if not _travispy:
options = get_options()
if options and options.access_token:
_travispy = travispy.TravisPy.github_auth(options.access_token)
_travispy = travispy.TravisPy.github_auth(
options.access_token, uri=options.api)
__logs__.debug('logged into travis-ci')
else:
_travispy = travispy.TravisPy()
_travispy = travispy.TravisPy(uri=options.api)
__logs__.debug('anon travis-ci activated')

return _travispy
Expand Down

0 comments on commit 922b753

Please sign in to comment.