Add params to change-view-integration plugin endpoint Take 2, fixed the broken test. Change-Id: Ibadbdc4cbbb5ec01da1568f2f8cf6db6191e3b0a
diff --git a/Documentation/pg-plugin-endpoints.txt b/Documentation/pg-plugin-endpoints.txt index 8ae25fd..7c960dd 100644 --- a/Documentation/pg-plugin-endpoints.txt +++ b/Documentation/pg-plugin-endpoints.txt
@@ -40,6 +40,16 @@ view page, and it may take full page's width. Primary purpose is to enable plugins to display custom CI related information (build status, etc). +* `change` ++ +current change displayed, an instance of +link:rest-api-changes.html#change-info[ChangeInfo] + +* `revision` ++ +current revision displayed, an instance of +link:rest-api-changes.html#revision-info[RevisionInfo] + === change-metadata-item Extension point is located on the bottom of the change view left panel, under `Label Status` and `Links` sections. It's width is equal to the left panel's and @@ -52,3 +62,8 @@ + current change displayed, an instance of link:rest-api-changes.html#change-info[ChangeInfo] + +* `revision` ++ +current revision displayed, an instance of +link:rest-api-changes.html#revision-info[RevisionInfo]
diff --git a/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.html b/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.html index 936b284..caf2fa3 100644 --- a/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.html +++ b/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.html
@@ -19,6 +19,7 @@ <link rel="import" href="../../../styles/shared-styles.html"> <link rel="import" href="../../core/gr-navigation/gr-navigation.html"> <link rel="import" href="../../plugins/gr-endpoint-decorator/gr-endpoint-decorator.html"> +<link rel="import" href="../../plugins/gr-endpoint-param/gr-endpoint-param.html"> <link rel="import" href="../../plugins/gr-external-style/gr-external-style.html"> <link rel="import" href="../../shared/gr-account-chip/gr-account-chip.html"> <link rel="import" href="../../shared/gr-account-link/gr-account-link.html"> @@ -330,6 +331,7 @@ </section> <gr-endpoint-decorator name="change-metadata-item"> <gr-endpoint-param name="change" value="[[change]]"></gr-endpoint-param> + <gr-endpoint-param name="revision" value="[[currentRevision]]"></gr-endpoint-param> </gr-endpoint-decorator> </gr-external-style> <gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
diff --git a/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.js b/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.js index db6c44c..00b4c2a 100644 --- a/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.js +++ b/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.js
@@ -37,6 +37,8 @@ properties: { /** @type {?} */ change: Object, + /** @type {?} */ + currentRevision: Object, commitInfo: Object, mutable: Boolean, /**
diff --git a/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata_test.html b/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata_test.html index 522d34e..0b88f22 100644 --- a/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata_test.html +++ b/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata_test.html
@@ -38,6 +38,9 @@ setup(() => { sandbox = sinon.sandbox.create(); + stub('gr-endpoint-decorator', { + _import: sandbox.stub().returns(Promise.resolve()), + }); stub('gr-rest-api-interface', { getConfig() { return Promise.resolve({}); }, getLoggedIn() { return Promise.resolve(false); }, @@ -615,5 +618,29 @@ }); }); }); + + suite('plugin endpoints', () => { + test('endpoint params', done => { + element.change = {labels: {}}; + element.currentRevision = {}; + let hookEl; + let plugin; + Gerrit.install( + p => { + plugin = p; + plugin.hook('change-metadata-item').getLastAttached().then( + el => hookEl = el); + }, + '0.1', + 'http://some/plugins/url.html'); + Gerrit._setPluginsCount(0); + flush(() => { + assert.strictEqual(hookEl.plugin, plugin); + assert.strictEqual(hookEl.change, element.change); + assert.strictEqual(hookEl.revision, element.currentRevision); + done(); + }); + }); + }); }); </script>
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html index 9e58204..56548de 100644 --- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html +++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html
@@ -15,7 +15,6 @@ --> <link rel="import" href="../../../bower_components/polymer/polymer.html"> - <link rel="import" href="../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html"> <link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html"> <link rel="import" href="../../../behaviors/rest-client-behavior/rest-client-behavior.html"> @@ -25,6 +24,7 @@ <link rel="import" href="../../diff/gr-diff-preferences/gr-diff-preferences.html"> <link rel="import" href="../../edit/gr-edit-constants.html"> <link rel="import" href="../../plugins/gr-endpoint-decorator/gr-endpoint-decorator.html"> +<link rel="import" href="../../plugins/gr-endpoint-param/gr-endpoint-param.html"> <link rel="import" href="../../shared/gr-account-link/gr-account-link.html"> <link rel="import" href="../../shared/gr-button/gr-button.html"> <link rel="import" href="../../shared/gr-change-star/gr-change-star.html"> @@ -357,6 +357,7 @@ <div class="changeInfo-column changeMetadata hideOnMobileOverlay"> <gr-change-metadata change="{{_change}}" + revision="[[_currentRevision]]" commit-info="[[_commitInfo]]" server-config="[[_serverConfig]]" mutable="[[_loggedIn]]" @@ -486,6 +487,10 @@ on-reload-drafts="_reloadDraftsWithCallback"></gr-file-list> </section> <gr-endpoint-decorator name="change-view-integration"> + <gr-endpoint-param name="change" value="[[_change]]"> + </gr-endpoint-param> + <gr-endpoint-param name="revision" value="[[_currentRevision]]"> + </gr-endpoint-param> </gr-endpoint-decorator> <gr-messages-list id="messageList" class="hideOnMobileOverlay"
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js index cd56752..145c1f8 100644 --- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js +++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js
@@ -166,6 +166,7 @@ type: Boolean, value: true, }, + _currentRevision: Object, _currentRevisionActions: Object, _allPatchSets: { type: Array, @@ -983,6 +984,7 @@ parseInt(lineHeight.slice(0, lineHeight.length - 2), 10); this._change = change; + this._currentRevision = currentRevision; if (!this._patchRange || !this._patchRange.patchNum || this.patchNumEquals(this._patchRange.patchNum, currentRevision._number)) {
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html index 4a4cd5c..d3e1d72 100644 --- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html +++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html
@@ -49,6 +49,11 @@ setup(() => { sandbox = sinon.sandbox.create(); + stub('gr-endpoint-decorator', { + _import: sandbox.stub().returns(Promise.resolve()), + }); + // Since _endpoints are global, must reset state. + Gerrit._endpoints = new GrPluginEndpoints(); navigateToChangeStub = sandbox.stub(Gerrit.Nav, 'navigateToChange'); stub('gr-rest-api-interface', { getConfig() { return Promise.resolve({test: 'config'}); }, @@ -57,6 +62,7 @@ }); element = fixture('basic'); sandbox.stub(element.$.actions, 'reload').returns(Promise.resolve()); + Gerrit._setPluginsCount(0); }); teardown(done => { @@ -1373,5 +1379,28 @@ assert.equal(Gerrit.Nav.getEditUrlForDiff.lastCall.args[1], 'foo'); assert.isTrue(Gerrit.Nav.navigateToRelativeUrl.called); }); + + suite('plugin endpoints', () => { + test('endpoint params', done => { + element._change = {labels: {}}; + element._currentRevision = {}; + let hookEl; + let plugin; + Gerrit.install( + p => { + plugin = p; + plugin.hook('change-view-integration').getLastAttached().then( + el => hookEl = el); + }, + '0.1', + 'http://some/plugins/url.html'); + flush(() => { + assert.strictEqual(hookEl.plugin, plugin); + assert.strictEqual(hookEl.change, element._change); + assert.strictEqual(hookEl.revision, element._currentRevision); + done(); + }); + }); + }); }); </script>