Merge "Add basePatchNum to SHOW_CHANGE plugin event" into stable-3.8
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 386a166..46c759b 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 {
ChangeInfo,
LabelNameToValueMap,
+ PARENT,
ReviewInput,
RevisionInfo,
} from '../../../types/common';
@@ -98,20 +99,22 @@
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 a10beab..8e3a87d 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 @@
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 6d111aa..c7111f6 100644
--- a/polygerrit-ui/app/models/change/change-model.ts
+++ b/polygerrit-ui/app/models/change/change-model.ts
@@ -407,21 +407,24 @@
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 e5d2e36..dc7d9c3 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 @@
});
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 @@
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);
});