From 89516b481bb43cec0d1eecebf3fbed7be2494b3f Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Fri, 28 Jul 2017 20:05:07 +0200 Subject: [PATCH] Use project object in _uploadPack in gerrit driver During playing around with mypy I found out that the _uploadPack method actually expects the project name but is called with the project object from every caller. This actually worked by accident as formatting the project object results in the correct string due to the __str__ method. Nevertheless this is incorrect and should be fixed. Additionally add some type annotations there. Change-Id: Ia066d6cade04db1fe6e01102e70c774660ae4327 --- zuul/driver/gerrit/gerritconnection.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/zuul/driver/gerrit/gerritconnection.py b/zuul/driver/gerrit/gerritconnection.py index 63f30937dc..d23857f2bd 100644 --- a/zuul/driver/gerrit/gerritconnection.py +++ b/zuul/driver/gerrit/gerritconnection.py @@ -25,8 +25,10 @@ import shlex import queue import voluptuous as v +from typing import Dict, List + from zuul.connection import BaseConnection -from zuul.model import Ref, Tag, Branch +from zuul.model import Ref, Tag, Branch, Project from zuul import exceptions from zuul.driver.gerrit.gerritmodel import GerritChange, GerritTriggerEvent @@ -614,7 +616,7 @@ class GerritConnection(BaseConnection): (record.get('number'),)) return changes - def getProjectBranches(self, project): + def getProjectBranches(self, project: Project) -> List[str]: refs = self.getInfoRefs(project) heads = [str(k[len('refs/heads/'):]) for k in refs.keys() if k.startswith('refs/heads/')] @@ -711,8 +713,8 @@ class GerritConnection(BaseConnection): chunk, more_changes = _query_chunk("%s %s" % (query, resume)) return alldata - def _uploadPack(self, project_name): - cmd = "git-upload-pack %s" % project_name + def _uploadPack(self, project: Project) -> str: + cmd = "git-upload-pack %s" % project.name out, err = self._ssh(cmd, "0000") return out @@ -757,7 +759,7 @@ class GerritConnection(BaseConnection): raise Exception("Gerrit error executing %s" % command) return (out, err) - def getInfoRefs(self, project): + def getInfoRefs(self, project: Project) -> Dict[str, str]: try: data = self._uploadPack(project) except: