Change status json to use "refs" instead of "changes"

This is mostly an internal API change to replace the use of the
word "change" with "ref" in the status json.  This matches the
database and build/buildsets records.

Change-Id: Id468d16d6deb0af3d1c0f74beb1b25630455b8f9
This commit is contained in:
James E. Blair 2024-02-02 11:05:38 -08:00
parent 1f026bd49c
commit 1cc276687a
7 changed files with 57 additions and 57 deletions

View File

@ -4591,9 +4591,9 @@ class TestScheduler(ZuulTestCase):
first = pipeline_status['change_queues'][0]['heads'][0][0]
second = pipeline_status['change_queues'][1]['heads'][0][0]
self.assertIn(first['changes'][0]['ref'],
self.assertIn(first['refs'][0]['ref'],
['refs/heads/master', 'refs/heads/stable'])
self.assertIn(second['changes'][0]['ref'],
self.assertIn(second['refs'][0]['ref'],
['refs/heads/master', 'refs/heads/stable'])
self.executor_server.hold_jobs_in_build = False

View File

@ -176,9 +176,9 @@ class TestWeb(BaseTestWeb):
for item in head:
self.assertIn(
'review.example.com/org/project',
item['changes'][0]['project_canonical'])
item['refs'][0]['project_canonical'])
self.assertTrue(item['active'])
change = item['changes'][0]
change = item['refs'][0]
self.assertIn(change['id'], ('1,1', '2,1', '3,1'))
for job in item['jobs']:
status_jobs.append(job)
@ -335,12 +335,12 @@ class TestWeb(BaseTestWeb):
data = self.get_url("api/tenant/tenant-one/status/change/1,1").json()
self.assertEqual(1, len(data), data)
self.assertEqual("org/project", data[0]['changes'][0]['project'])
self.assertEqual("org/project", data[0]['refs'][0]['project'])
data = self.get_url("api/tenant/tenant-one/status/change/2,1").json()
self.assertEqual(1, len(data), data)
self.assertEqual("org/project1", data[0]['changes'][0]['project'],
self.assertEqual("org/project1", data[0]['refs'][0]['project'],
data)
@simple_layout('layouts/nodeset-alternatives.yaml')

View File

@ -39,10 +39,10 @@ import LineAngleImage from '../../images/line-angle.png'
import LineTImage from '../../images/line-t.png'
import ItemPanel from './ItemPanel'
function getChange(item) {
// For backwards compat: get a representative change for this item
function getRef(item) {
// For backwards compat: get a representative ref for this item
// if there is more than one.
return 'changes' in item ? item.changes[0] : item
return 'refs' in item ? item.refs[0] : item
}
class Item extends React.Component {
@ -65,16 +65,16 @@ class Item extends React.Component {
dequeueConfirm = () => {
const { tenant, item, pipeline } = this.props
const change = getChange(item)
// Use the first change as a proxy for the item since queue
const ref = getRef(item)
// Use the first ref as a proxy for the item since queue
// commands operate on changes
let projectName = change.project
let changeId = change.id || 'N/A'
let changeRef = change.ref
let projectName = ref.project
let refId = ref.id || 'N/A'
let refRef = ref.ref
this.setState(() => ({ showDequeueModal: false }))
// post-merge
if (changeId !== 'N/A') {
dequeue(tenant.apiPrefix, projectName, pipeline.name, changeId)
if (refId !== 'N/A') {
dequeue(tenant.apiPrefix, projectName, pipeline.name, refId)
.then(() => {
this.props.dispatch(fetchStatusIfNeeded(tenant))
})
@ -82,7 +82,7 @@ class Item extends React.Component {
this.props.dispatch(addDequeueError(error))
})
} else {
dequeue_ref(tenant.apiPrefix, projectName, pipeline.name, changeRef)
dequeue_ref(tenant.apiPrefix, projectName, pipeline.name, refRef)
.then(() => {
this.props.dispatch(fetchStatusIfNeeded(tenant))
})
@ -99,9 +99,9 @@ class Item extends React.Component {
renderDequeueModal() {
const { showDequeueModal } = this.state
const { item } = this.props
const change = getChange(item)
let projectName = change.project
let changeId = change.id || change.ref
const ref = getRef(item)
let projectName = ref.project
let refId = ref.id || ref.ref
const title = 'You are about to dequeue a change'
return (
<Modal
@ -114,18 +114,18 @@ class Item extends React.Component {
<Button key="deq_confirm" variant="primary" onClick={this.dequeueConfirm}>Confirm</Button>,
<Button key="deq_cancel" variant="link" onClick={this.dequeueCancel}>Cancel</Button>,
]}>
<p>Please confirm that you want to cancel <strong>all ongoing builds</strong> on change <strong>{changeId}</strong> for project <strong>{projectName}</strong>.</p>
<p>Please confirm that you want to cancel <strong>all ongoing builds</strong> on change <strong>{refId}</strong> for project <strong>{projectName}</strong>.</p>
</Modal>
)
}
promoteConfirm = () => {
const { tenant, item, pipeline } = this.props
const change = getChange(item)
let changeId = change.id || 'NA'
const ref = getRef(item)
let refId = ref.id || 'NA'
this.setState(() => ({ showPromoteModal: false }))
if (changeId !== 'N/A') {
promote(tenant.apiPrefix, pipeline.name, [changeId,])
if (refId !== 'N/A') {
promote(tenant.apiPrefix, pipeline.name, [refId,])
.then(() => {
this.props.dispatch(fetchStatusIfNeeded(tenant))
})
@ -135,7 +135,7 @@ class Item extends React.Component {
} else {
this.props.dispatch(addNotification({
url: null,
status: 'Invalid change ' + changeId + ' for promotion',
status: 'Invalid change ' + refId + ' for promotion',
text: '',
type: 'error'
}))
@ -149,8 +149,8 @@ class Item extends React.Component {
renderPromoteModal() {
const { showPromoteModal } = this.state
const { item } = this.props
const change = getChange(item)
let changeId = change.id || 'N/A'
const ref = getRef(item)
let refId = ref.id || 'N/A'
const title = 'You are about to promote a change'
return (
<Modal
@ -163,7 +163,7 @@ class Item extends React.Component {
<Button key="prom_confirm" variant="primary" onClick={this.promoteConfirm}>Confirm</Button>,
<Button key="prom_cancel" variant="link" onClick={this.promoteCancel}>Cancel</Button>,
]}>
<p>Please confirm that you want to promote change <strong>{changeId}</strong>.</p>
<p>Please confirm that you want to promote change <strong>{refId}</strong>.</p>
</Modal>
)
}
@ -245,7 +245,7 @@ class Item extends React.Component {
)
if (item.live) {
return (
<Link to={this.props.tenant.linkPrefix + '/status/change/' + getChange(item).id}>
<Link to={this.props.tenant.linkPrefix + '/status/change/' + getRef(item).id}>
{icon}
</Link>
)

View File

@ -21,9 +21,9 @@ import * as moment from 'moment'
import 'moment-duration-format'
import { Button } from '@patternfly/react-core'
function getChanges(item) {
// For backwards compat: get a list of this items changes.
return 'changes' in item ? item.changes : [item]
function getRefs(item) {
// For backwards compat: get a list of this items refs.
return 'refs' in item ? item.refs : [item]
}
class ItemPanel extends React.Component {
@ -415,7 +415,7 @@ class ItemPanel extends React.Component {
</div>
</div>
) : ''}
{getChanges(item).map((change, idx) => (
{getRefs(item).map((change, idx) => (
<div key={idx} className='row'>
<div className='col-xs-8'>
<span className='change_project'>{change.project}</span>

View File

@ -25,7 +25,7 @@ import ItemPanel from './ItemPanel'
const fakeItem = {
changes: [{
refs: [{
project: 'org-project'
}],
jobs: [{
@ -71,7 +71,7 @@ it('item panel render white-label tenant links', () => {
it('item panel skip jobs', () => {
const fakeItem = {
changes: [{
refs: [{
project: 'org-project'
}],
jobs: [{

View File

@ -5906,34 +5906,34 @@ class QueueItem(zkobject.ZKObject):
ret = {}
ret['active'] = self.active
ret['live'] = self.live
changes = []
refs = []
for change in self.changes:
ret_change = {}
ret_ref = {}
if hasattr(change, 'url') and change.url is not None:
ret_change['url'] = change.url
ret_ref['url'] = change.url
else:
ret_change['url'] = None
ret_ref['url'] = None
if hasattr(change, 'ref') and change.ref is not None:
ret_change['ref'] = change.ref
ret_ref['ref'] = change.ref
else:
ret_change['ref'] = None
ret_ref['ref'] = None
if change.project:
ret_change['project'] = change.project.name
ret_change['project_canonical'] = change.project.canonical_name
ret_ref['project'] = change.project.name
ret_ref['project_canonical'] = change.project.canonical_name
else:
# For cross-project dependencies with the depends-on
# project not known to zuul, the project is None
# Set it to a static value
ret_change['project'] = "Unknown Project"
ret_change['project_canonical'] = "Unknown Project"
ret_ref['project'] = "Unknown Project"
ret_ref['project_canonical'] = "Unknown Project"
if hasattr(change, 'owner'):
ret_change['owner'] = change.owner
ret_ref['owner'] = change.owner
else:
ret_change['owner'] = None
ret_change['id'] = change._id()
changes.append(ret_change)
ret_ref['owner'] = None
ret_ref['id'] = change._id()
refs.append(ret_ref)
ret['id'] = self.uuid
ret['changes'] = changes
ret['refs'] = refs
if self.item_ahead:
ret['item_ahead'] = self.item_ahead.uuid
else:

View File

@ -376,7 +376,7 @@ def json_handler(*args, **kwargs):
return json_encoder.iterencode(value)
class ChangeFilter(object):
class RefFilter(object):
def __init__(self, desired):
self.desired = desired
@ -387,16 +387,16 @@ class ChangeFilter(object):
for head in change_queue['heads']:
for item in head:
want_item = False
for change in item['changes']:
if self.wantChange(change):
for ref in item['refs']:
if self.wantRef(ref):
want_item = True
break
if want_item:
status.append(copy.deepcopy(item))
return status
def wantChange(self, change):
return change['id'] == self.desired
def wantRef(self, ref):
return ref['id'] == self.desired
class LogStreamHandler(WebSocket):
@ -1213,7 +1213,7 @@ class ZuulWebAPI(object):
@cherrypy.tools.check_tenant_auth()
def status_change(self, tenant_name, tenant, auth, change):
payload = self._getStatus(tenant)[0]
result_filter = ChangeFilter(change)
result_filter = RefFilter(change)
return result_filter.filterPayload(payload)
@cherrypy.expose