diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html index cbf75cb41c..d751cff621 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html @@ -122,6 +122,7 @@ limitations under the License. commit-num="[[commitNum]]" on-confirm="_handleCherrypickConfirm" on-cancel="_handleConfirmDialogCancel" + project="[[change.project]]" hidden> - + + + diff --git a/polygerrit-ui/app/elements/change/gr-confirm-cherrypick-dialog/gr-confirm-cherrypick-dialog.js b/polygerrit-ui/app/elements/change/gr-confirm-cherrypick-dialog/gr-confirm-cherrypick-dialog.js index 48a3f76532..2ccb32781d 100644 --- a/polygerrit-ui/app/elements/change/gr-confirm-cherrypick-dialog/gr-confirm-cherrypick-dialog.js +++ b/polygerrit-ui/app/elements/change/gr-confirm-cherrypick-dialog/gr-confirm-cherrypick-dialog.js @@ -14,6 +14,8 @@ (function() { 'use strict'; + const SUGGESTIONS_LIMIT = 15; + Polymer({ is: 'gr-confirm-cherrypick-dialog', @@ -35,6 +37,13 @@ commitMessage: String, commitNum: String, message: String, + project: String, + _query: { + type: Function, + value() { + return this._getProjectBranchesSuggestions.bind(this); + }, + }, }, observers: [ @@ -59,5 +68,28 @@ e.preventDefault(); this.fire('cancel', null, {bubbles: false}); }, + + _getProjectBranchesSuggestions(input) { + if (input.startsWith('refs/heads/')) { + input = input.substring('refs/heads/'.length); + } + return this.$.restAPI.getProjectBranches( + input, this.project, SUGGESTIONS_LIMIT).then(response => { + const branches = []; + let branch; + for (const key in response) { + if (!response.hasOwnProperty(key)) { continue; } + if (response[key].ref.startsWith('refs/heads/')) { + branch = response[key].ref.substring('refs/heads/'.length); + } else { + branch = response[key].ref; + } + branches.push({ + name: branch, + }); + } + return branches; + }); + }, }); })(); diff --git a/polygerrit-ui/app/elements/change/gr-confirm-cherrypick-dialog/gr-confirm-cherrypick-dialog_test.html b/polygerrit-ui/app/elements/change/gr-confirm-cherrypick-dialog/gr-confirm-cherrypick-dialog_test.html index 107fb231b0..577a66f937 100644 --- a/polygerrit-ui/app/elements/change/gr-confirm-cherrypick-dialog/gr-confirm-cherrypick-dialog_test.html +++ b/polygerrit-ui/app/elements/change/gr-confirm-cherrypick-dialog/gr-confirm-cherrypick-dialog_test.html @@ -36,7 +36,23 @@ limitations under the License. let element; setup(() => { + stub('gr-rest-api-interface', { + getProjectBranches(input) { + if (input.startsWith('test')) { + return Promise.resolve([ + { + ref: 'refs/heads/test-branch', + revision: '67ebf73496383c6777035e374d2d664009e2aa5c', + can_delete: true, + }, + ]); + } else { + return Promise.resolve({}); + } + }, + }); element = fixture('basic'); + element.project = 'test-project'; }); test('with merged change', () => { @@ -69,5 +85,20 @@ limitations under the License. flushAsynchronousOperations(); assert.equal(element.message, myNewMessage); }); + + test('_getProjectBranchesSuggestions empty', done => { + element._getProjectBranchesSuggestions('nonexistent').then(branches => { + assert.equal(branches.length, 0); + done(); + }); + }); + + test('_getProjectBranchesSuggestions non-empty', done => { + element._getProjectBranchesSuggestions('test-branch').then(branches => { + assert.equal(branches.length, 1); + assert.equal(branches[0].name, 'test-branch'); + done(); + }); + }); });