Remove refspec

This internal-only attribute is basically the same as "ref" but
spelled differently only in the case of a change.  Just use
the "ref" name in all cases for improved developer sanity.

Change-Id: I476f8d32dae37309ab0c9e11c8a5337b213f985e
changes/75/485875/3
James E. Blair 5 years ago
parent 673dbd1441
commit 247cab7f2c
  1. 5
      tests/base.py
  2. 21
      tests/unit/test_scheduler.py
  3. 4
      zuul/driver/gerrit/gerritconnection.py
  4. 4
      zuul/driver/github/githubconnection.py
  5. 4
      zuul/driver/sql/sqlreporter.py
  6. 4
      zuul/driver/zuul/__init__.py
  7. 4
      zuul/executor/client.py
  8. 2
      zuul/executor/server.py
  9. 19
      zuul/merger/merger.py
  10. 10
      zuul/model.py

@ -1180,7 +1180,7 @@ class FakeBuild(object):
self.log.debug("Build %s continuing" % self.unique)
result = (RecordingAnsibleJob.RESULT_NORMAL, 0) # Success
if (('ZUUL_REF' in self.parameters) and self.shouldFail()):
if self.shouldFail():
result = (RecordingAnsibleJob.RESULT_NORMAL, 1) # Failure
if self.aborted:
result = (RecordingAnsibleJob.RESULT_ABORTED, None)
@ -1215,8 +1215,7 @@ class FakeBuild(object):
except NoSuchPathError as e:
self.log.debug('%s' % e)
return False
ref = self.parameters['ZUUL_REF']
repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
repo_messages = [c.message.strip() for c in repo.iter_commits()]
commit_message = '%s-1' % change.subject
self.log.debug("Checking if build %s has changes; commit_message "
"%s; repo_messages %s" % (self, commit_message,

@ -4776,12 +4776,10 @@ class TestSchedulerMerges(ZuulTestCase):
self.waitUntilSettled()
build = self.builds[-1]
ref = self.getParameter(build, 'ZUUL_REF')
path = os.path.join(build.jobdir.src_root, 'review.example.com',
project)
repo = git.Repo(path)
repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
repo_messages = [c.message.strip() for c in repo.iter_commits()]
repo_messages.reverse()
self.executor_server.hold_jobs_in_build = False
@ -4848,12 +4846,11 @@ class TestSchedulerMerges(ZuulTestCase):
build = self.builds[-1]
self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp')
ref = self.getParameter(build, 'ZUUL_REF')
path = os.path.join(build.jobdir.src_root, 'review.example.com',
'org/project-merge-branches')
repo = git.Repo(path)
repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
repo_messages = [c.message.strip() for c in repo.iter_commits()]
repo_messages.reverse()
correct_messages = [
'initial commit',
@ -4889,16 +4886,14 @@ class TestSchedulerMerges(ZuulTestCase):
for job in self.builds:
if 'project-merge' in job.name:
job_A = job
ref_A = self.getParameter(job_A, 'ZUUL_REF')
commit_A = self.getParameter(job_A, 'ZUUL_COMMIT')
self.log.debug("Got Zuul ref for change A: %s" % ref_A)
self.log.debug("Got Zuul commit for change A: %s" % commit_A)
path = os.path.join(job_A.jobdir.src_root, 'review.example.com',
'org/project-merge-branches')
repo = git.Repo(path)
repo_messages = [c.message.strip()
for c in repo.iter_commits(ref_A)]
for c in repo.iter_commits()]
repo_messages.reverse()
correct_messages = [
'initial commit', 'add content from fixture', 'A-1']
@ -4911,16 +4906,13 @@ class TestSchedulerMerges(ZuulTestCase):
for job in self.builds:
if 'project-merge' in job.name:
job_B = job
ref_B = self.getParameter(job_B, 'ZUUL_REF')
commit_B = self.getParameter(job_B, 'ZUUL_COMMIT')
self.log.debug("Got Zuul ref for change B: %s" % ref_B)
self.log.debug("Got Zuul commit for change B: %s" % commit_B)
path = os.path.join(job_B.jobdir.src_root, 'review.example.com',
'org/project-merge-branches')
repo = git.Repo(path)
repo_messages = [c.message.strip()
for c in repo.iter_commits(ref_B)]
repo_messages = [c.message.strip() for c in repo.iter_commits()]
repo_messages.reverse()
correct_messages = [
'initial commit', 'add content from fixture', 'mp commit', 'B-1']
@ -4933,15 +4925,12 @@ class TestSchedulerMerges(ZuulTestCase):
for job in self.builds:
if 'project-merge' in job.name:
job_C = job
ref_C = self.getParameter(job_C, 'ZUUL_REF')
commit_C = self.getParameter(job_C, 'ZUUL_COMMIT')
self.log.debug("Got Zuul ref for change C: %s" % ref_C)
self.log.debug("Got Zuul commit for change C: %s" % commit_C)
path = os.path.join(job_C.jobdir.src_root, 'review.example.com',
'org/project-merge-branches')
repo = git.Repo(path)
repo_messages = [c.message.strip()
for c in repo.iter_commits(ref_C)]
repo_messages = [c.message.strip() for c in repo.iter_commits()]
repo_messages.reverse()
correct_messages = [

@ -80,7 +80,7 @@ class GerritEventConnector(threading.Thread):
patchset = data.get('patchSet')
if patchset:
event.patch_number = patchset.get('number')
event.refspec = patchset.get('ref')
event.ref = patchset.get('ref')
event.approvals = data.get('approvals', [])
event.comment = data.get('comment')
refupdate = data.get('refUpdate')
@ -418,7 +418,7 @@ class GerritConnection(BaseConnection):
files = []
for ps in data['patchSets']:
if ps['number'] == change.patchset:
change.refspec = ps['ref']
change.ref = ps['ref']
for f in ps.get('files', []):
files.append(f['file'])
if int(ps['number']) > int(max_ps):

@ -299,7 +299,7 @@ class GithubWebhookListener():
event.change_number)
event.updated_at = pr_body.get('updated_at')
event.branch = base.get('ref')
event.refspec = "refs/pull/" + str(pr_body.get('number')) + "/head"
event.ref = "refs/pull/" + str(pr_body.get('number')) + "/head"
event.patch_number = head.get('sha')
event.title = pr_body.get('title')
@ -601,7 +601,7 @@ class GithubConnection(BaseConnection):
self.log.info("Updating %s" % (change,))
change.pr = self.getPull(change.project.name, change.number)
change.refspec = "refs/pull/%s/head" % change.number
change.ref = "refs/pull/%s/head" % change.number
change.branch = change.pr.get('base').get('ref')
change.files = change.pr.get('files')
change.title = change.pr.get('title')

@ -41,14 +41,14 @@ class SQLReporter(BaseReporter):
with self.connection.engine.begin() as conn:
change = getattr(item.change, 'number', '')
patchset = getattr(item.change, 'patchset', '')
refspec = getattr(item.change, 'refspec', item.change.newrev)
ref = getattr(item.change, 'ref', '')
buildset_ins = self.connection.zuul_buildset_table.insert().values(
zuul_ref=item.current_build_set.ref,
pipeline=item.pipeline.name,
project=item.change.project.name,
change=change,
patchset=patchset,
ref=refspec,
ref=ref,
score=self.result_score,
message=self._formatItemReport(
item, with_jobs=False),

@ -82,7 +82,7 @@ class ZuulDriver(Driver, TriggerInterface):
event.branch = change.branch
event.change_url = change.url
event.patch_number = change.patchset
event.refspec = change.refspec
event.ref = change.ref
self.sched.addEvent(event)
def _createParentChangeEnqueuedEvents(self, change, pipeline):
@ -104,7 +104,7 @@ class ZuulDriver(Driver, TriggerInterface):
event.branch = change.branch
event.change_url = change.url
event.patch_number = change.patchset
event.refspec = change.refspec
event.ref = change.ref
self.sched.addEvent(event)
def getTrigger(self, connection_name, config=None):

@ -196,10 +196,10 @@ class ExecutorClient(object):
params['ZUUL_PIPELINE'] = pipeline.name
params['ZUUL_URL'] = item.current_build_set.zuul_url
params['ZUUL_VOTING'] = job.voting and '1' or '0'
if hasattr(item.change, 'refspec'):
if hasattr(item.change, 'number'):
changes_str = '^'.join(
['%s:%s:%s' % (i.change.project.name, i.change.branch,
i.change.refspec)
i.change.ref)
for i in all_items])
params['ZUUL_BRANCH'] = item.change.branch
params['ZUUL_CHANGES'] = changes_str

@ -848,7 +848,7 @@ class AnsibleJob(object):
project['name'])
repos[project['canonical_name']] = repo
merge_items = [i for i in args['items'] if i.get('refspec')]
merge_items = [i for i in args['items'] if i.get('number')]
if merge_items:
if not self.doMergeChanges(merger, merge_items,
args['repo_state']):

@ -225,9 +225,9 @@ class Repo(object):
except AssertionError:
origin.fetch(ref)
def fetchFrom(self, repository, refspec):
def fetchFrom(self, repository, ref):
repo = self.createRepoObject()
repo.git.fetch(repository, refspec)
repo.git.fetch(repository, ref)
def createZuulRef(self, ref, commit='HEAD'):
repo = self.createRepoObject()
@ -391,11 +391,11 @@ class Merger(object):
try:
mode = item['merge_mode']
if mode == zuul.model.MERGER_MERGE:
commit = repo.merge(item['refspec'])
commit = repo.merge(item['ref'])
elif mode == zuul.model.MERGER_MERGE_RESOLVE:
commit = repo.merge(item['refspec'], 'resolve')
commit = repo.merge(item['ref'], 'resolve')
elif mode == zuul.model.MERGER_CHERRY_PICK:
commit = repo.cherryPick(item['refspec'])
commit = repo.cherryPick(item['ref'])
else:
raise Exception("Unsupported merge mode: %s" % mode)
except git.GitCommandError:
@ -410,9 +410,10 @@ class Merger(object):
return commit
def _mergeItem(self, item, recent, repo_state):
self.log.debug("Processing refspec %s for project %s/%s / %s ref %s" %
(item['refspec'], item['connection'],
item['project'], item['branch'], item['ref']))
self.log.debug("Processing ref %s for project %s/%s / %s uuid %s" %
(item['ref'], item['connection'],
item['project'], item['branch'],
item['buildset_uuid']))
repo = self.getRepo(item['connection'], item['project'])
key = (item['connection'], item['project'], item['branch'])
@ -451,7 +452,7 @@ class Merger(object):
zuul_ref = None
try:
repo = self.getRepo(connection, project)
zuul_ref = branch + '/' + item['ref']
zuul_ref = branch + '/' + item['buildset_uuid']
if not repo.getCommitFromRef(zuul_ref):
repo.createZuulRef(zuul_ref, mrc)
except Exception:

@ -1841,12 +1841,10 @@ class QueueItem(object):
patchset = None
oldrev = None
newrev = None
refspec = None
branch = None
if hasattr(self.change, 'number'):
number = self.change.number
patchset = self.change.patchset
refspec = self.change.refspec
if hasattr(self.change, 'newrev'):
oldrev = self.change.oldrev
newrev = self.change.newrev
@ -1860,9 +1858,9 @@ class QueueItem(object):
return dict(project=project.name,
connection=connection_name,
merge_mode=self.current_build_set.getMergeMode(),
refspec=refspec,
ref=self.change.ref,
branch=branch,
ref=self.current_build_set.ref,
buildset_uuid=self.current_build_set.uuid,
number=number,
patchset=patchset,
oldrev=oldrev,
@ -1951,7 +1949,6 @@ class Change(Branch):
self.number = None
self.url = None
self.patchset = None
self.refspec = None
self.needs_changes = []
self.needed_by_changes = []
@ -2008,6 +2005,7 @@ class TriggerEvent(object):
# common
self.type = None
self.branch_updated = False
self.ref = None
# For management events (eg: enqueue / promote)
self.tenant_name = None
self.project_hostname = None
@ -2019,12 +2017,10 @@ class TriggerEvent(object):
self.change_number = None
self.change_url = None
self.patch_number = None
self.refspec = None
self.branch = None
self.comment = None
self.state = None
# ref-updated
self.ref = None
self.oldrev = None
self.newrev = None
# For events that arrive with a destination pipeline (eg, from

Loading…
Cancel
Save