diff options
author | Frank Borden <frankborden@google.com> | 2023-05-09 17:14:04 +0200 |
---|---|---|
committer | Paladox none <thomasmulhall410@yahoo.com> | 2023-05-10 15:58:42 +0000 |
commit | 7552394d533f1c002feee5597fa576b78aa6b18d (patch) | |
tree | d25c41b64428a8019def3f74ed702faa79635640 | |
parent | b1a42ad3feb0c23d15f1550bbb4e2b96e0c57136 (diff) |
Add basePatchNum to SHOW_CHANGE plugin event
This also means SHOW_CHANGE will trigger when LHS patchset changes. If
LHS is just the PARENT, plugin callback will receive 'parent' marker
string. If LHS is an integer patchset, plugin callback will receive
RevisionInfo object.
Release-Notes: SHOW_CHANGE web plugin event receives both patchset sides
Change-Id: I032b70a591c78ecaf37b7bcada6957bd9dfa380e
(cherry picked from commit 79b4a252d5fff127d09a7d00897d4406bbc35199)
4 files changed, 16 insertions, 6 deletions
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface-element.ts b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface-element.ts index 386a1660cc..46c759b11d 100644 --- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface-element.ts +++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface-element.ts @@ -7,6 +7,7 @@ import {hasOwnProperty} from '../../../utils/common-util'; import { ChangeInfo, LabelNameToValueMap, + PARENT, ReviewInput, RevisionInfo, } from '../../../types/common'; @@ -98,20 +99,22 @@ export class GrJsApiInterface implements JsApiService, Finalizable { return detail.info && detail.info.mergeable; }, }; - const patchNum = detail.patchNum; - const info = detail.info; + const {patchNum, info, basePatchNum} = detail; let revision; + let baseRevision; for (const rev of Object.values(change.revisions || {})) { if (rev._number === patchNum) { revision = rev; - break; + } + if (rev._number === basePatchNum) { + baseRevision = rev; } } for (const cb of this._getEventCallbacks(EventType.SHOW_CHANGE)) { try { - cb(change, revision, info); + cb(change, revision, info, baseRevision ?? PARENT); } catch (err: unknown) { this.reporting.error( 'GrJsApiInterface', diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts index a10beab9e4..8e3a87d925 100644 --- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts +++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-types.ts @@ -6,6 +6,7 @@ import { ActionInfo, ChangeInfo, + BasePatchSetNum, PatchSetNum, ReviewInput, RevisionInfo, @@ -17,6 +18,7 @@ import {MenuLink} from '../../../api/admin'; export interface ShowChangeDetail { change?: ParsedChangeInfo; + basePatchNum?: BasePatchSetNum; patchNum?: PatchSetNum; info: {mergeable: boolean | null}; } diff --git a/polygerrit-ui/app/models/change/change-model.ts b/polygerrit-ui/app/models/change/change-model.ts index 6d111aafc1..c7111f6781 100644 --- a/polygerrit-ui/app/models/change/change-model.ts +++ b/polygerrit-ui/app/models/change/change-model.ts @@ -407,21 +407,24 @@ export class ChangeModel extends Model<ChangeState> { return combineLatest([ this.viewModel.childView$, this.change$, + this.basePatchNum$, this.patchNum$, this.mergeable$, ]) .pipe( filter( - ([childView, change, patchNum, mergeable]) => + ([childView, change, basePatchNum, patchNum, mergeable]) => childView === ChangeChildView.OVERVIEW && !!change && + !!basePatchNum && !!patchNum && mergeable !== undefined ) ) - .subscribe(([_, change, patchNum, mergeable]) => { + .subscribe(([_, change, basePatchNum, patchNum, mergeable]) => { this.pluginLoader.jsApiService.handleShowChange({ change, + basePatchNum, patchNum, // `?? null` is for the TypeScript compiler only. We have a // `mergeable !== undefined` filter above, so this cannot happen. diff --git a/polygerrit-ui/app/models/change/change-model_test.ts b/polygerrit-ui/app/models/change/change-model_test.ts index e5d2e36be9..dc7d9c3c41 100644 --- a/polygerrit-ui/app/models/change/change-model_test.ts +++ b/polygerrit-ui/app/models/change/change-model_test.ts @@ -222,6 +222,7 @@ suite('change model tests', () => { }); test('fireShowChange', async () => { + await waitForLoadingStatus(LoadingStatus.NOT_LOADED); const pluginLoader = testResolver(pluginLoaderToken); const jsApiService = pluginLoader.jsApiService; const showChangeStub = sinon.stub(jsApiService, 'handleShowChange'); @@ -239,6 +240,7 @@ suite('change model tests', () => { const detail: ShowChangeDetail = showChangeStub.lastCall.firstArg; assert.equal(detail.change?._number, createParsedChange()._number); assert.equal(detail.patchNum, 1 as PatchSetNumber); + assert.equal(detail.basePatchNum, PARENT); assert.equal(detail.info.mergeable, true); }); |