Handle no file commits in the Gerrit driver

It is possible to push no file commits to Gerrit. We had previous code
looking for this case by checking for the special '/COMMIT_MSG' file
entry as the only entry in change.files. Unfortunately, the gerrit http
connection queries were returning a dict of files in the form of
{'name': {attrs}' and this broke the special checking for the single
commit message entry.

We fix this by coercing the type of the returned files data from a dict
to a list of file names.

Change-Id: Ie475911b1c9668bd831c4d31213a2fd3a8c049a7
This commit is contained in:
Clark Boylan 2021-10-01 08:29:30 -07:00
parent 5858510e22
commit c26238bb57
1 changed files with 9 additions and 1 deletions

View File

@ -83,6 +83,8 @@ class GerritChange(Change):
if str(ps['number']) == self.patchset:
self.ref = ps['ref']
self.commit = ps['revision']
# SSH queries gives us a list of dicts for the files. We
# convert that to a list of filenames.
for f in ps.get('files', []):
files.append(f['file'])
if int(ps['number']) > int(max_ps):
@ -142,7 +144,13 @@ class GerritChange(Change):
self.is_current_patchset = True
else:
self.is_current_patchset = False
self.files = files or []
# HTTP queries give us a dict of files in the form of
# {filename: { attrs }}. We only want a list of filenames here.
if files:
self.files = list(files.keys())
else:
self.files = []
self.is_merged = data['status'] == 'MERGED'
self.approvals = []