From bb4c83bf8d1923f20fb9e08c9751133118172e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Wed, 22 Oct 2014 21:56:06 +0200 Subject: [PATCH] Fix changeset fetching This change adds support for fetching over the anonymous git and authenticated SSH protocols, and it also makes sure that we follow URLs specified by the download plugin (they might differ from the server's address even for anonymous HTTP). Also see https://storyboard.openstack.org/#!/story/294 . Change-Id: Iafb7ae63147fc7a70ab63a9d6f61617b87e65ac9 --- gertty/sync.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/gertty/sync.py b/gertty/sync.py index c24f8ce..0c91998 100644 --- a/gertty/sync.py +++ b/gertty/sync.py @@ -474,18 +474,35 @@ class SyncChangeTask(Task): for remote_commit, remote_revision in remote_change.get('revisions', {}).items(): revision = session.getRevisionByCommit(remote_commit) # TODO: handle multiple parents - url = sync.app.config.url + change.project.name - if 'anonymous http' in remote_revision['fetch']: - ref = remote_revision['fetch']['anonymous http']['ref'] + if 'git' in remote_revision['fetch']: + ref = remote_revision['fetch']['git']['ref'] + url = remote_revision['fetch']['git']['url'] auth = False - else: + elif 'anonymous http' in remote_revision['fetch']: + ref = remote_revision['fetch']['anonymous http']['ref'] + url = remote_revision['fetch']['anonymous http']['url'] + auth = False + elif 'http' in remote_revision['fetch']: auth = True ref = remote_revision['fetch']['http']['ref'] - url = list(urlparse.urlsplit(url)) + url = list(urlparse.urlsplit(sync.app.config.url + change.project.name)) url[1] = '%s:%s@%s' % ( urllib.quote_plus(sync.app.config.username), urllib.quote_plus(sync.app.config.password), url[1]) url = urlparse.urlunsplit(url) + elif 'ssh' in remote_revision['fetch']: + ref = remote_revision['fetch']['ssh']['ref'] + url = remote_revision['fetch']['ssh']['url'] + auth = False + else: + if len(remote_revision['fetch']): + errMessage = 'Don\'t know how to download changes. ' \ + 'Server offered these schemes, but Gertty doesn\'t support any of them: %s' \ + % ', '.join(remote_revision['fetch'].keys()) + else: + errMessage = 'The server is missing the download-commands plugin. ' \ + 'Don\'t know how to download revisions.' + raise Exception(errMessage) if (not revision) or self.force_fetch: fetches[url].append('+%(ref)s:%(ref)s' % dict(ref=ref)) if not revision: