Merge "Remove unused opt_ctx param from API interface"

This commit is contained in:
Wyatt Allen 2018-05-18 23:30:07 +00:00 committed by Gerrit Code Review
commit c1399cf4c7
3 changed files with 83 additions and 123 deletions

View File

@ -209,8 +209,7 @@
_handleDeleteItemConfirm() {
this.$.overlay.close();
if (this.detailType === DETAIL_TYPES.BRANCHES) {
return this.$.restAPI.deleteRepoBranches(this._repo,
this._refName)
return this.$.restAPI.deleteRepoBranches(this._repo, this._refName)
.then(itemDeleted => {
if (itemDeleted.status === 204) {
this._getItems(
@ -219,8 +218,7 @@
}
});
} else if (this.detailType === DETAIL_TYPES.TAGS) {
return this.$.restAPI.deleteRepoTags(this._repo,
this._refName)
return this.$.restAPI.deleteRepoTags(this._repo, this._refName)
.then(itemDeleted => {
if (itemDeleted.status === 204) {
this._getItems(

View File

@ -1188,7 +1188,7 @@
}
const patchNum = revisionAction ? this.latestPatchNum : null;
return this.$.restAPI.getChangeURLAndSend(this.changeNum, method,
patchNum, actionEndpoint, payload, handleError, this)
patchNum, actionEndpoint, payload, handleError)
.then(response => {
cleanupFn.call(this);
return response;

View File

@ -293,47 +293,42 @@
});
},
saveRepoConfig(repo, config, opt_errFn, opt_ctx) {
saveRepoConfig(repo, config, opt_errFn) {
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
// supports it.
const encodeName = encodeURIComponent(repo);
return this.send('PUT', `/projects/${encodeName}/config`, config,
opt_errFn, opt_ctx);
opt_errFn);
},
runRepoGC(repo, opt_errFn, opt_ctx) {
runRepoGC(repo, opt_errFn) {
if (!repo) { return ''; }
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
// supports it.
const encodeName = encodeURIComponent(repo);
return this.send('POST', `/projects/${encodeName}/gc`, '',
opt_errFn, opt_ctx);
return this.send('POST', `/projects/${encodeName}/gc`, '', opt_errFn);
},
/**
* @param {?Object} config
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
createRepo(config, opt_errFn, opt_ctx) {
createRepo(config, opt_errFn) {
if (!config.name) { return ''; }
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
// supports it.
const encodeName = encodeURIComponent(config.name);
return this.send('PUT', `/projects/${encodeName}`, config, opt_errFn,
opt_ctx);
return this.send('PUT', `/projects/${encodeName}`, config, opt_errFn);
},
/**
* @param {?Object} config
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
createGroup(config, opt_errFn, opt_ctx) {
createGroup(config, opt_errFn) {
if (!config.name) { return ''; }
const encodeName = encodeURIComponent(config.name);
return this.send('PUT', `/groups/${encodeName}`, config, opt_errFn,
opt_ctx);
return this.send('PUT', `/groups/${encodeName}`, config, opt_errFn);
},
getGroupConfig(group, opt_errFn) {
@ -347,34 +342,30 @@
* @param {string} repo
* @param {string} ref
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
deleteRepoBranches(repo, ref, opt_errFn, opt_ctx) {
deleteRepoBranches(repo, ref, opt_errFn) {
if (!repo || !ref) { return ''; }
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
// supports it.
const encodeName = encodeURIComponent(repo);
const encodeRef = encodeURIComponent(ref);
return this.send('DELETE',
`/projects/${encodeName}/branches/${encodeRef}`, '',
opt_errFn, opt_ctx);
`/projects/${encodeName}/branches/${encodeRef}`, '', opt_errFn);
},
/**
* @param {string} repo
* @param {string} ref
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
deleteRepoTags(repo, ref, opt_errFn, opt_ctx) {
deleteRepoTags(repo, ref, opt_errFn) {
if (!repo || !ref) { return ''; }
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
// supports it.
const encodeName = encodeURIComponent(repo);
const encodeRef = encodeURIComponent(ref);
return this.send('DELETE',
`/projects/${encodeName}/tags/${encodeRef}`, '',
opt_errFn, opt_ctx);
`/projects/${encodeName}/tags/${encodeRef}`, '', opt_errFn);
},
/**
@ -382,9 +373,8 @@
* @param {string} branch
* @param {string} revision
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
createRepoBranch(name, branch, revision, opt_errFn, opt_ctx) {
createRepoBranch(name, branch, revision, opt_errFn) {
if (!name || !branch || !revision) { return ''; }
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
// supports it.
@ -392,7 +382,7 @@
const encodeBranch = encodeURIComponent(branch);
return this.send('PUT',
`/projects/${encodeName}/branches/${encodeBranch}`,
revision, opt_errFn, opt_ctx);
revision, opt_errFn);
},
/**
@ -400,16 +390,15 @@
* @param {string} tag
* @param {string} revision
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
createRepoTag(name, tag, revision, opt_errFn, opt_ctx) {
createRepoTag(name, tag, revision, opt_errFn) {
if (!name || !tag || !revision) { return ''; }
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
// supports it.
const encodeName = encodeURIComponent(name);
const encodeTag = encodeURIComponent(tag);
return this.send('PUT', `/projects/${encodeName}/tags/${encodeTag}`,
revision, opt_errFn, opt_ctx);
revision, opt_errFn);
},
/**
@ -562,41 +551,37 @@
/**
* @param {?Object} prefs
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
savePreferences(prefs, opt_errFn, opt_ctx) {
savePreferences(prefs, opt_errFn) {
// Note (Issue 5142): normalize the download scheme with lower case before
// saving.
if (prefs.download_scheme) {
prefs.download_scheme = prefs.download_scheme.toLowerCase();
}
return this.send('PUT', '/accounts/self/preferences', prefs, opt_errFn,
opt_ctx);
return this.send('PUT', '/accounts/self/preferences', prefs, opt_errFn);
},
/**
* @param {?Object} prefs
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
saveDiffPreferences(prefs, opt_errFn, opt_ctx) {
saveDiffPreferences(prefs, opt_errFn) {
// Invalidate the cache.
this._cache['/accounts/self/preferences.diff'] = undefined;
return this.send('PUT', '/accounts/self/preferences.diff', prefs,
opt_errFn, opt_ctx);
opt_errFn);
},
/**
* @param {?Object} prefs
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
saveEditPreferences(prefs, opt_errFn, opt_ctx) {
saveEditPreferences(prefs, opt_errFn) {
// Invalidate the cache.
this._cache['/accounts/self/preferences.edit'] = undefined;
return this.send('PUT', '/accounts/self/preferences.edit', prefs,
opt_errFn, opt_ctx);
opt_errFn);
},
getAccount() {
@ -636,46 +621,43 @@
/**
* @param {string} email
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
addAccountEmail(email, opt_errFn, opt_ctx) {
addAccountEmail(email, opt_errFn) {
return this.send('PUT', '/accounts/self/emails/' +
encodeURIComponent(email), null, opt_errFn, opt_ctx);
encodeURIComponent(email), null, opt_errFn);
},
/**
* @param {string} email
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
deleteAccountEmail(email, opt_errFn, opt_ctx) {
deleteAccountEmail(email, opt_errFn) {
return this.send('DELETE', '/accounts/self/emails/' +
encodeURIComponent(email), null, opt_errFn, opt_ctx);
encodeURIComponent(email), null, opt_errFn);
},
/**
* @param {string} email
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
setPreferredAccountEmail(email, opt_errFn, opt_ctx) {
return this.send('PUT', '/accounts/self/emails/' +
encodeURIComponent(email) + '/preferred', null,
opt_errFn, opt_ctx).then(() => {
// If result of getAccountEmails is in cache, update it in the cache
// so we don't have to invalidate it.
const cachedEmails = this._cache['/accounts/self/emails'];
if (cachedEmails) {
const emails = cachedEmails.map(entry => {
if (entry.email === email) {
return {email, preferred: true};
} else {
return {email};
}
});
this._cache['/accounts/self/emails'] = emails;
setPreferredAccountEmail(email, opt_errFn) {
const encodedEmail = encodeURIComponent(email);
const url = `/accounts/self/emails/${encodedEmail}/preferred`;
return this.send('PUT', url, null, opt_errFn).then(() => {
// If result of getAccountEmails is in cache, update it in the cache
// so we don't have to invalidate it.
const cachedEmails = this._cache['/accounts/self/emails'];
if (cachedEmails) {
const emails = cachedEmails.map(entry => {
if (entry.email === email) {
return {email, preferred: true};
} else {
return {email};
}
});
this._cache['/accounts/self/emails'] = emails;
}
});
},
/**
@ -695,35 +677,31 @@
/**
* @param {string} name
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
setAccountName(name, opt_errFn, opt_ctx) {
return this.send('PUT', '/accounts/self/name', {name}, opt_errFn, opt_ctx)
.then(response => this.getResponseObject(response)
.then(newName => this._updateCachedAccount({name: newName})));
setAccountName(name, opt_errFn) {
return this.send('PUT', '/accounts/self/name', {name}, opt_errFn)
.then(response => this.getResponseObject(response))
.then(newName => this._updateCachedAccount({name: newName}));
},
/**
* @param {string} username
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
setAccountUsername(username, opt_errFn, opt_ctx) {
return this.send('PUT', '/accounts/self/username', {username}, opt_errFn,
opt_ctx).then(response => this.getResponseObject(response)
.then(newName => this._updateCachedAccount({username: newName})));
setAccountUsername(username, opt_errFn) {
return this.send('PUT', '/accounts/self/username', {username}, opt_errFn)
.then(response => this.getResponseObject(response))
.then(newName => this._updateCachedAccount({username: newName}));
},
/**
* @param {string} status
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
setAccountStatus(status, opt_errFn, opt_ctx) {
return this.send('PUT', '/accounts/self/status', {status},
opt_errFn, opt_ctx).then(response => this.getResponseObject(response)
.then(newStatus => this._updateCachedAccount(
{status: newStatus})));
setAccountStatus(status, opt_errFn) {
return this.send('PUT', '/accounts/self/status', {status}, opt_errFn)
.then(response => this.getResponseObject(response))
.then(newStatus => this._updateCachedAccount({status: newStatus}));
},
getAccountStatus(userId) {
@ -832,24 +810,20 @@
/**
* @param {string} projects
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
saveWatchedProjects(projects, opt_errFn, opt_ctx) {
return this.send('POST', '/accounts/self/watched.projects', projects,
opt_errFn, opt_ctx)
.then(response => {
return this.getResponseObject(response);
});
saveWatchedProjects(projects, opt_errFn) {
const url = '/accounts/self/watched.projects';
return this.send('POST', url, projects, opt_errFn)
.then(response => this.getResponseObject(response));
},
/**
* @param {string} projects
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
deleteWatchedProjects(projects, opt_errFn, opt_ctx) {
deleteWatchedProjects(projects, opt_errFn) {
return this.send('POST', '/accounts/self/watched.projects:delete',
projects, opt_errFn, opt_ctx);
projects, opt_errFn);
},
/**
@ -1287,15 +1261,13 @@
* @param {string} inputVal
* @param {number} opt_n
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
getSuggestedGroups(inputVal, opt_n, opt_errFn, opt_ctx) {
getSuggestedGroups(inputVal, opt_n, opt_errFn) {
const params = {s: inputVal};
if (opt_n) { params.n = opt_n; }
return this._fetchJSON({
url: '/groups/',
errFn: opt_errFn,
cancelCondition: opt_ctx,
params,
});
},
@ -1304,9 +1276,8 @@
* @param {string} inputVal
* @param {number} opt_n
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
getSuggestedProjects(inputVal, opt_n, opt_errFn, opt_ctx) {
getSuggestedProjects(inputVal, opt_n, opt_errFn) {
const params = {
m: inputVal,
n: MAX_PROJECT_RESULTS,
@ -1316,7 +1287,6 @@
return this._fetchJSON({
url: '/projects/',
errFn: opt_errFn,
cancelCondition: opt_ctx,
params,
});
},
@ -1325,9 +1295,8 @@
* @param {string} inputVal
* @param {number} opt_n
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
getSuggestedAccounts(inputVal, opt_n, opt_errFn, opt_ctx) {
getSuggestedAccounts(inputVal, opt_n, opt_errFn) {
if (!inputVal) {
return Promise.resolve([]);
}
@ -1336,7 +1305,6 @@
return this._fetchJSON({
url: '/accounts/',
errFn: opt_errFn,
cancelCondition: opt_ctx,
params,
});
},
@ -1441,13 +1409,12 @@
* @param {string} path
* @param {boolean} reviewed
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
saveFileReviewed(changeNum, patchNum, path, reviewed, opt_errFn, opt_ctx) {
saveFileReviewed(changeNum, patchNum, path, reviewed, opt_errFn) {
const method = reviewed ? 'PUT' : 'DELETE';
const e = `/files/${encodeURIComponent(path)}/reviewed`;
return this.getChangeURLAndSend(changeNum, method, patchNum, e, null,
opt_errFn, opt_ctx);
const endpoint = `/files/${encodeURIComponent(path)}/reviewed`;
return this.getChangeURLAndSend(changeNum, method, patchNum, endpoint,
null, opt_errFn);
},
/**
@ -1455,15 +1422,14 @@
* @param {number|string} patchNum
* @param {!Object} review
* @param {function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
*/
saveChangeReview(changeNum, patchNum, review, opt_errFn, opt_ctx) {
saveChangeReview(changeNum, patchNum, review, opt_errFn) {
const promises = [
this.awaitPendingDiffDrafts(),
this.getChangeActionURL(changeNum, patchNum, '/review'),
];
return Promise.all(promises).then(([, url]) => {
return this.send('POST', url, review, opt_errFn, opt_ctx);
return this.send('POST', url, review, opt_errFn);
});
},
@ -1542,7 +1508,7 @@
const e = `/files/${encodeURIComponent(path)}/content`;
const headers = {Accept: 'application/json'};
return this.getChangeURLAndSend(changeNum, 'GET', patchNum, e, null,
opt_errFn, null, null, headers);
opt_errFn, null, headers);
},
/**
@ -1554,7 +1520,7 @@
const e = '/edit/' + encodeURIComponent(path);
const headers = {Accept: 'application/json'};
return this.getChangeURLAndSend(changeNum, 'GET', null, e, null, null,
null, null, headers);
null, headers);
},
rebaseChangeEdit(changeNum) {
@ -1583,7 +1549,7 @@
saveChangeEdit(changeNum, path, contents) {
const e = '/edit/' + encodeURIComponent(path);
return this.getChangeURLAndSend(changeNum, 'PUT', null, e, contents, null,
null, 'text/plain');
'text/plain');
},
// Deprecated, prefer to use putChangeCommitMessage instead.
@ -1617,12 +1583,10 @@
* number at least.
* @param {?function(?Response, string=)=} opt_errFn
* passed as null sometimes.
* @param {?=} opt_ctx
* @param {?string=} opt_contentType
* @param {Object=} opt_headers
*/
send(method, url, opt_body, opt_errFn, opt_ctx, opt_contentType,
opt_headers) {
send(method, url, opt_body, opt_errFn, opt_contentType, opt_headers) {
const options = {method};
if (opt_body) {
options.headers = new Headers();
@ -1646,7 +1610,7 @@
return this._auth.fetch(url, options).then(response => {
if (!response.ok) {
if (opt_errFn) {
return opt_errFn.call(opt_ctx || null, response);
return opt_errFn.call(null, response);
}
this.fire('server-error', {response});
}
@ -1654,7 +1618,7 @@
}).catch(err => {
this.fire('network-error', {error: err});
if (opt_errFn) {
return opt_errFn.call(opt_ctx, null, err);
return opt_errFn.call(null, null, err);
} else {
throw err;
}
@ -2032,7 +1996,7 @@
},
addAccountSSHKey(key) {
return this.send('POST', '/accounts/self/sshkeys', key, null, null,
return this.send('POST', '/accounts/self/sshkeys', key, null,
'plain/text')
.then(response => {
if (response.status < 200 && response.status >= 300) {
@ -2220,17 +2184,15 @@
* @param {?Object|number|string=} opt_payload gets passed as null, string,
* Object, or number.
* @param {?function(?Response, string=)=} opt_errFn
* @param {?=} opt_ctx
* @param {?=} opt_contentType
* @param {Object=} opt_headers
* @return {!Promise<!Object>}
*/
getChangeURLAndSend(changeNum, method, patchNum, endpoint, opt_payload,
opt_errFn, opt_ctx, opt_contentType, opt_headers) {
return this._changeBaseURL(changeNum, patchNum).then(url => {
return this.send(method, url + endpoint, opt_payload, opt_errFn,
opt_ctx, opt_contentType, opt_headers);
});
opt_errFn, opt_contentType, opt_headers) {
return this._changeBaseURL(changeNum, patchNum).then(url =>
this.send(method, url + endpoint, opt_payload, opt_errFn,
opt_contentType, opt_headers));
},
/**