Browse Source

Annotate getChangeByUrl logs with event id

This causes e.g. web requests that should be trackable via the event
id in the logs.

Change-Id: Iade2558f2312aedca7480b4ea1d3df60735cfc90
changes/71/743971/1
Tobias Henkel 9 months ago
parent
commit
e4a207e5c9
No known key found for this signature in database GPG Key ID: 3750DEC158E5FA2
8 changed files with 23 additions and 17 deletions
  1. +4
    -3
      zuul/driver/gerrit/gerritsource.py
  2. +1
    -1
      zuul/driver/git/gitsource.py
  3. +5
    -3
      zuul/driver/github/githubsource.py
  4. +4
    -3
      zuul/driver/gitlab/gitlabsource.py
  5. +3
    -2
      zuul/driver/pagure/pagureconnection.py
  6. +4
    -3
      zuul/driver/pagure/paguresource.py
  7. +1
    -1
      zuul/manager/__init__.py
  8. +1
    -1
      zuul/source/__init__.py

+ 4
- 3
zuul/driver/gerrit/gerritsource.py View File

@ -55,7 +55,7 @@ class GerritSource(BaseSource):
def getChange(self, event, refresh=False):
return self.connection.getChange(event, refresh)
def getChangeByURL(self, url):
def getChangeByURL(self, url, event):
try:
parsed = urllib.parse.urlparse(url)
except ValueError:
@ -71,11 +71,12 @@ class GerritSource(BaseSource):
except ValueError:
return None
query = "change:%s" % (change_no,)
results = self.connection.simpleQuery(query)
results = self.connection.simpleQuery(query, event=event)
if not results:
return None
change = self.connection._getChange(
results[0].number, results[0].current_patchset)
results[0].number, results[0].current_patchset,
event=event)
return change
def getChangesDependingOn(self, change, projects, tenant):


+ 1
- 1
zuul/driver/git/gitsource.py View File

@ -38,7 +38,7 @@ class GitSource(BaseSource):
def getChange(self, event, refresh=False):
return self.connection.getChange(event, refresh)
def getChangeByURL(self, url):
def getChangeByURL(self, url, event):
return None
def getChangesDependingOn(self, change, projects, tenant):


+ 5
- 3
zuul/driver/github/githubsource.py View File

@ -67,7 +67,7 @@ class GithubSource(BaseSource):
change_re = re.compile(r"/(.*?)/(.*?)/pull/(\d+)[\w]*")
def getChangeByURL(self, url):
def getChangeByURL(self, url, event):
try:
parsed = urllib.parse.urlparse(url)
except ValueError:
@ -81,14 +81,16 @@ class GithubSource(BaseSource):
num = int(m.group(3))
except ValueError:
return None
pull, pr_obj = self.connection.getPull('%s/%s' % (org, proj), int(num))
pull, pr_obj = self.connection.getPull(
'%s/%s' % (org, proj), int(num), event=event)
if not pull:
return None
proj = pull.get('base').get('repo').get('full_name')
project = self.getProject(proj)
change = self.connection._getChange(
project, num,
patchset=pull.get('head').get('sha'))
patchset=pull.get('head').get('sha'),
event=event)
return change
def getChangesDependingOn(self, change, projects, tenant):


+ 4
- 3
zuul/driver/gitlab/gitlabsource.py View File

@ -55,7 +55,7 @@ class GitlabSource(BaseSource):
def getChange(self, event, refresh=False):
return self.connection.getChange(event, refresh)
def getChangeByURL(self, url):
def getChangeByURL(self, url, event):
try:
parsed = urllib.parse.urlparse(url)
except ValueError:
@ -68,12 +68,13 @@ class GitlabSource(BaseSource):
num = int(m.group(2))
except ValueError:
return None
mr = self.connection.getPull(project_name, num)
mr = self.connection.getPull(project_name, num, event=event)
if not mr:
return None
project = self.getProject(project_name)
change = self.connection._getChange(
project, num, mr['sha'], url=url)
project, num, mr['sha'], url=url,
event=event)
return change
def getChangesDependingOn(self, change, projects, tenant):


+ 3
- 2
zuul/driver/pagure/pagureconnection.py View File

@ -753,12 +753,13 @@ class PagureConnection(BaseConnection):
change.project.name, change.number, can_merge)
return can_merge
def getPull(self, project_name, number):
def getPull(self, project_name, number, event=None):
log = get_annotated_logger(self.log, event=event)
pagure = self.get_project_api_client(project_name)
pr = pagure.get_pr(number)
diffstats = pagure.get_pr_diffstats(number)
pr['files'] = list(diffstats.keys())
self.log.info('Got PR %s#%s', project_name, number)
log.info('Got PR %s#%s', project_name, number)
return pr
def getStatus(self, project, number):


+ 4
- 3
zuul/driver/pagure/paguresource.py View File

@ -62,7 +62,7 @@ class PagureSource(BaseSource):
def getChange(self, event, refresh=False):
return self.connection.getChange(event, refresh)
def getChangeByURL(self, url):
def getChangeByURL(self, url, event):
try:
parsed = urllib.parse.urlparse(url)
except ValueError:
@ -75,14 +75,15 @@ class PagureSource(BaseSource):
num = int(m.group(2))
except ValueError:
return None
pull = self.connection.getPull(project_name, num)
pull = self.connection.getPull(project_name, num, event=event)
if not pull:
return None
project = self.getProject(project_name)
change = self.connection._getChange(
project, num,
patchset=pull.get('commit_stop'),
url=url)
url=url,
event=event)
return change
def getChangesDependingOn(self, change, projects, tenant):


+ 1
- 1
zuul/manager/__init__.py View File

@ -445,7 +445,7 @@ class PipelineManager(metaclass=ABCMeta):
if not source:
continue
log.debug(" Found source: %s", source)
dep = source.getChangeByURL(match)
dep = source.getChangeByURL(match, event)
if dep and (not dep.is_merged) and dep not in dependencies:
log.debug(" Adding dependency: %s", dep)
dependencies.append(dep)


+ 1
- 1
zuul/source/__init__.py View File

@ -59,7 +59,7 @@ class BaseSource(object, metaclass=abc.ABCMeta):
"""
@abc.abstractmethod
def getChangeByURL(self, url):
def getChangeByURL(self, url, event):
"""Get the change corresponding to the supplied URL.
The URL may may not correspond to this source; if it doesn't,


Loading…
Cancel
Save