From c015c1aa845f8db8f386eefa3181e2da4b3c007a Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Mon, 17 Apr 2023 10:40:04 -0500 Subject: gerrit: Handle case where commit has no parents If a commit has no parents (e.g. the first commit in a repository), the HTTP request to gerrit to the revision files endpoint must not specify the parent=1 query parameter. Otherwise, gerrit will return an HTTP 400 error with the message 'invalid parent number: 1'. Explicitly check for this by examining if any parents are present for the current revision before adding the query parameter Change-Id: I3f93899dc79ebc716223ecc6f5adecd0f1ce9b3e --- zuul/driver/gerrit/gerritconnection.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'zuul/driver') diff --git a/zuul/driver/gerrit/gerritconnection.py b/zuul/driver/gerrit/gerritconnection.py index 6efca17c5..990b7b235 100644 --- a/zuul/driver/gerrit/gerritconnection.py +++ b/zuul/driver/gerrit/gerritconnection.py @@ -1476,8 +1476,14 @@ class GerritConnection(ZKChangeCacheMixin, ZKBranchCacheMixin, BaseConnection): data = self.get(query) related = self.get('changes/%s/revisions/%s/related' % ( number, data['current_revision'])) - files = self.get('changes/%s/revisions/%s/files?parent=1' % ( - number, data['current_revision'])) + + files_query = 'changes/%s/revisions/%s/files' % ( + number, data['current_revision']) + + if data['revisions'][data['current_revision']]['commit']['parents']: + files_query += '?parent=1' + + files = self.get(files_query) return data, related, files def queryChange(self, number, event=None): -- cgit v1.2.1