Refactor gr-rest-api-interface to use rest-client-behavior
Significant unnecessary code duplication existed between the two files, most importantly an enum that existed and was mirrored in both places. This change removes all duplicate code from the interface, preferring the publicly accessible nature of the behavior, and changes private function calls within the interface accordingly. Change-Id: Ifbe10e445c03f13044b8ae07e0d3cd24cfb3284e
This commit is contained in:
@@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
|
|
||||||
<link rel="import" href="../../../behaviors/gr-path-list-behavior/gr-path-list-behavior.html">
|
<link rel="import" href="../../../behaviors/gr-path-list-behavior/gr-path-list-behavior.html">
|
||||||
|
<link rel="import" href="../../../behaviors/rest-client-behavior/rest-client-behavior.html">
|
||||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||||
<script src="../../../bower_components/es6-promise/dist/es6-promise.min.js"></script>
|
<script src="../../../bower_components/es6-promise/dist/es6-promise.min.js"></script>
|
||||||
<script src="../../../bower_components/fetch/fetch.js"></script>
|
<script src="../../../bower_components/fetch/fetch.js"></script>
|
||||||
|
|||||||
@@ -26,66 +26,12 @@
|
|||||||
SEND_DIFF_DRAFT: 'sendDiffDraft',
|
SEND_DIFF_DRAFT: 'sendDiffDraft',
|
||||||
};
|
};
|
||||||
|
|
||||||
// Must be kept in sync with the ListChangesOption enum and protobuf.
|
|
||||||
const ListChangesOption = {
|
|
||||||
LABELS: 0,
|
|
||||||
DETAILED_LABELS: 8,
|
|
||||||
|
|
||||||
// Return information on the current patch set of the change.
|
|
||||||
CURRENT_REVISION: 1,
|
|
||||||
ALL_REVISIONS: 2,
|
|
||||||
|
|
||||||
// If revisions are included, parse the commit object.
|
|
||||||
CURRENT_COMMIT: 3,
|
|
||||||
ALL_COMMITS: 4,
|
|
||||||
|
|
||||||
// If a patch set is included, include the files of the patch set.
|
|
||||||
CURRENT_FILES: 5,
|
|
||||||
ALL_FILES: 6,
|
|
||||||
|
|
||||||
// If accounts are included, include detailed account info.
|
|
||||||
DETAILED_ACCOUNTS: 7,
|
|
||||||
|
|
||||||
// Include messages associated with the change.
|
|
||||||
MESSAGES: 9,
|
|
||||||
|
|
||||||
// Include allowed actions client could perform.
|
|
||||||
CURRENT_ACTIONS: 10,
|
|
||||||
|
|
||||||
// Set the reviewed boolean for the caller.
|
|
||||||
REVIEWED: 11,
|
|
||||||
|
|
||||||
// Include download commands for the caller.
|
|
||||||
DOWNLOAD_COMMANDS: 13,
|
|
||||||
|
|
||||||
// Include patch set weblinks.
|
|
||||||
WEB_LINKS: 14,
|
|
||||||
|
|
||||||
// Include consistency check results.
|
|
||||||
CHECK: 15,
|
|
||||||
|
|
||||||
// Include allowed change actions client could perform.
|
|
||||||
CHANGE_ACTIONS: 16,
|
|
||||||
|
|
||||||
// Include a copy of commit messages including review footers.
|
|
||||||
COMMIT_FOOTERS: 17,
|
|
||||||
|
|
||||||
// Include push certificate information along with any patch sets.
|
|
||||||
PUSH_CERTIFICATES: 18,
|
|
||||||
|
|
||||||
// Include change's reviewer updates.
|
|
||||||
REVIEWER_UPDATES: 19,
|
|
||||||
|
|
||||||
// Set the submittable boolean.
|
|
||||||
SUBMITTABLE: 20,
|
|
||||||
};
|
|
||||||
|
|
||||||
Polymer({
|
Polymer({
|
||||||
is: 'gr-rest-api-interface',
|
is: 'gr-rest-api-interface',
|
||||||
|
|
||||||
behaviors: [
|
behaviors: [
|
||||||
Gerrit.BaseUrlBehavior,
|
|
||||||
Gerrit.PathListBehavior,
|
Gerrit.PathListBehavior,
|
||||||
|
Gerrit.RESTClientBehavior,
|
||||||
],
|
],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -423,9 +369,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
getChanges(changesPerPage, opt_query, opt_offset) {
|
getChanges(changesPerPage, opt_query, opt_offset) {
|
||||||
const options = this._listChangesOptionsToHex(
|
const options = this.listChangesOptionsToHex(
|
||||||
ListChangesOption.LABELS,
|
this.ListChangesOption.LABELS,
|
||||||
ListChangesOption.DETAILED_ACCOUNTS
|
this.ListChangesOption.DETAILED_ACCOUNTS
|
||||||
);
|
);
|
||||||
// Issue 4524: respect legacy token with max sortkey.
|
// Issue 4524: respect legacy token with max sortkey.
|
||||||
if (opt_offset === 'n,z') {
|
if (opt_offset === 'n,z') {
|
||||||
@@ -443,10 +389,10 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
getDashboardChanges() {
|
getDashboardChanges() {
|
||||||
const options = this._listChangesOptionsToHex(
|
const options = this.listChangesOptionsToHex(
|
||||||
ListChangesOption.LABELS,
|
this.ListChangesOption.LABELS,
|
||||||
ListChangesOption.DETAILED_ACCOUNTS,
|
this.ListChangesOption.DETAILED_ACCOUNTS,
|
||||||
ListChangesOption.REVIEWED
|
this.ListChangesOption.REVIEWED
|
||||||
);
|
);
|
||||||
const params = {
|
const params = {
|
||||||
O: options,
|
O: options,
|
||||||
@@ -461,18 +407,18 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
getChangeActionURL(changeNum, opt_patchNum, endpoint) {
|
getChangeActionURL(changeNum, opt_patchNum, endpoint) {
|
||||||
return this._changeBaseURL(changeNum, opt_patchNum) + endpoint;
|
return this.changeBaseURL(changeNum, opt_patchNum) + endpoint;
|
||||||
},
|
},
|
||||||
|
|
||||||
getChangeDetail(changeNum, opt_errFn, opt_cancelCondition) {
|
getChangeDetail(changeNum, opt_errFn, opt_cancelCondition) {
|
||||||
const options = this._listChangesOptionsToHex(
|
const options = this.listChangesOptionsToHex(
|
||||||
ListChangesOption.ALL_REVISIONS,
|
this.ListChangesOption.ALL_REVISIONS,
|
||||||
ListChangesOption.CHANGE_ACTIONS,
|
this.ListChangesOption.CHANGE_ACTIONS,
|
||||||
ListChangesOption.CURRENT_ACTIONS,
|
this.ListChangesOption.CURRENT_ACTIONS,
|
||||||
ListChangesOption.CURRENT_COMMIT,
|
this.ListChangesOption.CURRENT_COMMIT,
|
||||||
ListChangesOption.DOWNLOAD_COMMANDS,
|
this.ListChangesOption.DOWNLOAD_COMMANDS,
|
||||||
ListChangesOption.SUBMITTABLE,
|
this.ListChangesOption.SUBMITTABLE,
|
||||||
ListChangesOption.WEB_LINKS
|
this.ListChangesOption.WEB_LINKS
|
||||||
);
|
);
|
||||||
return this._getChangeDetail(
|
return this._getChangeDetail(
|
||||||
changeNum, options, opt_errFn, opt_cancelCondition)
|
changeNum, options, opt_errFn, opt_cancelCondition)
|
||||||
@@ -480,8 +426,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
getDiffChangeDetail(changeNum, opt_errFn, opt_cancelCondition) {
|
getDiffChangeDetail(changeNum, opt_errFn, opt_cancelCondition) {
|
||||||
const options = this._listChangesOptionsToHex(
|
const options = this.listChangesOptionsToHex(
|
||||||
ListChangesOption.ALL_REVISIONS
|
this.ListChangesOption.ALL_REVISIONS
|
||||||
);
|
);
|
||||||
return this._getChangeDetail(changeNum, options, opt_errFn,
|
return this._getChangeDetail(changeNum, options, opt_errFn,
|
||||||
opt_cancelCondition);
|
opt_cancelCondition);
|
||||||
@@ -620,9 +566,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
getChangeConflicts(changeNum) {
|
getChangeConflicts(changeNum) {
|
||||||
const options = this._listChangesOptionsToHex(
|
const options = this.listChangesOptionsToHex(
|
||||||
ListChangesOption.CURRENT_REVISION,
|
this.ListChangesOption.CURRENT_REVISION,
|
||||||
ListChangesOption.CURRENT_COMMIT
|
this.ListChangesOption.CURRENT_COMMIT
|
||||||
);
|
);
|
||||||
const params = {
|
const params = {
|
||||||
O: options,
|
O: options,
|
||||||
@@ -632,9 +578,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
getChangeCherryPicks(project, changeID, changeNum) {
|
getChangeCherryPicks(project, changeID, changeNum) {
|
||||||
const options = this._listChangesOptionsToHex(
|
const options = this.listChangesOptionsToHex(
|
||||||
ListChangesOption.CURRENT_REVISION,
|
this.ListChangesOption.CURRENT_REVISION,
|
||||||
ListChangesOption.CURRENT_COMMIT
|
this.ListChangesOption.CURRENT_COMMIT
|
||||||
);
|
);
|
||||||
const query = [
|
const query = [
|
||||||
'project:' + project,
|
'project:' + project,
|
||||||
@@ -650,11 +596,11 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
getChangesWithSameTopic(topic) {
|
getChangesWithSameTopic(topic) {
|
||||||
const options = this._listChangesOptionsToHex(
|
const options = this.listChangesOptionsToHex(
|
||||||
ListChangesOption.LABELS,
|
this.ListChangesOption.LABELS,
|
||||||
ListChangesOption.CURRENT_REVISION,
|
this.ListChangesOption.CURRENT_REVISION,
|
||||||
ListChangesOption.CURRENT_COMMIT,
|
this.ListChangesOption.CURRENT_COMMIT,
|
||||||
ListChangesOption.DETAILED_LABELS
|
this.ListChangesOption.DETAILED_LABELS
|
||||||
);
|
);
|
||||||
const params = {
|
const params = {
|
||||||
O: options,
|
O: options,
|
||||||
@@ -801,7 +747,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_getDiffFetchURL(changeNum, patchNum, path) {
|
_getDiffFetchURL(changeNum, patchNum, path) {
|
||||||
return this._changeBaseURL(changeNum, patchNum) + '/files/' +
|
return this.changeBaseURL(changeNum, patchNum) + '/files/' +
|
||||||
encodeURIComponent(path) + '/diff';
|
encodeURIComponent(path) + '/diff';
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -899,7 +845,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_getDiffCommentsFetchURL(changeNum, endpoint, opt_patchNum) {
|
_getDiffCommentsFetchURL(changeNum, endpoint, opt_patchNum) {
|
||||||
return this._changeBaseURL(changeNum, opt_patchNum) + endpoint;
|
return this.changeBaseURL(changeNum, opt_patchNum) + endpoint;
|
||||||
},
|
},
|
||||||
|
|
||||||
saveDiffDraft(changeNum, patchNum, draft) {
|
saveDiffDraft(changeNum, patchNum, draft) {
|
||||||
@@ -935,24 +881,6 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_changeBaseURL(changeNum, opt_patchNum) {
|
|
||||||
let v = '/changes/' + changeNum;
|
|
||||||
if (opt_patchNum) {
|
|
||||||
v += '/revisions/' + opt_patchNum;
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Derived from
|
|
||||||
// gerrit-extension-api/src/main/j/c/g/gerrit/extensions/client/ListChangesOption.java
|
|
||||||
_listChangesOptionsToHex(...args) {
|
|
||||||
let v = 0;
|
|
||||||
for (let i = 0; i < args.length; i++) {
|
|
||||||
v |= 1 << args[i];
|
|
||||||
}
|
|
||||||
return v.toString(16);
|
|
||||||
},
|
|
||||||
|
|
||||||
_getCookie(name) {
|
_getCookie(name) {
|
||||||
const key = name + '=';
|
const key = name + '=';
|
||||||
const cookies = document.cookie.split(';');
|
const cookies = document.cookie.split(';');
|
||||||
@@ -1134,7 +1062,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
deleteComment(changeNum, patchNum, commentID, reason) {
|
deleteComment(changeNum, patchNum, commentID, reason) {
|
||||||
const url = this._changeBaseURL(changeNum, patchNum) +
|
const url = this.changeBaseURL(changeNum, patchNum) +
|
||||||
'/comments/' + commentID + '/delete';
|
'/comments/' + commentID + '/delete';
|
||||||
return this.send('POST', url, {reason}).then(response =>
|
return this.send('POST', url, {reason}).then(response =>
|
||||||
this.getResponseObject(response));
|
this.getResponseObject(response));
|
||||||
|
|||||||
Reference in New Issue
Block a user