From 6c1c91f8ba6305f7c742133ca99bc0253ea6774f Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Sat, 10 Dec 2022 15:20:32 -0800 Subject: [PATCH] Improve support for web enqueue/dequeue This change: * Returns the build/buildset oldrev through the REST API (this field was missing). * Updates the web UI so that when enqueuing or dequeueing a ref it will send exactly the oldrev/newrev values it received, including None/null. * No longer translate None to 40*'0' when creating internal management events. In concert, these changes allow a user to re-enqueue exactly as originally enqueued buildsets for branch tips (periodic pipeline) as well as ref updates (tag/post pipelines). Additionally, the re-enqueue method in the web UI is updated to support re-enqueing tag and branch heads (it only worked on change and ref-updates before). Finally, the buildset page is updated to show the old and new revs if they are non-null. Change-Id: I9886cd44f8b4bae6f4a5ce3644f0598a73ecfe0a --- web/src/containers/build/Buildset.jsx | 44 ++++++++++++++++++--------- web/src/containers/status/Change.jsx | 24 +++++---------- zuul/model.py | 4 +-- zuul/web/__init__.py | 2 ++ 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/web/src/containers/build/Buildset.jsx b/web/src/containers/build/Buildset.jsx index 2ca70549dc..0dd78eaf96 100644 --- a/web/src/containers/build/Buildset.jsx +++ b/web/src/containers/build/Buildset.jsx @@ -179,9 +179,8 @@ function Buildset({ buildset, timezone, tenant, user }) { function enqueueConfirm() { setShowEnqueueModal(false) if (buildset.change === null) { - const oldrev = '0000000000000000000000000000000000000000' - const newrev = buildset.newrev ? buildset.newrev : '0000000000000000000000000000000000000000' - enqueue_ref(tenant.apiPrefix, buildset.project, buildset.pipeline, buildset.ref, oldrev, newrev) + enqueue_ref(tenant.apiPrefix, buildset.project, buildset.pipeline, + buildset.ref, buildset.oldrev, buildset.newrev) .then(() => { dispatch(addNotification( { @@ -234,6 +233,32 @@ function Buildset({ buildset, timezone, tenant, user }) { ) } + function renderRefInfo(buildset) { + const refinfo = buildset.branch ? ( + <> + Branch {buildset.branch} + + ) : ( + <> + Ref {buildset.ref} + + ) + const oldrev = buildset.oldrev ? ( + <>
Old {buildset.oldrev} + ) : ( <> ) + const newrev = buildset.newrev ? ( + <>
New {buildset.newrev} + ) : ( <> ) + + return ( + <> + {refinfo} + {oldrev} + {newrev} + + ) + } + return ( <> @@ -275,18 +300,7 @@ function Buildset({ buildset, timezone, tenant, user }) { <IconProperty WrapElement={ListItem} icon={<CodeBranchIcon />} - value={ - buildset.branch ? ( - <> - <strong>Branch </strong> {buildset.branch} - </> - ) : ( - <> - <strong>Ref </strong> {buildset.ref} - </> - ) - } - /> + value={renderRefInfo(buildset)}/> <IconProperty WrapElement={ListItem} icon={<StreamIcon />} diff --git a/web/src/containers/status/Change.jsx b/web/src/containers/status/Change.jsx index ac0a4e6e84..5105718b8c 100644 --- a/web/src/containers/status/Change.jsx +++ b/web/src/containers/status/Change.jsx @@ -64,16 +64,7 @@ class Change extends React.Component { let changeRef = change.ref this.setState(() => ({ showDequeueModal: false })) // post-merge - if (/^[0-9a-f]{40}$/.test(changeId)) { - dequeue_ref(tenant.apiPrefix, projectName, pipeline.name, changeRef) - .then(() => { - this.props.dispatch(fetchStatusIfNeeded(tenant)) - }) - .catch(error => { - this.props.dispatch(addDequeueError(error)) - }) - // pre-merge, ie we have a change id - } else if (changeId !== 'N/A') { + if (changeId !== 'N/A') { dequeue(tenant.apiPrefix, projectName, pipeline.name, changeId) .then(() => { this.props.dispatch(fetchStatusIfNeeded(tenant)) @@ -82,12 +73,13 @@ class Change extends React.Component { this.props.dispatch(addDequeueError(error)) }) } else { - this.props.dispatch(addNotification({ - url: null, - status: 'Invalid change ' + changeRef + ' on project ' + projectName, - text: '', - type: 'error', - })) + dequeue_ref(tenant.apiPrefix, projectName, pipeline.name, changeRef) + .then(() => { + this.props.dispatch(fetchStatusIfNeeded(tenant)) + }) + .catch(error => { + this.props.dispatch(addDequeueError(error)) + }) } } diff --git a/zuul/model.py b/zuul/model.py index c2da4f65cf..53a2666eec 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -6450,8 +6450,8 @@ class ChangeManagementEvent(ManagementEvent): else: self.change_number, self.patch_number = (None, None) self.ref = ref - self.oldrev = oldrev or '0000000000000000000000000000000000000000' - self.newrev = newrev or '0000000000000000000000000000000000000000' + self.oldrev = oldrev + self.newrev = newrev self.timestamp = time.time() span = trace.get_current_span() self.span_context = tracing.getSpanContext(span) diff --git a/zuul/web/__init__.py b/zuul/web/__init__.py index de8e91c2c7..626defe923 100755 --- a/zuul/web/__init__.py +++ b/zuul/web/__init__.py @@ -1391,6 +1391,7 @@ class ZuulWebAPI(object): 'change': buildset.change, 'patchset': buildset.patchset, 'ref': buildset.ref, + 'oldrev': buildset.oldrev, 'newrev': buildset.newrev, 'ref_url': buildset.ref_url, 'event_id': buildset.event_id, @@ -1487,6 +1488,7 @@ class ZuulWebAPI(object): 'change': buildset.change, 'patchset': buildset.patchset, 'ref': buildset.ref, + 'oldrev': buildset.oldrev, 'newrev': buildset.newrev, 'ref_url': buildset.ref_url, 'event_id': buildset.event_id,