Merge "Remove hostname hardcode from commit records links"

This commit is contained in:
Zuul 2019-03-12 18:26:03 +00:00 committed by Gerrit Code Review
commit d23e09f337
4 changed files with 68 additions and 13 deletions

View File

@ -297,6 +297,9 @@ def make_blueprint_link(module, name):
def make_commit_message(record):
s = record['message']
module = record['module']
# NOTE(aostapenko) Keeping default value here not to brake links
# with existing storage data
gerrit_hostname = record.get('gerrit_hostname', 'review.openstack.org')
s = utils.format_text(s)
@ -307,8 +310,10 @@ def make_commit_message(record):
s = re.sub(re.compile('(bug[\s#:]*)([\d]{5,7})', flags=re.IGNORECASE),
r'\1<a href="https://bugs.launchpad.net/bugs/\2" '
r'class="ext_link">\2</a>', s)
# NOTE(aostapenko) Setting http here as it's common practice to redirect
# http -> https, but not vice versa
s = re.sub(r'\s+(I[0-9a-f]{40})',
r' <a href="https://review.openstack.org/#/q/\1" '
r' <a href="http://%s/#/q/\1" ' % gerrit_hostname +
r'class="ext_link">\1</a>', s)
s = utils.unwrap_text(s)

View File

@ -71,12 +71,16 @@ def _merge_commits(original, new):
return True
def _record_typer(record_iterator, record_type):
def _param_adder(record_iterator, key, value):
for record in record_iterator:
record['record_type'] = record_type
record[key] = value
yield record
def _record_typer(record_iterator, record_type):
return _param_adder(record_iterator, 'record_type', record_type)
def _get_repo_branches(repo):
return ({repo.get('default_branch', 'master')} |
set(r['branch'] for r in repo.get('releases', [])
@ -147,6 +151,9 @@ def _process_repo_reviews(repo, runtime_storage_inst, record_processor_inst):
def _process_repo_vcs(repo, runtime_storage_inst, record_processor_inst):
vcs_inst = vcs.get_vcs(repo, CONF.sources_root)
vcs_inst.fetch()
gerrit_hostname, _ = rcs.get_socket_tuple_from_uri(
repo.get('gerrit_uri', CONF.review_uri)
)
for branch in _get_repo_branches(repo):
LOG.info('Processing commits in repo: %s, branch: %s',
@ -157,7 +164,10 @@ def _process_repo_vcs(repo, runtime_storage_inst, record_processor_inst):
last_id = runtime_storage_inst.get_by_key(vcs_key)
commit_iterator = vcs_inst.log(branch, last_id)
commit_iterator_typed = _record_typer(commit_iterator, 'commit')
commit_iterator_review = _param_adder(
commit_iterator, 'gerrit_hostname', gerrit_hostname
)
commit_iterator_typed = _record_typer(commit_iterator_review, 'commit')
processed_commit_iterator = record_processor_inst.process(
commit_iterator_typed)
runtime_storage_inst.set_records(

View File

@ -29,6 +29,17 @@ REQUEST_COUNT_LIMIT = 20
SSH_ERRORS_LIMIT = 10
def get_socket_tuple_from_uri(uri):
stripped = re.sub(GERRIT_URI_PREFIX, '', uri)
if stripped:
hostname, semicolon, port = stripped.partition(':')
if not port:
port = DEFAULT_PORT
else:
raise RcsException('Invalid rcs uri %s' % uri)
return hostname, port
class RcsException(Exception):
pass
@ -57,13 +68,7 @@ class Gerrit(Rcs):
def __init__(self, uri):
super(Gerrit, self).__init__()
stripped = re.sub(GERRIT_URI_PREFIX, '', uri)
if stripped:
self.hostname, semicolon, self.port = stripped.partition(':')
if not self.port:
self.port = DEFAULT_PORT
else:
raise RcsException('Invalid rcs uri %s' % uri)
self.hostname, self.port = get_socket_tuple_from_uri(uri)
self.key_filename = None
self.username = None

View File

@ -46,7 +46,42 @@ returned.
Fixes bug <a href="https://bugs.launchpad.net/bugs/1076801" class="ext_link">\
1076801</a>
''' + (
'Change-Id: <a href="https://review.openstack.org/#/q/'
'Change-Id: <a href="http://review.openstack.org/#/q/'
'Ie49ccd2138905e178843b375a9b16c3fe572d1db" class="ext_link">'
'Ie49ccd2138905e178843b375a9b16c3fe572d1db</a>')
observed = helpers.make_commit_message(record)
self.assertEqual(expected, observed,
'Commit message should be processed correctly')
def test_make_commit_message_gerrit_host(self):
message = '''
During finish_migration the manager calls initialize_connection but doesn't
update the block_device_mapping with the potentially new connection_info
returned.
Fixes bug 1076801
Change-Id: Ie49ccd2138905e178843b375a9b16c3fe572d1db'''
module = 'test'
gerrit = 'someothergerrit.org'
record = {
'message': message,
'module': module,
'gerrit_hostname': gerrit,
}
expected = '''\
During finish_migration the manager calls initialize_connection but doesn't \
update the block_device_mapping with the potentially new connection_info \
returned.
Fixes bug <a href="https://bugs.launchpad.net/bugs/1076801" class="ext_link">\
1076801</a>
''' + (
'Change-Id: <a href="http://%s/#/q/' % gerrit +
'Ie49ccd2138905e178843b375a9b16c3fe572d1db" class="ext_link">'
'Ie49ccd2138905e178843b375a9b16c3fe572d1db</a>')
@ -73,7 +108,7 @@ Implemented new driver for Cinder &lt;:
Implements Blueprint ''' + (
'<a href="https://blueprints.launchpad.net/cinder/+spec/'
'super-driver" class="ext_link">super-driver</a>' + '\n' +
'Change-Id: <a href="https://review.openstack.org/#/q/'
'Change-Id: <a href="http://review.openstack.org/#/q/'
'Ie49ccd2138905e178843b375a9b16c3fe572d1db" class="ext_link">'
'Ie49ccd2138905e178843b375a9b16c3fe572d1db</a>')