pagure: ensure files is list and not a dict_keys

This fixes an issue with project defining a Zuul job config that
use a file matcher:

2020-06-01 12:18:35,833 ERROR zuul.Pipeline.fedora.check: Error freezing job graph for <QueueItem 0x7f7e8e465438 for <Change 0x7f7ea0c8f748 project: fedora-infra/ansible number: 100 patchset: cb7ab828c28754fe0a4d02f0d5c0aecf7921e016 updated: 1591013908 status: failure state: open> in check>
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/zuul/manager/__init__.py", line 798, in prepareItem
    item.freezeJobGraph()
  File "/usr/lib/python3.6/site-packages/zuul/model.py", line 2208, in freezeJobGraph
    self, ppc, skip_file_matcher)
  File "/usr/lib/python3.6/site-packages/zuul/model.py", line 4190, in createJobGraph
    self._createJobGraph(item, ppc, ret, skip_file_matcher)
  File "/usr/lib/python3.6/site-packages/zuul/model.py", line 4145, in _createJobGraph
    not frozen_job.changeMatchesFiles(change):
  File "/usr/lib/python3.6/site-packages/zuul/model.py", line 1678, in changeMatchesFiles
    if self.file_matcher and not self.file_matcher.matches(change):
  File "/usr/lib/python3.6/site-packages/zuul/change_matcher.py", line 149, in matches
    if len(change.files) == 1 and self.commit_regex.match(change.files[0]):
TypeError: 'dict_keys' object does not support indexing

Change-Id: I40f503b1e3d9629472c759911b15b718e6c79cff
This commit is contained in:
Fabien Boucher 2020-06-01 14:32:48 +02:00
parent ba94d07e8a
commit 67e55a35c3
4 changed files with 51 additions and 5 deletions

View File

@ -1131,7 +1131,7 @@ class FakePagurePullRequest(object):
log = logging.getLogger("zuul.test.FakePagurePullRequest")
def __init__(self, pagure, number, project, branch,
subject, upstream_root, files=[], number_of_commits=1,
subject, upstream_root, files={}, number_of_commits=1,
initial_comment=None):
self.pagure = pagure
self.source = pagure
@ -1291,17 +1291,17 @@ class FakePagurePullRequest(object):
return PagureChangeReference.create(
repo, self.getPRReference(), 'refs/tags/init')
def addCommit(self, files=[]):
def addCommit(self, files={}):
"""Adds a commit on top of the actual PR head."""
self._addCommitInPR(files=files)
self._updateTimeStamp()
def forcePush(self, files=[]):
def forcePush(self, files={}):
"""Clears actual commits and add a commit on top of the base."""
self._addCommitInPR(files=files, reset=True)
self._updateTimeStamp()
def _addCommitInPR(self, files=[], reset=False):
def _addCommitInPR(self, files={}, reset=False):
repo = self._getRepo()
ref = repo.references[self.getPRReference()]
if reset:

View File

@ -0,0 +1,24 @@
- pipeline:
name: check
manager: independent
trigger:
pagure:
- event: pg_pull_request
action: opened
- job:
name: base
parent: null
run: playbooks/base.yaml
- job:
name: project-test1
files:
- .*-requires
run: playbooks/project-test1.yaml
- project:
name: org/project
check:
jobs:
- project-test1

View File

@ -284,6 +284,28 @@ class TestPagureDriver(ZuulTestCase):
], ordered=False
)
@simple_layout('layouts/files-pagure.yaml', driver='pagure')
def test_pull_matched_file_event(self):
A = self.fake_pagure.openFakePullRequest(
'org/project', 'master', 'A',
files={'random.txt': 'test', 'build-requires': 'test'})
self.fake_pagure.emitEvent(A.getPullRequestOpenedEvent())
self.waitUntilSettled()
self.assertEqual(1, len(self.history))
B = self.fake_pagure.openFakePullRequest('org/project', 'master', 'B',
files={'random.txt': 'test2'})
self.fake_pagure.emitEvent(B.getPullRequestOpenedEvent())
self.waitUntilSettled()
self.assertEqual(1, len(self.history))
C = self.fake_pagure.openFakePullRequest(
'org/project', 'master', 'C',
files={'build-requires': 'test'})
self.fake_pagure.emitEvent(C.getPullRequestOpenedEvent())
self.waitUntilSettled()
self.assertEqual(2, len(self.history))
@simple_layout('layouts/basic-pagure.yaml', driver='pagure')
def test_tag_created(self):

View File

@ -757,7 +757,7 @@ class PagureConnection(BaseConnection):
pagure = self.get_project_api_client(project_name)
pr = pagure.get_pr(number)
diffstats = pagure.get_pr_diffstats(number)
pr['files'] = diffstats.keys()
pr['files'] = list(diffstats.keys())
self.log.info('Got PR %s#%s', project_name, number)
return pr