Change all components to use the service for rest-api-interface

Change-Id: I3acf9269ff43f463aca59aa10ca131b037cede9d
This commit is contained in:
Ben Rohlfs
2020-12-01 19:14:09 +01:00
parent bc87e856de
commit 43935a4918
211 changed files with 1052 additions and 1190 deletions

View File

@@ -296,7 +296,7 @@ Common errors and fixes are:
existing helpers to create an object with all required properties:
```
// Before:
sinon.stub(element.$.restAPI, 'getPreferences').returns(
sinon.stub(element.restApiService, 'getPreferences').returns(
Promise.resolve({default_diff_view: 'UNIFIED'}));
// After:

View File

@@ -153,5 +153,4 @@ export const htmlTemplate = html`
</div>
<!-- end deletedContainer -->
</fieldset>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -32,9 +32,9 @@ import {customElement, property, observe, computed} from '@polymer/decorators';
import {AppElementAdminParams} from '../../gr-app-types';
import {GrOverlay} from '../../shared/gr-overlay/gr-overlay';
import {GroupId, GroupInfo, GroupName} from '../../../types/common';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GrCreateGroupDialog} from '../gr-create-group-dialog/gr-create-group-dialog';
import {fireTitleChange} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
declare global {
interface HTMLElementTagNameMap {
@@ -46,7 +46,6 @@ export interface GrAdminGroupList {
$: {
createOverlay: GrOverlay;
createNewModal: GrCreateGroupDialog;
restAPI: RestApiService & Element;
};
}
@@ -97,6 +96,8 @@ export class GrAdminGroupList extends ListViewMixin(
@property({type: String})
_filter = '';
private restApiService = appContext.restApiService;
/** @override */
attached() {
super.attached();
@@ -131,11 +132,11 @@ export class GrAdminGroupList extends ListViewMixin(
}
_getCreateGroupCapability() {
return this.$.restAPI.getAccount().then(account => {
return this.restApiService.getAccount().then(account => {
if (!account) {
return;
}
return this.$.restAPI
return this.restApiService
.getAccountCapabilities(['createGroup'])
.then(capabilities => {
if (capabilities?.createGroup) {
@@ -147,7 +148,7 @@ export class GrAdminGroupList extends ListViewMixin(
_getGroups(filter: string, groupsPerPage: number, offset?: number) {
this._groups = [];
return this.$.restAPI
return this.restApiService
.getGroups(filter, groupsPerPage, offset)
.then(groups => {
if (!groups) {
@@ -163,7 +164,7 @@ export class GrAdminGroupList extends ListViewMixin(
}
_refreshGroupsList() {
this.$.restAPI.invalidateGroupsCache();
this.restApiService.invalidateGroupsCache();
return this._getGroups(this._filter, this._groupsPerPage, this._offset);
}

View File

@@ -78,5 +78,4 @@ export const htmlTemplate = html`
</div>
</gr-dialog>
</gr-overlay>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -131,7 +131,7 @@ suite('gr-admin-group-list tests', () => {
suite('filter', () => {
test('_paramsChanged', done => {
sinon.stub(
element.$.restAPI,
element.restApiService,
'getGroups')
.callsFake(() => Promise.resolve(groups));
const value = {
@@ -139,7 +139,7 @@ suite('gr-admin-group-list tests', () => {
offset: 25,
};
element._paramsChanged(value).then(() => {
assert.isTrue(element.$.restAPI.getGroups.lastCall
assert.isTrue(element.restApiService.getGroups.lastCall
.calledWithExactly('test', 25, 25));
done();
});

View File

@@ -52,7 +52,6 @@ import {
SubsectionInterface,
} from '../../../utils/admin-nav-util';
import {customElement, observe, property} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {
AppElementAdminParams,
AppElementGroupParams,
@@ -67,12 +66,12 @@ import {
import {GroupNameChangedDetail} from '../gr-group/gr-group';
import {ValueChangeDetail} from '../../shared/gr-dropdown-list/gr-dropdown-list';
import {GrJsApiInterface} from '../../shared/gr-js-api-interface/gr-js-api-interface-element';
import {appContext} from '../../../services/app-context';
const INTERNAL_GROUP_REGEX = /^[\da-f]{40}$/;
export interface GrAdminView {
$: {
restAPI: RestApiService & Element;
jsAPI: GrJsApiInterface;
};
}
@@ -183,6 +182,8 @@ export class GrAdminView extends GestureEventListeners(
@property({type: Boolean})
_showPluginList?: boolean;
private restApiService = appContext.restApiService;
/** @override */
attached() {
super.attached();
@@ -191,7 +192,7 @@ export class GrAdminView extends GestureEventListeners(
reload() {
const promises: [Promise<AccountDetailInfo | undefined>, Promise<void>] = [
this.$.restAPI.getAccount(),
this.restApiService.getAccount(),
getPluginLoader().awaitPluginsLoaded(),
];
return Promise.all(promises).then(result => {
@@ -212,7 +213,7 @@ export class GrAdminView extends GestureEventListeners(
return getAdminLinks(
this._account,
() =>
this.$.restAPI.getAccountCapabilities().then(capabilities => {
this.restApiService.getAccountCapabilities().then(capabilities => {
if (!capabilities) {
throw new Error('getAccountCapabilities returns undefined');
}
@@ -423,7 +424,7 @@ export class GrAdminView extends GestureEventListeners(
if (!groupId) return;
const promises: Array<Promise<void>> = [];
this.$.restAPI.getGroupConfig(groupId).then(group => {
this.restApiService.getGroupConfig(groupId).then(group => {
if (!group || !group.name) {
return;
}
@@ -433,13 +434,13 @@ export class GrAdminView extends GestureEventListeners(
this.reload();
promises.push(
this.$.restAPI.getIsAdmin().then(isAdmin => {
this.restApiService.getIsAdmin().then(isAdmin => {
this._isAdmin = !!isAdmin;
})
);
promises.push(
this.$.restAPI.getIsGroupOwner(group.name).then(isOwner => {
this.restApiService.getIsGroupOwner(group.name).then(isOwner => {
this._groupOwner = isOwner;
})
);

View File

@@ -178,6 +178,5 @@ export const htmlTemplate = html`
<gr-repo-dashboards repo="[[params.repo]]"></gr-repo-dashboards>
</main>
</template>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
<gr-js-api-interface id="jsAPI"></gr-js-api-interface>
`;

View File

@@ -83,11 +83,11 @@ suite('gr-admin-view tests', () => {
});
test('_filteredLinks admin', done => {
sinon.stub(element.$.restAPI, 'getAccount').returns(Promise.resolve({
sinon.stub(element.restApiService, 'getAccount').returns(Promise.resolve({
name: 'test-user',
}));
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccountCapabilities')
.callsFake(() => Promise.resolve({
createGroup: true,
@@ -111,11 +111,11 @@ suite('gr-admin-view tests', () => {
});
test('_filteredLinks non admin authenticated', done => {
sinon.stub(element.$.restAPI, 'getAccount').returns(Promise.resolve({
sinon.stub(element.restApiService, 'getAccount').returns(Promise.resolve({
name: 'test-user',
}));
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccountCapabilities')
.callsFake(() => Promise.resolve({})
);
@@ -171,11 +171,11 @@ suite('gr-admin-view tests', () => {
test('Repo shows up in nav', done => {
element._repoName = 'Test Repo';
sinon.stub(element.$.restAPI, 'getAccount').returns(Promise.resolve({
sinon.stub(element.restApiService, 'getAccount').returns(Promise.resolve({
name: 'test-user',
}));
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccountCapabilities')
.callsFake(() => Promise.resolve({
createGroup: true,
@@ -202,11 +202,11 @@ suite('gr-admin-view tests', () => {
element._groupIsInternal = true;
element._isAdmin = true;
element._groupOwner = false;
sinon.stub(element.$.restAPI, 'getAccount').returns(Promise.resolve({
sinon.stub(element.restApiService, 'getAccount').returns(Promise.resolve({
name: 'test-user',
}));
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccountCapabilities')
.callsFake(() => Promise.resolve({
createGroup: true,
@@ -232,7 +232,7 @@ suite('gr-admin-view tests', () => {
test('Nav is reloaded when repo changes', () => {
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccountCapabilities')
.callsFake(() => Promise.resolve({
createGroup: true,
@@ -240,7 +240,7 @@ suite('gr-admin-view tests', () => {
viewPlugins: true,
}));
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccount')
.callsFake(() => Promise.resolve({_id: 1}));
sinon.stub(element, 'reload');
@@ -254,7 +254,7 @@ suite('gr-admin-view tests', () => {
test('Nav is reloaded when group changes', () => {
sinon.stub(element, '_computeGroupName');
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccountCapabilities')
.callsFake(() => Promise.resolve({
createGroup: true,
@@ -262,7 +262,7 @@ suite('gr-admin-view tests', () => {
viewPlugins: true,
}));
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccount')
.callsFake(() => Promise.resolve({_id: 1}));
sinon.stub(element, 'reload');
@@ -321,7 +321,7 @@ suite('gr-admin-view tests', () => {
detail: GerritNav.RepoDetailView.ACCESS,
};
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccountCapabilities')
.callsFake(() => Promise.resolve({
createGroup: true,
@@ -329,7 +329,7 @@ suite('gr-admin-view tests', () => {
viewPlugins: true,
}));
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccount')
.callsFake(() => Promise.resolve({_id: 1}));
flush();
@@ -484,7 +484,7 @@ suite('gr-admin-view tests', () => {
suite('_computeSelectedClass', () => {
setup(() => {
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccountCapabilities')
.callsFake(() => Promise.resolve({
createGroup: true,
@@ -492,7 +492,7 @@ suite('gr-admin-view tests', () => {
viewPlugins: true,
}));
sinon.stub(
element.$.restAPI,
element.restApiService,
'getAccount')
.callsFake(() => Promise.resolve({_id: 1}));
@@ -576,12 +576,12 @@ suite('gr-admin-view tests', () => {
_loadGroupDetails: () => {},
});
sinon.stub(element.$.restAPI, 'getGroupConfig')
sinon.stub(element.restApiService, 'getGroupConfig')
.returns(Promise.resolve({
name: 'foo',
id: 'c0f83e941ce90caea30e6ad88f0d4ea0e841a7a9',
}));
sinon.stub(element.$.restAPI, 'getIsGroupOwner')
sinon.stub(element.restApiService, 'getIsGroupOwner')
.returns(Promise.resolve(true));
return element.reload();
});
@@ -619,8 +619,8 @@ suite('gr-admin-view tests', () => {
});
test('external group', () => {
element.$.restAPI.getGroupConfig.restore();
sinon.stub(element.$.restAPI, 'getGroupConfig')
element.restApiService.getGroupConfig.restore();
sinon.stub(element.restApiService, 'getGroupConfig')
.returns(Promise.resolve({
name: 'foo',
id: 'external-id',

View File

@@ -36,16 +36,15 @@ import {
} from '../../../types/common';
import {InheritedBooleanInfoConfiguredValue} from '../../../constants/constants';
import {hasOwnProperty} from '../../../utils/common-util';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GrAutocomplete} from '../../shared/gr-autocomplete/gr-autocomplete';
import {IronAutogrowTextareaElement} from '@polymer/iron-autogrow-textarea/iron-autogrow-textarea';
import {appContext} from '../../../services/app-context';
const SUGGESTIONS_LIMIT = 15;
const REF_PREFIX = 'refs/heads/';
export interface GrCreateChangeDialog {
$: {
restAPI: RestApiService & Element;
privateChangeCheckBox: HTMLInputElement;
branchInput: GrAutocomplete;
tagNameInput: HTMLInputElement;
@@ -93,6 +92,8 @@ export class GrCreateChangeDialog extends GestureEventListeners(
@property({type: Boolean})
_privateChangesEnabled?: boolean;
restApiService = appContext.restApiService;
constructor() {
super();
this._query = (input: string) => this._getRepoBranchesSuggestions(input);
@@ -108,14 +109,14 @@ export class GrCreateChangeDialog extends GestureEventListeners(
const promises = [];
promises.push(
this.$.restAPI.getProjectConfig(this.repoName).then(config => {
this.restApiService.getProjectConfig(this.repoName).then(config => {
if (!config) return;
this.privateByDefault = config.private_by_default;
})
);
promises.push(
this.$.restAPI.getConfig().then(config => {
this.restApiService.getConfig().then(config => {
if (!config) {
return;
}
@@ -143,7 +144,7 @@ export class GrCreateChangeDialog extends GestureEventListeners(
}
const isPrivate = this.$.privateChangeCheckBox.checked;
const isWip = true;
return this.$.restAPI
return this.restApiService
.createChange(
this.repoName,
this.branch,
@@ -169,7 +170,7 @@ export class GrCreateChangeDialog extends GestureEventListeners(
if (input.startsWith(REF_PREFIX)) {
input = input.substring(REF_PREFIX.length);
}
return this.$.restAPI
return this.restApiService
.getRepoBranches(input, this.repoName, SUGGESTIONS_LIMIT)
.then(response => {
if (!response) return [];

View File

@@ -113,5 +113,4 @@ export const htmlTemplate = html`
</span>
</section>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -68,7 +68,7 @@ suite('gr-create-change-dialog tests', () => {
};
const saveStub = sinon
.stub(element.$.restAPI, 'createChange')
.stub(element.restApiService, 'createChange')
.callsFake(() => Promise.resolve(createChange()));
element.branch = 'test-branch' as BranchName;
@@ -104,7 +104,7 @@ suite('gr-create-change-dialog tests', () => {
};
const saveStub = sinon
.stub(element.$.restAPI, 'createChange')
.stub(element.restApiService, 'createChange')
.callsFake(() => Promise.resolve(createChange()));
element.branch = 'test-branch' as BranchName;

View File

@@ -25,14 +25,8 @@ import {htmlTemplate} from './gr-create-group-dialog_html';
import {encodeURL, getBaseUrl} from '../../../utils/url-util';
import {page} from '../../../utils/page-wrapper-utils';
import {customElement, property, observe} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GroupName} from '../../../types/common';
export interface GrCreateGroupDialog {
$: {
restAPI: RestApiService & Element;
};
}
import {appContext} from '../../../services/app-context';
@customElement('gr-create-group-dialog')
export class GrCreateGroupDialog extends GestureEventListeners(
@@ -51,6 +45,8 @@ export class GrCreateGroupDialog extends GestureEventListeners(
@property({type: Boolean})
_groupCreated = false;
private restApiService = appContext.restApiService;
_computeGroupUrl(groupId: string) {
return getBaseUrl() + '/admin/groups/' + encodeURL(groupId, true);
}
@@ -62,12 +58,12 @@ export class GrCreateGroupDialog extends GestureEventListeners(
handleCreateGroup() {
const name = this._name as GroupName;
return this.$.restAPI.createGroup({name}).then(groupRegistered => {
return this.restApiService.createGroup({name}).then(groupRegistered => {
if (groupRegistered.status !== 201) {
return;
}
this._groupCreated = true;
return this.$.restAPI.getGroupConfig(name).then(group => {
return this.restApiService.getGroupConfig(name).then(group => {
// TODO(TS): should group always defined ?
page.show(this._computeGroupUrl(group!.group_id!));
});

View File

@@ -38,5 +38,4 @@ export const htmlTemplate = html`
</section>
</div>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -47,10 +47,10 @@ suite('gr-create-group-dialog tests', () => {
});
test('test for redirecting to group on successful creation', done => {
sinon.stub(element.$.restAPI, 'createGroup')
sinon.stub(element.restApiService, 'createGroup')
.returns(Promise.resolve({status: 201}));
sinon.stub(element.$.restAPI, 'getGroupConfig')
sinon.stub(element.restApiService, 'getGroupConfig')
.returns(Promise.resolve({group_id: 551}));
const showStub = sinon.stub(page, 'show');
@@ -62,10 +62,10 @@ suite('gr-create-group-dialog tests', () => {
});
test('test for unsuccessful group creation', done => {
sinon.stub(element.$.restAPI, 'createGroup')
sinon.stub(element.restApiService, 'createGroup')
.returns(Promise.resolve({status: 409}));
sinon.stub(element.$.restAPI, 'getGroupConfig')
sinon.stub(element.restApiService, 'getGroupConfig')
.returns(Promise.resolve({group_id: 551}));
const showStub = sinon.stub(page, 'show');

View File

@@ -28,19 +28,13 @@ import {encodeURL, getBaseUrl} from '../../../utils/url-util';
import {page} from '../../../utils/page-wrapper-utils';
import {customElement, property, observe} from '@polymer/decorators';
import {BranchName, RepoName} from '../../../types/common';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {appContext} from '../../../services/app-context';
enum DetailType {
branches = 'branches',
tags = 'tags',
}
export interface GrCreatePointerDialog {
$: {
restAPI: RestApiService & Element;
};
}
@customElement('gr-create-pointer-dialog')
export class GrCreatePointerDialog extends GestureEventListeners(
LegacyElementMixin(PolymerElement)
@@ -75,6 +69,8 @@ export class GrCreatePointerDialog extends GestureEventListeners(
this.hasNewItemName = !!name;
}
private restApiService = appContext.restApiService;
handleCreateItem() {
if (!this.repoName) {
throw new Error('repoName name is not set');
@@ -85,7 +81,7 @@ export class GrCreatePointerDialog extends GestureEventListeners(
const USE_HEAD = this._itemRevision ? this._itemRevision : 'HEAD';
const url = `${getBaseUrl()}/admin/repos/${encodeURL(this.repoName, true)}`;
if (this.itemDetail === DetailType.branches) {
return this.$.restAPI
return this.restApiService
.createRepoBranch(this.repoName, this._itemName, {revision: USE_HEAD})
.then(itemRegistered => {
if (itemRegistered.status === 201) {
@@ -93,7 +89,7 @@ export class GrCreatePointerDialog extends GestureEventListeners(
}
});
} else if (this.itemDetail === DetailType.tags) {
return this.$.restAPI
return this.restApiService
.createRepoTag(this.repoName, this._itemName, {
revision: USE_HEAD,
message: this._itemAnnotation || undefined,

View File

@@ -80,5 +80,4 @@ export const htmlTemplate = html`
</section>
</div>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -36,7 +36,7 @@ suite('gr-create-pointer-dialog tests', () => {
test('branch created', done => {
sinon.stub(
element.$.restAPI,
element.restApiService,
'createRepoBranch')
.callsFake(() => Promise.resolve({}));
@@ -58,7 +58,7 @@ suite('gr-create-pointer-dialog tests', () => {
test('tag created', done => {
sinon.stub(
element.$.restAPI,
element.restApiService,
'createRepoTag')
.callsFake(() => Promise.resolve({}));
@@ -80,7 +80,7 @@ suite('gr-create-pointer-dialog tests', () => {
test('tag created with annotations', done => {
sinon.stub(
element.$.restAPI,
element.restApiService,
'createRepoTag')
.callsFake(() => Promise.resolve({}));

View File

@@ -28,10 +28,10 @@ import {htmlTemplate} from './gr-create-repo-dialog_html';
import {encodeURL, getBaseUrl} from '../../../utils/url-util';
import {page} from '../../../utils/page-wrapper-utils';
import {customElement, observe, property} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {ProjectInput, RepoName} from '../../../types/common';
import {hasOwnProperty} from '../../../utils/common-util';
import {AutocompleteQuery} from '../../shared/gr-autocomplete/gr-autocomplete';
import {appContext} from '../../../services/app-context';
declare global {
interface HTMLElementTagNameMap {
@@ -39,12 +39,6 @@ declare global {
}
}
export interface GrCreateRepoDialog {
$: {
restAPI: RestApiService & Element;
};
}
@customElement('gr-create-repo-dialog')
export class GrCreateRepoDialog extends GestureEventListeners(
LegacyElementMixin(PolymerElement)
@@ -78,6 +72,8 @@ export class GrCreateRepoDialog extends GestureEventListeners(
@property({type: Object})
_queryGroups: AutocompleteQuery;
private restApiService = appContext.restApiService;
constructor() {
super();
this._query = (input: string) => this._getRepoSuggestions(input);
@@ -103,16 +99,18 @@ export class GrCreateRepoDialog extends GestureEventListeners(
}
handleCreateRepo() {
return this.$.restAPI.createRepo(this._repoConfig).then(repoRegistered => {
if (repoRegistered.status === 201) {
this._repoCreated = true;
page.show(this._computeRepoUrl(this._repoConfig.name));
}
});
return this.restApiService
.createRepo(this._repoConfig)
.then(repoRegistered => {
if (repoRegistered.status === 201) {
this._repoCreated = true;
page.show(this._computeRepoUrl(this._repoConfig.name));
}
});
}
_getRepoSuggestions(input: string) {
return this.$.restAPI.getSuggestedProjects(input).then(response => {
return this.restApiService.getSuggestedProjects(input).then(response => {
const repos = [];
for (const key in response) {
if (!hasOwnProperty(response, key)) {
@@ -128,7 +126,7 @@ export class GrCreateRepoDialog extends GestureEventListeners(
}
_getGroupSuggestions(input: string) {
return this.$.restAPI.getSuggestedGroups(input).then(response => {
return this.restApiService.getSuggestedGroups(input).then(response => {
const groups = [];
for (const key in response) {
if (!hasOwnProperty(response, key)) {

View File

@@ -99,5 +99,4 @@ export const htmlTemplate = html`
</section>
</div>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -44,7 +44,7 @@ suite('gr-create-repo-dialog tests', () => {
owners: ['testId'],
};
const saveStub = sinon.stub(element.$.restAPI,
const saveStub = sinon.stub(element.restApiService,
'createRepo').callsFake(() => Promise.resolve({}));
assert.isFalse(element.hasNewRepoName);

View File

@@ -27,10 +27,7 @@ import {htmlTemplate} from './gr-group-audit-log_html';
import {ListViewMixin} from '../../../mixins/gr-list-view-mixin/gr-list-view-mixin';
import {GerritNav} from '../../core/gr-navigation/gr-navigation';
import {customElement, property} from '@polymer/decorators';
import {
ErrorCallback,
RestApiService,
} from '../../../services/services/gr-rest-api/gr-rest-api';
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
import {
GroupInfo,
AccountInfo,
@@ -38,14 +35,10 @@ import {
GroupAuditEventInfo,
} from '../../../types/common';
import {firePageError, fireTitleChange} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
const GROUP_EVENTS = ['ADD_GROUP', 'REMOVE_GROUP'];
export interface GrGroupAuditLog {
$: {
restAPI: RestApiService & Element;
};
}
@customElement('gr-group-audit-log')
export class GrGroupAuditLog extends ListViewMixin(
GestureEventListeners(LegacyElementMixin(PolymerElement))
@@ -63,6 +56,8 @@ export class GrGroupAuditLog extends ListViewMixin(
@property({type: Boolean})
_loading = true;
private restApiService = appContext.restApiService;
/** @override */
attached() {
super.attached();
@@ -84,7 +79,7 @@ export class GrGroupAuditLog extends ListViewMixin(
firePageError(this, response);
};
return this.$.restAPI
return this.restApiService
.getGroupAuditLog(this.groupId, errFn)
.then(auditLog => {
if (!auditLog) {

View File

@@ -66,5 +66,4 @@ export const htmlTemplate = html`
</template>
</tbody>
</table>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -80,7 +80,7 @@ suite('gr-group-audit-log tests', () => {
const response = {status: 404};
sinon.stub(
element.$.restAPI, 'getGroupAuditLog')
element.restApiService, 'getGroupAuditLog')
.callsFake((group, errFn) => {
errFn(response);
});

View File

@@ -31,10 +31,7 @@ import {PolymerElement} from '@polymer/polymer/polymer-element';
import {htmlTemplate} from './gr-group-members_html';
import {getBaseUrl} from '../../../utils/url-util';
import {customElement, property} from '@polymer/decorators';
import {
RestApiService,
ErrorCallback,
} from '../../../services/services/gr-rest-api/gr-rest-api';
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GrOverlay} from '../../shared/gr-overlay/gr-overlay';
import {
GroupId,
@@ -51,6 +48,7 @@ import {
firePageError,
fireTitleChange,
} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
const SUGGESTIONS_LIMIT = 15;
const SAVING_ERROR_TEXT =
@@ -60,7 +58,6 @@ const URL_REGEX = '^(?:[a-z]+:)?//';
export interface GrGroupMembers {
$: {
restAPI: RestApiService & Element;
overlay: GrOverlay;
};
}
@@ -119,6 +116,8 @@ export class GrGroupMembers extends GestureEventListeners(
_itemId?: AccountId | GroupId;
private restApiService = appContext.restApiService;
constructor() {
super();
this._queryMembers = input => this._getAccountSuggestions(input);
@@ -144,41 +143,45 @@ export class GrGroupMembers extends GestureEventListeners(
firePageError(this, response);
};
return this.$.restAPI.getGroupConfig(this.groupId, errFn).then(config => {
if (!config || !config.name) {
return Promise.resolve();
}
return this.restApiService
.getGroupConfig(this.groupId, errFn)
.then(config => {
if (!config || !config.name) {
return Promise.resolve();
}
this._groupName = config.name;
this._groupName = config.name;
promises.push(
this.$.restAPI.getIsAdmin().then(isAdmin => {
this._isAdmin = !!isAdmin;
})
);
promises.push(
this.restApiService.getIsAdmin().then(isAdmin => {
this._isAdmin = !!isAdmin;
})
);
promises.push(
this.$.restAPI.getIsGroupOwner(this._groupName).then(isOwner => {
this._groupOwner = !!isOwner;
})
);
promises.push(
this.restApiService.getIsGroupOwner(this._groupName).then(isOwner => {
this._groupOwner = !!isOwner;
})
);
promises.push(
this.$.restAPI.getGroupMembers(this._groupName).then(members => {
this._groupMembers = members;
})
);
promises.push(
this.restApiService.getGroupMembers(this._groupName).then(members => {
this._groupMembers = members;
})
);
promises.push(
this.$.restAPI.getIncludedGroup(this._groupName).then(includedGroup => {
this._includedGroups = includedGroup;
})
);
promises.push(
this.restApiService
.getIncludedGroup(this._groupName)
.then(includedGroup => {
this._includedGroups = includedGroup;
})
);
return Promise.all(promises).then(() => {
this._loading = false;
return Promise.all(promises).then(() => {
this._loading = false;
});
});
});
}
_computeLoadingClass(loading: boolean) {
@@ -210,13 +213,13 @@ export class GrGroupMembers extends GestureEventListeners(
if (!this._groupName) {
return Promise.reject(new Error('group name undefined'));
}
return this.$.restAPI
return this.restApiService
.saveGroupMember(this._groupName, this._groupMemberSearchId as AccountId)
.then(config => {
if (!config || !this._groupName) {
return;
}
this.$.restAPI.getGroupMembers(this._groupName).then(members => {
this.restApiService.getGroupMembers(this._groupName).then(members => {
this._groupMembers = members;
});
this._groupMemberSearchName = '';
@@ -230,24 +233,26 @@ export class GrGroupMembers extends GestureEventListeners(
}
this.$.overlay.close();
if (this._itemType === 'member') {
return this.$.restAPI
return this.restApiService
.deleteGroupMember(this._groupName, this._itemId! as AccountId)
.then(itemDeleted => {
if (itemDeleted.status === 204 && this._groupName) {
this.$.restAPI.getGroupMembers(this._groupName).then(members => {
this._groupMembers = members;
});
this.restApiService
.getGroupMembers(this._groupName)
.then(members => {
this._groupMembers = members;
});
}
});
} else if (this._itemType === 'includedGroup') {
return this.$.restAPI
return this.restApiService
.deleteIncludedGroup(this._groupName, this._itemId! as GroupId)
.then(itemDeleted => {
if (
(itemDeleted.status === 204 || itemDeleted.status === 205) &&
this._groupName
) {
this.$.restAPI
this.restApiService
.getIncludedGroup(this._groupName)
.then(includedGroup => {
this._includedGroups = includedGroup;
@@ -283,7 +288,7 @@ export class GrGroupMembers extends GestureEventListeners(
new Error('group name or includedGroupSearchId undefined')
);
}
return this.$.restAPI
return this.restApiService
.saveIncludedGroup(
this._groupName,
this._includedGroupSearchId.replace(/\+/g, ' ') as GroupId,
@@ -302,9 +307,11 @@ export class GrGroupMembers extends GestureEventListeners(
if (!config || !this._groupName) {
return;
}
this.$.restAPI.getIncludedGroup(this._groupName).then(includedGroup => {
this._includedGroups = includedGroup;
});
this.restApiService
.getIncludedGroup(this._groupName)
.then(includedGroup => {
this._includedGroups = includedGroup;
});
this._includedGroupSearchName = '';
this._includedGroupSearchId = '';
});
@@ -330,7 +337,7 @@ export class GrGroupMembers extends GestureEventListeners(
if (input.length === 0) {
return Promise.resolve([]);
}
return this.$.restAPI
return this.restApiService
.getSuggestedAccounts(input, SUGGESTIONS_LIMIT)
.then(accounts => {
const accountSuggestions = [];
@@ -357,7 +364,7 @@ export class GrGroupMembers extends GestureEventListeners(
}
_getGroupSuggestions(input: string) {
return this.$.restAPI.getSuggestedGroups(input).then(response => {
return this.restApiService.getSuggestedGroups(input).then(response => {
const groups = [];
for (const key in response) {
if (!hasOwnProperty(response, key)) {

View File

@@ -180,5 +180,4 @@ export const htmlTemplate = html`
item-type="[[_itemType]]"
></gr-confirm-delete-item-dialog>
</gr-overlay>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -139,7 +139,7 @@ suite('gr-group-members tests', () => {
stubBaseUrl('https://test/site');
element.groupId = 1;
groupStub = sinon.stub(
element.$.restAPI,
element.restApiService,
'getGroupConfig')
.callsFake(() => Promise.resolve(groups));
return element._loadGroupDetails();
@@ -162,7 +162,7 @@ suite('gr-group-members tests', () => {
const memberName = 'test-admin';
const saveStub = sinon.stub(element.$.restAPI, 'saveGroupMember')
const saveStub = sinon.stub(element.restApiService, 'saveGroupMember')
.callsFake(() => Promise.resolve({}));
const button = element.$.saveGroupMember;
@@ -188,7 +188,7 @@ suite('gr-group-members tests', () => {
const includedGroupName = 'testName';
const saveIncludedGroupStub = sinon.stub(
element.$.restAPI, 'saveIncludedGroup')
element.restApiService, 'saveIncludedGroup')
.callsFake(() => Promise.resolve({}));
const button = element.$.saveIncludedGroups;
@@ -219,7 +219,7 @@ suite('gr-group-members tests', () => {
status: 404,
ok: false,
};
sinon.stub(element.$.restAPI._restApiHelper, 'fetch').callsFake(
sinon.stub(element.restApiService._restApiHelper, 'fetch').callsFake(
() => Promise.resolve(errorResponse));
element.$.groupMemberSearchInput.text = memberName;
@@ -237,7 +237,7 @@ suite('gr-group-members tests', () => {
const alertStub = sinon.stub();
element.addEventListener('show-alert', alertStub);
const err = new Error();
sinon.stub(element.$.restAPI._restApiHelper, 'fetch').callsFake(
sinon.stub(element.restApiService._restApiHelper, 'fetch').callsFake(
() => Promise.reject(err));
element.$.groupMemberSearchInput.text = memberName;
@@ -367,7 +367,7 @@ suite('gr-group-members tests', () => {
const response = {status: 404};
sinon.stub(
element.$.restAPI, 'getGroupConfig')
element.restApiService, 'getGroupConfig')
.callsFake((group, errFn) => {
errFn(response);
});

View File

@@ -33,12 +33,10 @@ import {
AutocompleteQuery,
} from '../../shared/gr-autocomplete/gr-autocomplete';
import {GroupId, GroupInfo, GroupName} from '../../../types/common';
import {
ErrorCallback,
RestApiService,
} from '../../../services/services/gr-rest-api/gr-rest-api';
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
import {hasOwnProperty} from '../../../utils/common-util';
import {firePageError, fireTitleChange} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
const INTERNAL_GROUP_REGEX = /^[\da-f]{40}$/;
@@ -55,7 +53,6 @@ const OPTIONS = {
export interface GrGroup {
$: {
restAPI: RestApiService & Element;
loading: HTMLDivElement;
};
}
@@ -127,6 +124,8 @@ export class GrGroup extends GestureEventListeners(
@property({type: Boolean})
_isAdmin = false;
private restApiService = appContext.restApiService;
constructor() {
super();
this._query = (input: string) => this._getGroupSuggestions(input);
@@ -149,41 +148,43 @@ export class GrGroup extends GestureEventListeners(
firePageError(this, response);
};
return this.$.restAPI.getGroupConfig(this.groupId, errFn).then(config => {
if (!config || !config.name) {
return Promise.resolve();
}
return this.restApiService
.getGroupConfig(this.groupId, errFn)
.then(config => {
if (!config || !config.name) {
return Promise.resolve();
}
this._groupName = config.name;
this._groupIsInternal = !!config.id.match(INTERNAL_GROUP_REGEX);
this._groupName = config.name;
this._groupIsInternal = !!config.id.match(INTERNAL_GROUP_REGEX);
promises.push(
this.$.restAPI.getIsAdmin().then(isAdmin => {
this._isAdmin = !!isAdmin;
})
);
promises.push(
this.restApiService.getIsAdmin().then(isAdmin => {
this._isAdmin = !!isAdmin;
})
);
promises.push(
this.$.restAPI.getIsGroupOwner(config.name).then(isOwner => {
this._groupOwner = !!isOwner;
})
);
promises.push(
this.restApiService.getIsGroupOwner(config.name).then(isOwner => {
this._groupOwner = !!isOwner;
})
);
// If visible to all is undefined, set to false. If it is defined
// as false, setting to false is fine. If any optional values
// are added with a default of true, then this would need to be an
// undefined check and not a truthy/falsy check.
if (config.options && !config.options.visible_to_all) {
config.options.visible_to_all = false;
}
this._groupConfig = config;
// If visible to all is undefined, set to false. If it is defined
// as false, setting to false is fine. If any optional values
// are added with a default of true, then this would need to be an
// undefined check and not a truthy/falsy check.
if (config.options && !config.options.visible_to_all) {
config.options.visible_to_all = false;
}
this._groupConfig = config;
fireTitleChange(this, config.name);
fireTitleChange(this, config.name);
return Promise.all(promises).then(() => {
this._loading = false;
return Promise.all(promises).then(() => {
this._loading = false;
});
});
});
}
_computeLoadingClass(loading: boolean) {
@@ -200,7 +201,7 @@ export class GrGroup extends GestureEventListeners(
return Promise.reject(new Error('invalid groupId or config name'));
}
const groupName = groupConfig.name;
return this.$.restAPI
return this.restApiService
.saveGroupName(this.groupId, groupName)
.then(config => {
if (config.status === 200) {
@@ -228,7 +229,7 @@ export class GrGroup extends GestureEventListeners(
owner = decodeURIComponent(this._groupConfigOwner);
}
if (!owner) return;
return this.$.restAPI.saveGroupOwner(this.groupId, owner).then(() => {
return this.restApiService.saveGroupOwner(this.groupId, owner).then(() => {
this._owner = false;
});
}
@@ -236,7 +237,7 @@ export class GrGroup extends GestureEventListeners(
_handleSaveDescription() {
if (!this.groupId || !this._groupConfig || !this._groupConfig.description)
return;
return this.$.restAPI
return this.restApiService
.saveGroupDescription(this.groupId, this._groupConfig.description)
.then(() => {
this._description = false;
@@ -250,9 +251,11 @@ export class GrGroup extends GestureEventListeners(
const options = {visible_to_all: visible};
return this.$.restAPI.saveGroupOptions(this.groupId, options).then(() => {
this._options = false;
});
return this.restApiService
.saveGroupOptions(this.groupId, options)
.then(() => {
this._options = false;
});
}
@observe('_groupConfig.name')
@@ -292,7 +295,7 @@ export class GrGroup extends GestureEventListeners(
}
_getGroupSuggestions(input: string) {
return this.$.restAPI.getSuggestedGroups(input).then(response => {
return this.restApiService.getSuggestedGroups(input).then(response => {
const groups: AutocompleteSuggestion[] = [];
for (const key in response) {
if (!hasOwnProperty(response, key)) {

View File

@@ -165,5 +165,4 @@ export const htmlTemplate = html`
</div>
</div>
</main>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -41,7 +41,7 @@ suite('gr-group tests', () => {
});
element = basicFixture.instantiate();
groupStub = sinon.stub(
element.$.restAPI,
element.restApiService,
'getGroupConfig')
.callsFake(() => Promise.resolve(group));
});
@@ -56,7 +56,7 @@ suite('gr-group tests', () => {
test('default values are populated with internal group', done => {
sinon.stub(
element.$.restAPI,
element.restApiService,
'getIsGroupOwner')
.callsFake(() => Promise.resolve(true));
element.groupId = 1;
@@ -72,11 +72,11 @@ suite('gr-group tests', () => {
groupExternal.id = 'external-group-id';
groupStub.restore();
groupStub = sinon.stub(
element.$.restAPI,
element.restApiService,
'getGroupConfig')
.callsFake(() => Promise.resolve(groupExternal));
sinon.stub(
element.$.restAPI,
element.restApiService,
'getIsGroupOwner')
.callsFake(() => Promise.resolve(true));
element.groupId = 1;
@@ -97,12 +97,12 @@ suite('gr-group tests', () => {
element._groupName = groupName;
sinon.stub(
element.$.restAPI,
element.restApiService,
'getIsGroupOwner')
.callsFake(() => Promise.resolve(true));
sinon.stub(
element.$.restAPI,
element.restApiService,
'saveGroupName')
.callsFake(() => Promise.resolve({status: 200}));
@@ -136,7 +136,7 @@ suite('gr-group tests', () => {
element._groupOwner = true;
sinon.stub(
element.$.restAPI,
element.restApiService,
'getIsGroupOwner')
.callsFake(() => Promise.resolve({status: 200}));
@@ -163,7 +163,7 @@ suite('gr-group tests', () => {
groupStub.restore();
sinon.stub(
element.$.restAPI,
element.restApiService,
'getGroupConfig')
.callsFake(() => Promise.resolve({}));
@@ -189,7 +189,7 @@ suite('gr-group tests', () => {
name: 'test-group',
};
element.groupId = 'gg';
sinon.stub(element.$.restAPI, 'saveGroupName')
sinon.stub(element.restApiService, 'saveGroupName')
.returns(Promise.resolve({status: 200}));
const showStub = sinon.stub(element, 'dispatchEvent');
@@ -240,7 +240,7 @@ suite('gr-group tests', () => {
const response = {status: 404};
sinon.stub(
element.$.restAPI, 'getGroupConfig').callsFake((group, errFn) => {
element.restApiService, 'getGroupConfig').callsFake((group, errFn) => {
errFn(response);
});

View File

@@ -34,7 +34,6 @@ import {
PermissionArray,
} from '../../../utils/access-util';
import {customElement, property, observe} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {hasOwnProperty} from '../../../utils/common-util';
import {
LabelNameToLabelTypeInfoMap,
@@ -56,6 +55,7 @@ import {
EditableProjectAccessGroups,
} from '../gr-repo-access/gr-repo-access-interfaces';
import {PolymerDomRepeatEvent} from '../../../types/types';
import {appContext} from '../../../services/app-context';
const MAX_AUTOCOMPLETE_RESULTS = 20;
@@ -65,7 +65,6 @@ type GroupsWithRulesMap = {[ruleId: string]: boolean};
export interface GrPermission {
$: {
restAPI: RestApiService & Element;
groupAutocomplete: GrAutocomplete;
};
}
@@ -142,6 +141,8 @@ export class GrPermission extends GestureEventListeners(
@property({type: Boolean})
_originalExclusiveValue?: boolean;
private restApiService = appContext.restApiService;
constructor() {
super();
this._query = () => this._getGroupSuggestions();
@@ -337,7 +338,7 @@ export class GrPermission extends GestureEventListeners(
}
_getGroupSuggestions(): Promise<AutocompleteSuggestion[]> {
return this.$.restAPI
return this.restApiService
.getSuggestedGroups(this._groupFilter || '', MAX_AUTOCOMPLETE_RESULTS)
.then(response => {
const groups: GroupSuggestion[] = [];

View File

@@ -140,5 +140,4 @@ export const htmlTemplate = html`
</div>
<!-- end deletedContainer -->
</section>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -25,7 +25,7 @@ suite('gr-permission tests', () => {
setup(() => {
element = basicFixture.instantiate();
sinon.stub(element.$.restAPI, 'getSuggestedGroups').returns(
sinon.stub(element.restApiService, 'getSuggestedGroups').returns(
Promise.resolve({
'Administrators': {
id: '4c97682e6ce61b7247f3381b6f1789356666de7f',

View File

@@ -27,20 +27,15 @@ import {
ListViewParams,
} from '../../../mixins/gr-list-view-mixin/gr-list-view-mixin';
import {customElement, property} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
import {PluginInfo} from '../../../types/common';
import {firePageError} from '../../../utils/event-util';
import {fireTitleChange} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
interface PluginInfoWithName extends PluginInfo {
name: string;
}
export interface GrPluginList {
$: {
restAPI: RestApiService & Element;
};
}
@customElement('gr-plugin-list')
export class GrPluginList extends ListViewMixin(
GestureEventListeners(LegacyElementMixin(PolymerElement))
@@ -83,6 +78,8 @@ export class GrPluginList extends ListViewMixin(
@property({type: String})
_filter = '';
private restApiService = appContext.restApiService;
/** @override */
attached() {
super.attached();
@@ -101,7 +98,7 @@ export class GrPluginList extends ListViewMixin(
const errFn: ErrorCallback = response => {
firePageError(this, response);
};
return this.$.restAPI
return this.restApiService
.getPlugins(filter, pluginsPerPage, offset, errFn)
.then(plugins => {
if (!plugins) {

View File

@@ -78,5 +78,4 @@ export const htmlTemplate = html`
</tbody>
</table>
</gr-list-view>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -131,7 +131,7 @@ suite('gr-plugin-list tests', () => {
suite('filter', () => {
test('_paramsChanged', done => {
sinon.stub(
element.$.restAPI,
element.restApiService,
'getPlugins')
.callsFake(() => Promise.resolve(plugins));
const value = {
@@ -139,11 +139,11 @@ suite('gr-plugin-list tests', () => {
offset: 25,
};
element._paramsChanged(value).then(() => {
assert.equal(element.$.restAPI.getPlugins.lastCall.args[0],
assert.equal(element.restApiService.getPlugins.lastCall.args[0],
'test');
assert.equal(element.$.restAPI.getPlugins.lastCall.args[1],
assert.equal(element.restApiService.getPlugins.lastCall.args[1],
25);
assert.equal(element.$.restAPI.getPlugins.lastCall.args[2],
assert.equal(element.restApiService.getPlugins.lastCall.args[2],
25);
done();
});
@@ -168,7 +168,7 @@ suite('gr-plugin-list tests', () => {
suite('404', () => {
test('fires page-error', done => {
const response = {status: 404};
sinon.stub(element.$.restAPI, 'getPlugins').callsFake(
sinon.stub(element.restApiService, 'getPlugins').callsFake(
(filter, pluginsPerPage, opt_offset, errFn) => {
errFn(response);
});

View File

@@ -38,7 +38,6 @@ import {
UrlEncodedRepoName,
ProjectAccessGroups,
} from '../../../types/common';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {hasOwnProperty} from '../../../utils/common-util';
import {GrButton} from '../../shared/gr-button/gr-button';
import {GrAccessSection} from '../gr-access-section/gr-access-section';
@@ -53,17 +52,12 @@ import {
PrimitiveValue,
} from './gr-repo-access-interfaces';
import {firePageError, fireAlert} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
const NOTHING_TO_SAVE = 'No changes to save.';
const MAX_AUTOCOMPLETE_RESULTS = 50;
export interface GrRepoAccess {
$: {
restAPI: RestApiService & Element;
};
}
/**
* Fired when save is a no-op
*
@@ -127,6 +121,8 @@ export class GrRepoAccess extends GestureEventListeners(
private _originalInheritsFrom?: ProjectInfo | null;
private restApiService = appContext.restApiService;
constructor() {
super();
this._query = () => this._getInheritFromSuggestions();
@@ -163,7 +159,7 @@ export class GrRepoAccess extends GestureEventListeners(
// Always reset sections when a project changes.
this._sections = [];
const sectionsPromises = this.$.restAPI
const sectionsPromises = this.restApiService
.getRepoAccessRights(repo, errFn)
.then(res => {
if (!res) {
@@ -199,7 +195,7 @@ export class GrRepoAccess extends GestureEventListeners(
return toSortedPermissionsArray(this._local);
});
const capabilitiesPromises = this.$.restAPI
const capabilitiesPromises = this.restApiService
.getCapabilities(errFn)
.then(res => {
if (!res) {
@@ -209,13 +205,15 @@ export class GrRepoAccess extends GestureEventListeners(
return res;
});
const labelsPromises = this.$.restAPI.getRepo(repo, errFn).then(res => {
if (!res) {
return Promise.resolve(undefined);
}
const labelsPromises = this.restApiService
.getRepo(repo, errFn)
.then(res => {
if (!res) {
return Promise.resolve(undefined);
}
return res.labels;
});
return res.labels;
});
return Promise.all([
sectionsPromises,
@@ -247,7 +245,7 @@ export class GrRepoAccess extends GestureEventListeners(
}
_getInheritFromSuggestions(): Promise<AutocompleteSuggestion[]> {
return this.$.restAPI
return this.restApiService
.getRepos(this._inheritFromFilter, MAX_AUTOCOMPLETE_RESULTS)
.then(response => {
const projects: AutocompleteSuggestion[] = [];
@@ -537,7 +535,7 @@ export class GrRepoAccess extends GestureEventListeners(
if (!repo) {
return Promise.resolve();
}
return this.$.restAPI
return this.restApiService
.setRepoAccessRights(repo, obj)
.then(() => {
this._reload(repo);
@@ -562,7 +560,7 @@ export class GrRepoAccess extends GestureEventListeners(
if (!this.repo) {
return;
}
return this.$.restAPI
return this.restApiService
.setRepoAccessRightsForReview(this.repo, obj)
.then(change => {
GerritNav.navigateToChange(change);

View File

@@ -143,5 +143,4 @@ export const htmlTemplate = html`
</div>
</div>
</main>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -104,7 +104,7 @@ suite('gr-repo-access tests', () => {
stub('gr-rest-api-interface', {
getAccount() { return Promise.resolve(null); },
});
repoStub = sinon.stub(element.$.restAPI, 'getRepo').returns(
repoStub = sinon.stub(element.restApiService, 'getRepo').returns(
Promise.resolve(repoRes));
element._loading = false;
element._ownerOf = [];
@@ -118,14 +118,14 @@ suite('gr-repo-access tests', () => {
});
test('_repoChanged', done => {
const accessStub = sinon.stub(element.$.restAPI,
const accessStub = sinon.stub(element.restApiService,
'getRepoAccessRights');
accessStub.withArgs('New Repo').returns(
Promise.resolve(JSON.parse(JSON.stringify(accessRes))));
accessStub.withArgs('Another New Repo')
.returns(Promise.resolve(JSON.parse(JSON.stringify(accessRes2))));
const capabilitiesStub = sinon.stub(element.$.restAPI,
const capabilitiesStub = sinon.stub(element.restApiService,
'getCapabilities');
capabilitiesStub.returns(Promise.resolve(capabilitiesRes));
@@ -160,9 +160,9 @@ suite('gr-repo-access tests', () => {
name: 'Access Database',
},
};
const accessStub = sinon.stub(element.$.restAPI, 'getRepoAccessRights')
const accessStub = sinon.stub(element.restApiService, 'getRepoAccessRights')
.returns(Promise.resolve(JSON.parse(JSON.stringify(accessRes2))));
const capabilitiesStub = sinon.stub(element.$.restAPI,
const capabilitiesStub = sinon.stub(element.restApiService,
'getCapabilities').returns(Promise.resolve(capabilitiesRes));
element._repoChanged().then(() => {
@@ -241,7 +241,7 @@ suite('gr-repo-access tests', () => {
const response = {status: 404};
sinon.stub(
element.$.restAPI, 'getRepoAccessRights')
element.restApiService, 'getRepoAccessRights')
.callsFake((repoName, errFn) => {
errFn(response);
});
@@ -378,7 +378,7 @@ suite('gr-repo-access tests', () => {
test('_handleSaveForReview', () => {
const saveStub =
sinon.stub(element.$.restAPI, 'setRepoAccessRightsForReview');
sinon.stub(element.restApiService, 'setRepoAccessRightsForReview');
sinon.stub(element, '_computeAddAndRemove').returns({
add: {},
remove: {},
@@ -1161,11 +1161,11 @@ suite('gr-repo-access tests', () => {
},
},
};
sinon.stub(element.$.restAPI, 'getRepoAccessRights').returns(
sinon.stub(element.restApiService, 'getRepoAccessRights').returns(
Promise.resolve(JSON.parse(JSON.stringify(accessRes))));
sinon.stub(GerritNav, 'navigateToChange');
let resolver;
const saveStub = sinon.stub(element.$.restAPI,
const saveStub = sinon.stub(element.restApiService,
'setRepoAccessRights')
.returns(new Promise(r => resolver = r));
@@ -1208,11 +1208,11 @@ suite('gr-repo-access tests', () => {
},
},
};
sinon.stub(element.$.restAPI, 'getRepoAccessRights').returns(
sinon.stub(element.restApiService, 'getRepoAccessRights').returns(
Promise.resolve(JSON.parse(JSON.stringify(accessRes))));
sinon.stub(GerritNav, 'navigateToChange');
let resolver;
const saveForReviewStub = sinon.stub(element.$.restAPI,
const saveForReviewStub = sinon.stub(element.restApiService,
'setRepoAccessRightsForReview')
.returns(new Promise(r => resolver = r));

View File

@@ -30,10 +30,7 @@ import {PolymerElement} from '@polymer/polymer/polymer-element';
import {htmlTemplate} from './gr-repo-commands_html';
import {GerritNav} from '../../core/gr-navigation/gr-navigation';
import {customElement, property} from '@polymer/decorators';
import {
ErrorCallback,
RestApiService,
} from '../../../services/services/gr-rest-api/gr-rest-api';
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
import {
BranchName,
ConfigInfo,
@@ -47,6 +44,7 @@ import {
firePageError,
fireTitleChange,
} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
const GC_MESSAGE = 'Garbage collection completed successfully.';
const CONFIG_BRANCH = 'refs/meta/config' as BranchName;
@@ -58,7 +56,6 @@ const CREATE_CHANGE_SUCCEEDED_MESSAGE = 'Navigating to change';
export interface GrRepoCommands {
$: {
restAPI: RestApiService & Element;
createChangeOverlay: GrOverlay;
createNewChangeModal: GrCreateChangeDialog;
};
@@ -95,6 +92,8 @@ export class GrRepoCommands extends GestureEventListeners(
@property({type: Boolean})
_runningGC = false;
private restApiService = appContext.restApiService;
/** @override */
attached() {
super.attached();
@@ -111,7 +110,7 @@ export class GrRepoCommands extends GestureEventListeners(
firePageError(this, response);
};
this.$.restAPI.getProjectConfig(this.repo, errFn).then(config => {
this.restApiService.getProjectConfig(this.repo, errFn).then(config => {
if (!config) return;
// Do not process the response, if the component is not attached to the
// DOM anymore, which at least in tests can happen.
@@ -131,7 +130,7 @@ export class GrRepoCommands extends GestureEventListeners(
_handleRunningGC() {
this._runningGC = true;
return this.$.restAPI
return this.restApiService
.runRepoGC(this.repo)
.then(response => {
if (response?.status === 200) {
@@ -164,7 +163,7 @@ export class GrRepoCommands extends GestureEventListeners(
*/
_handleEditRepoConfig() {
this._editingConfig = true;
return this.$.restAPI
return this.restApiService
.createChange(
this.repo,
CONFIG_BRANCH,

View File

@@ -88,5 +88,4 @@ export const htmlTemplate = html`
</div>
</gr-dialog>
</gr-overlay>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -31,7 +31,7 @@ suite('gr-repo-commands tests', () => {
// Note that this probably does not achieve what it is supposed to, because
// getProjectConfig() is called as soon as the element is attached, so
// stubbing it here has not effect anymore.
repoStub = sinon.stub(element.$.restAPI, 'getProjectConfig')
repoStub = sinon.stub(element.restApiService, 'getProjectConfig')
.returns(Promise.resolve({}));
});
@@ -68,7 +68,7 @@ suite('gr-repo-commands tests', () => {
let alertStub;
setup(() => {
createChangeStub = sinon.stub(element.$.restAPI, 'createChange');
createChangeStub = sinon.stub(element.restApiService, 'createChange');
urlStub = sinon.stub(GerritNav, 'getEditUrlForDiff');
sinon.stub(GerritNav, 'navigateToRelativeUrl');
handleSpy = sinon.spy(element, '_handleEditRepoConfig');
@@ -119,7 +119,7 @@ suite('gr-repo-commands tests', () => {
const response = {status: 404};
sinon.stub(
element.$.restAPI, 'getProjectConfig')
element.restApiService, 'getProjectConfig')
.callsFake((repo, errFn) => {
errFn(response);
});

View File

@@ -24,21 +24,16 @@ import {PolymerElement} from '@polymer/polymer/polymer-element';
import {htmlTemplate} from './gr-repo-dashboards_html';
import {GerritNav} from '../../core/gr-navigation/gr-navigation';
import {customElement, property} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {RepoName, DashboardId, DashboardInfo} from '../../../types/common';
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
import {firePageError} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
interface DashboardRef {
section: string;
dashboards: DashboardInfo[];
}
export interface GrRepoDashboards {
$: {
restAPI: RestApiService & Element;
};
}
@customElement('gr-repo-dashboards')
export class GrRepoDashboards extends GestureEventListeners(
LegacyElementMixin(PolymerElement)
@@ -56,6 +51,8 @@ export class GrRepoDashboards extends GestureEventListeners(
@property({type: Array})
_dashboards?: DashboardRef[];
private restApiService = appContext.restApiService;
_repoChanged(repo?: RepoName) {
this._loading = true;
if (!repo) {
@@ -66,7 +63,7 @@ export class GrRepoDashboards extends GestureEventListeners(
firePageError(this, response);
};
return this.$.restAPI
return this.restApiService
.getRepoDashboards(repo, errFn)
.then((res?: DashboardInfo[]) => {
if (!res) {

View File

@@ -67,5 +67,4 @@ export const htmlTemplate = html`
</template>
</tbody>
</table>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -30,7 +30,7 @@ suite('gr-repo-dashboards tests', () => {
suite('dashboard table', () => {
setup(() => {
sinon.stub(element.$.restAPI, 'getRepoDashboards').returns(
sinon.stub(element.restApiService, 'getRepoDashboards').returns(
Promise.resolve([
{
id: 'default:contributor',
@@ -124,7 +124,7 @@ suite('gr-repo-dashboards tests', () => {
test('fires page-error', done => {
const response = {status: 404};
sinon.stub(
element.$.restAPI, 'getRepoDashboards')
element.restApiService, 'getRepoDashboards')
.callsFake((repo, errFn) => {
errFn(response);
});

View File

@@ -36,10 +36,7 @@ import {htmlTemplate} from './gr-repo-detail-list_html';
import {ListViewMixin} from '../../../mixins/gr-list-view-mixin/gr-list-view-mixin';
import {encodeURL} from '../../../utils/url-util';
import {customElement, property} from '@polymer/decorators';
import {
ErrorCallback,
RestApiService,
} from '../../../services/services/gr-rest-api/gr-rest-api';
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GrOverlay} from '../../shared/gr-overlay/gr-overlay';
import {GrCreatePointerDialog} from '../gr-create-pointer-dialog/gr-create-pointer-dialog';
import {
@@ -54,12 +51,12 @@ import {AppElementRepoParams} from '../../gr-app-types';
import {PolymerDomRepeatEvent} from '../../../types/types';
import {RepoDetailView} from '../../core/gr-navigation/gr-navigation';
import {firePageError} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
const PGP_START = '-----BEGIN PGP SIGNATURE-----';
export interface GrRepoDetailList {
$: {
restAPI: RestApiService & Element;
overlay: GrOverlay;
createOverlay: GrOverlay;
createNewModal: GrCreatePointerDialog;
@@ -121,8 +118,10 @@ export class GrRepoDetailList extends ListViewMixin(
@property({type: String})
_revisedRef?: GitRef;
private readonly restApiService = appContext.restApiService;
_determineIfOwner(repo: RepoName) {
return this.$.restAPI
return this.restApiService
.getRepoAccess(repo)
.then(access => (this._isOwner = !!access && !!access[repo].is_owner));
}
@@ -187,7 +186,7 @@ export class GrRepoDetailList extends ListViewMixin(
};
if (detailType === RepoDetailView.BRANCHES) {
return this.$.restAPI
return this.restApiService
.getRepoBranches(filter, repo, itemsPerPage, offset, errFn)
.then(items => {
if (!items) {
@@ -197,7 +196,7 @@ export class GrRepoDetailList extends ListViewMixin(
this._loading = false;
});
} else if (detailType === RepoDetailView.TAGS) {
return this.$.restAPI
return this.restApiService
.getRepoTags(filter, repo, itemsPerPage, offset, errFn)
.then(items => {
if (!items) {
@@ -245,7 +244,7 @@ export class GrRepoDetailList extends ListViewMixin(
}
_getLoggedIn() {
return this.$.restAPI.getLoggedIn();
return this.restApiService.getLoggedIn();
}
_computeEditingClass(isEditing: boolean) {
@@ -273,7 +272,7 @@ export class GrRepoDetailList extends ListViewMixin(
}
_setRepoHead(repo: RepoName, ref: GitRef, e: PolymerDomRepeatEvent<GitRef>) {
return this.$.restAPI.setRepoHead(repo, ref).then(res => {
return this.restApiService.setRepoHead(repo, ref).then(res => {
if (res.status < 400) {
this._isEditing = false;
e.model.set('item.revision', ref);
@@ -305,7 +304,7 @@ export class GrRepoDetailList extends ListViewMixin(
return Promise.reject(new Error('undefined repo or refName'));
}
if (this.detailType === RepoDetailView.BRANCHES) {
return this.$.restAPI
return this.restApiService
.deleteRepoBranches(this._repo, this._refName)
.then(itemDeleted => {
if (itemDeleted.status === 204) {
@@ -319,7 +318,7 @@ export class GrRepoDetailList extends ListViewMixin(
}
});
} else if (this.detailType === RepoDetailView.TAGS) {
return this.$.restAPI
return this.restApiService
.deleteRepoTags(this._repo, this._refName)
.then(itemDeleted => {
if (itemDeleted.status === 204) {

View File

@@ -220,5 +220,4 @@ export const htmlTemplate = html`
</div>
</gr-dialog>
</gr-overlay>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -118,7 +118,7 @@ suite('gr-repo-detail-list', () => {
test('Edit HEAD button not admin', done => {
sinon.stub(element, '_getLoggedIn').returns(Promise.resolve(true));
sinon.stub(element.$.restAPI, 'getRepoAccess').returns(
sinon.stub(element.restApiService, 'getRepoAccess').returns(
Promise.resolve({
test: {is_owner: false},
}));
@@ -142,7 +142,7 @@ suite('gr-repo-detail-list', () => {
.querySelector('.revisionWithEditing');
sinon.stub(element, '_getLoggedIn').returns(Promise.resolve(true));
sinon.stub(element.$.restAPI, 'getRepoAccess').returns(
sinon.stub(element.restApiService, 'getRepoAccess').returns(
Promise.resolve({
test: {is_owner: true},
}));
@@ -219,7 +219,7 @@ suite('gr-repo-detail-list', () => {
test('_handleSaveRevision with invalid rev', done => {
const event = {model: {set: sinon.stub()}};
element._isEditing = true;
sinon.stub(element.$.restAPI, 'setRepoHead').returns(
sinon.stub(element.restApiService, 'setRepoHead').returns(
Promise.resolve({
status: 400,
})
@@ -235,7 +235,7 @@ suite('gr-repo-detail-list', () => {
test('_handleSaveRevision with valid rev', done => {
const event = {model: {set: sinon.stub()}};
element._isEditing = true;
sinon.stub(element.$.restAPI, 'setRepoHead').returns(
sinon.stub(element.restApiService, 'setRepoHead').returns(
Promise.resolve({
status: 200,
})
@@ -280,7 +280,7 @@ suite('gr-repo-detail-list', () => {
suite('filter', () => {
test('_paramsChanged', done => {
sinon.stub(
element.$.restAPI,
element.restApiService,
'getRepoBranches')
.callsFake(() => Promise.resolve(branches));
const params = {
@@ -290,13 +290,13 @@ suite('gr-repo-detail-list', () => {
offset: 25,
};
element._paramsChanged(params).then(() => {
assert.equal(element.$.restAPI.getRepoBranches.lastCall.args[0],
assert.equal(element.restApiService.getRepoBranches.lastCall.args[0],
'test');
assert.equal(element.$.restAPI.getRepoBranches.lastCall.args[1],
assert.equal(element.restApiService.getRepoBranches.lastCall.args[1],
'test');
assert.equal(element.$.restAPI.getRepoBranches.lastCall.args[2],
assert.equal(element.restApiService.getRepoBranches.lastCall.args[2],
25);
assert.equal(element.$.restAPI.getRepoBranches.lastCall.args[3],
assert.equal(element.restApiService.getRepoBranches.lastCall.args[3],
25);
done();
});
@@ -306,7 +306,7 @@ suite('gr-repo-detail-list', () => {
suite('404', () => {
test('fires page-error', done => {
const response = {status: 404};
sinon.stub(element.$.restAPI, 'getRepoBranches').callsFake(
sinon.stub(element.restApiService, 'getRepoBranches').callsFake(
(filter, repo, reposBranchesPerPage, opt_offset, errFn) => {
errFn(response);
});
@@ -458,7 +458,7 @@ suite('gr-repo-detail-list', () => {
suite('filter', () => {
test('_paramsChanged', done => {
sinon.stub(
element.$.restAPI,
element.restApiService,
'getRepoTags')
.callsFake(() => Promise.resolve(tags));
const params = {
@@ -468,13 +468,13 @@ suite('gr-repo-detail-list', () => {
offset: 25,
};
element._paramsChanged(params).then(() => {
assert.equal(element.$.restAPI.getRepoTags.lastCall.args[0],
assert.equal(element.restApiService.getRepoTags.lastCall.args[0],
'test');
assert.equal(element.$.restAPI.getRepoTags.lastCall.args[1],
assert.equal(element.restApiService.getRepoTags.lastCall.args[1],
'test');
assert.equal(element.$.restAPI.getRepoTags.lastCall.args[2],
assert.equal(element.restApiService.getRepoTags.lastCall.args[2],
25);
assert.equal(element.$.restAPI.getRepoTags.lastCall.args[3],
assert.equal(element.restApiService.getRepoTags.lastCall.args[3],
25);
done();
});
@@ -520,7 +520,7 @@ suite('gr-repo-detail-list', () => {
suite('404', () => {
test('fires page-error', done => {
const response = {status: 404};
sinon.stub(element.$.restAPI, 'getRepoTags').callsFake(
sinon.stub(element.restApiService, 'getRepoTags').callsFake(
(filter, repo, reposTagsPerPage, opt_offset, errFn) => {
errFn(response);
});

View File

@@ -29,12 +29,12 @@ import {ListViewMixin} from '../../../mixins/gr-list-view-mixin/gr-list-view-mix
import {GerritNav} from '../../core/gr-navigation/gr-navigation';
import {customElement, property, observe, computed} from '@polymer/decorators';
import {AppElementAdminParams} from '../../gr-app-types';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GrOverlay} from '../../shared/gr-overlay/gr-overlay';
import {RepoName, ProjectInfoWithName} from '../../../types/common';
import {GrCreateRepoDialog} from '../gr-create-repo-dialog/gr-create-repo-dialog';
import {ProjectState} from '../../../constants/constants';
import {fireTitleChange} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
declare global {
interface HTMLElementTagNameMap {
@@ -44,7 +44,6 @@ declare global {
export interface GrRepoList {
$: {
restAPI: RestApiService & Element;
createOverlay: GrOverlay;
createNewModal: GrCreateRepoDialog;
};
@@ -90,6 +89,8 @@ export class GrRepoList extends ListViewMixin(
return this.computeShownItems(this._repos);
}
private restApiService = appContext.restApiService;
/** @override */
attached() {
super.attached();
@@ -125,11 +126,11 @@ export class GrRepoList extends ListViewMixin(
}
_getCreateRepoCapability() {
return this.$.restAPI.getAccount().then(account => {
return this.restApiService.getAccount().then(account => {
if (!account) {
return;
}
return this.$.restAPI
return this.restApiService
.getAccountCapabilities(['createProject'])
.then(capabilities => {
if (capabilities?.createProject) {
@@ -141,18 +142,20 @@ export class GrRepoList extends ListViewMixin(
_getRepos(filter: string, reposPerPage: number, offset?: number) {
this._repos = [];
return this.$.restAPI.getRepos(filter, reposPerPage, offset).then(repos => {
// Late response.
if (filter !== this._filter || !repos) {
return;
}
this._repos = repos;
this._loading = false;
});
return this.restApiService
.getRepos(filter, reposPerPage, offset)
.then(repos => {
// Late response.
if (filter !== this._filter || !repos) {
return;
}
this._repos = repos;
this._loading = false;
});
}
_refreshReposList() {
this.$.restAPI.invalidateReposCache();
this.restApiService.invalidateReposCache();
return this._getRepos(this._filter, this._reposPerPage, this._offset);
}

View File

@@ -115,5 +115,4 @@ export const htmlTemplate = html`
</div>
</gr-dialog>
</gr-overlay>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -109,21 +109,21 @@ suite('gr-repo-list tests', () => {
});
test('_paramsChanged', done => {
sinon.stub(element.$.restAPI, 'getRepos')
sinon.stub(element.restApiService, 'getRepos')
.callsFake( () => Promise.resolve(repos));
const value = {
filter: 'test',
offset: 25,
};
element._paramsChanged(value).then(() => {
assert.isTrue(element.$.restAPI.getRepos.lastCall
assert.isTrue(element.restApiService.getRepos.lastCall
.calledWithExactly('test', 25, 25));
done();
});
});
test('latest repos requested are always set', done => {
const repoStub = sinon.stub(element.$.restAPI, 'getRepos');
const repoStub = sinon.stub(element.restApiService, 'getRepos');
repoStub.withArgs('test').returns(Promise.resolve(repos));
repoStub.withArgs('filter').returns(Promise.resolve(reposFiltered));
element._filter = 'test';

View File

@@ -31,10 +31,7 @@ import {PolymerElement} from '@polymer/polymer/polymer-element';
import {htmlTemplate} from './gr-repo_html';
import {GerritNav} from '../../core/gr-navigation/gr-navigation';
import {customElement, property, observe} from '@polymer/decorators';
import {
RestApiService,
ErrorCallback,
} from '../../../services/services/gr-rest-api/gr-rest-api';
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
import {
ConfigInfo,
RepoName,
@@ -49,6 +46,7 @@ import {ProjectState} from '../../../constants/constants';
import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
import {hasOwnProperty} from '../../../utils/common-util';
import {firePageError, fireTitleChange} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
const STATES = {
active: {value: ProjectState.ACTIVE, label: 'Active'},
@@ -84,11 +82,6 @@ const SUBMIT_TYPES = {
},
};
export interface GrRepo {
$: {
restAPI: RestApiService & Element;
};
}
@customElement('gr-repo')
export class GrRepo extends GestureEventListeners(
LegacyElementMixin(PolymerElement)
@@ -145,6 +138,8 @@ export class GrRepo extends GestureEventListeners(
@property({type: Object})
_schemesObj?: SchemesInfoMap;
private restApiService = appContext.restApiService;
/** @override */
attached() {
super.attached();
@@ -186,7 +181,7 @@ export class GrRepo extends GestureEventListeners(
if (loggedIn) {
const repo = this.repo;
if (!repo) throw new Error('undefined repo');
this.$.restAPI.getRepoAccess(repo).then(access => {
this.restApiService.getRepoAccess(repo).then(access => {
if (!access || this.repo !== repo) {
return;
}
@@ -199,7 +194,7 @@ export class GrRepo extends GestureEventListeners(
);
promises.push(
this.$.restAPI.getProjectConfig(this.repo, errFn).then(config => {
this.restApiService.getProjectConfig(this.repo, errFn).then(config => {
if (!config) {
return;
}
@@ -221,7 +216,7 @@ export class GrRepo extends GestureEventListeners(
);
promises.push(
this.$.restAPI.getConfig().then(config => {
this.restApiService.getConfig().then(config => {
if (!config) {
return;
}
@@ -245,7 +240,7 @@ export class GrRepo extends GestureEventListeners(
if (!_loggedIn) {
return;
}
this.$.restAPI.getPreferences().then(prefs => {
this.restApiService.getPreferences().then(prefs => {
if (prefs?.download_scheme) {
// Note (issue 5180): normalize the download scheme with lower-case.
this._selectedScheme = prefs.download_scheme.toLowerCase();
@@ -313,7 +308,7 @@ export class GrRepo extends GestureEventListeners(
}
_getLoggedIn() {
return this.$.restAPI.getLoggedIn();
return this.restApiService.getLoggedIn();
}
_formatRepoConfigForSave(repoConfig: ConfigInfo): ConfigInput {
@@ -346,7 +341,7 @@ export class GrRepo extends GestureEventListeners(
_handleSaveRepoConfig() {
if (!this._repoConfig || !this.repo)
return Promise.reject(new Error('undefined repoConfig or repo'));
return this.$.restAPI
return this.restApiService
.saveRepoConfig(
this.repo,
this._formatRepoConfigForSave(this._repoConfig)

View File

@@ -436,5 +436,4 @@ export const htmlTemplate = html`
</div>
</div>
</main>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -106,7 +106,7 @@ suite('gr-repo tests', () => {
});
element = basicFixture.instantiate();
repoStub = sinon.stub(
element.$.restAPI,
element.restApiService,
'getProjectConfig')
.callsFake(() => Promise.resolve(repoConf));
});
@@ -171,7 +171,7 @@ suite('gr-repo tests', () => {
element.repo = REPO;
sinon.stub(element, '_getLoggedIn').callsFake(() => Promise.resolve(true));
sinon.stub(
element.$.restAPI,
element.restApiService,
'getRepoAccess')
.callsFake(() => Promise.resolve({'test-repo': {}}));
element._loadRepo().then(() => {
@@ -247,7 +247,7 @@ suite('gr-repo tests', () => {
const response = {status: 404};
sinon.stub(
element.$.restAPI, 'getProjectConfig').callsFake((repo, errFn) => {
element.restApiService, 'getProjectConfig').callsFake((repo, errFn) => {
errFn(response);
});
element.addEventListener('page-error', e => {
@@ -264,7 +264,7 @@ suite('gr-repo tests', () => {
sinon.stub(element, '_getLoggedIn')
.callsFake(() => Promise.resolve(true));
sinon.stub(
element.$.restAPI,
element.restApiService,
'getRepoAccess')
.callsFake(() => Promise.resolve({'test-repo': {is_owner: true}}));
});
@@ -322,7 +322,7 @@ suite('gr-repo tests', () => {
enable_reviewer_by_email: 'TRUE',
};
const saveStub = sinon.stub(element.$.restAPI, 'saveRepoConfig')
const saveStub = sinon.stub(element.restApiService, 'saveRepoConfig')
.callsFake(() => Promise.resolve({}));
const button = element.root.querySelector('gr-button');

View File

@@ -156,5 +156,4 @@ export const htmlTemplate = html`
>Undo</gr-button
>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -36,12 +36,12 @@ import {
EmailAddress,
PreferencesInput,
} from '../../../types/common';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {ChangeListToggleReviewedDetail} from '../gr-change-list-item/gr-change-list-item';
import {ChangeStarToggleStarDetail} from '../../shared/gr-change-star/gr-change-star';
import {hasOwnProperty} from '../../../utils/common-util';
import {ChangeListViewState} from '../../../types/types';
import {fireTitleChange} from '../../../utils/event-util';
import {appContext} from '../../../services/app-context';
const LookupQueryPatterns = {
CHANGE_ID: /^\s*i?[0-9a-f]{7,40}\s*$/i,
@@ -57,7 +57,6 @@ const LIMIT_OPERATOR_PATTERN = /\blimit:(\d+)/i;
export interface GrChangeListView {
$: {
restAPI: RestApiService & Element;
prevArrow: HTMLAnchorElement;
nextArrow: HTMLAnchorElement;
};
@@ -113,6 +112,8 @@ export class GrChangeListView extends GestureEventListeners(
@property({type: String})
_repo: string | null = null;
private restApiService = appContext.restApiService;
/** @override */
created() {
super.created();
@@ -146,7 +147,7 @@ export class GrChangeListView extends GestureEventListeners(
// in an async so that attachment to the DOM can take place first.
this.async(() => fireTitleChange(this, this._query));
this.$.restAPI
this.restApiService
.getPreferences()
.then(prefs => {
if (!prefs) {
@@ -183,9 +184,9 @@ export class GrChangeListView extends GestureEventListeners(
}
_loadPreferences() {
return this.$.restAPI.getLoggedIn().then(loggedIn => {
return this.restApiService.getLoggedIn().then(loggedIn => {
if (loggedIn) {
this.$.restAPI.getPreferences().then(preferences => {
this.restApiService.getPreferences().then(preferences => {
this.preferences = preferences;
});
} else {
@@ -195,7 +196,7 @@ export class GrChangeListView extends GestureEventListeners(
}
_getChanges() {
return this.$.restAPI.getChanges(
return this.restApiService.getChanges(
this._changesPerPage,
this._query,
this._offset
@@ -282,11 +283,14 @@ export class GrChangeListView extends GestureEventListeners(
}
_handleToggleStar(e: CustomEvent<ChangeStarToggleStarDetail>) {
this.$.restAPI.saveChangeStarred(e.detail.change._number, e.detail.starred);
this.restApiService.saveChangeStarred(
e.detail.change._number,
e.detail.starred
);
}
_handleToggleReviewed(e: CustomEvent<ChangeListToggleReviewedDetail>) {
this.$.restAPI.saveChangeReviewed(
this.restApiService.saveChangeReviewed(
e.detail.change._number,
e.detail.reviewed
);

View File

@@ -98,5 +98,4 @@ export const htmlTemplate = html`
</a>
</nav>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -43,7 +43,6 @@ import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-end
import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader';
import {changeIsOpen, isOwner} from '../../../utils/change-util';
import {customElement, property, observe} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GrCursorManager} from '../../shared/gr-cursor-manager/gr-cursor-manager';
import {
AccountInfo,
@@ -69,7 +68,6 @@ export interface ChangeListSection {
}
export interface GrChangeList {
$: {
restAPI: RestApiService & Element;
cursor: GrCursorManager;
};
}
@@ -147,6 +145,8 @@ export class GrChangeList extends ChangeTableMixin(
flagsService = appContext.flagsService;
private restApiService = appContext.restApiService;
keyboardShortcuts() {
return {
[Shortcut.CURSOR_NEXT_CHANGE]: '_nextChange',
@@ -169,7 +169,7 @@ export class GrChangeList extends ChangeTableMixin(
/** @override */
ready() {
super.ready();
this.$.restAPI.getConfig().then(config => {
this.restApiService.getConfig().then(config => {
this._config = config;
});
}

View File

@@ -163,5 +163,4 @@ export const htmlTemplate = html`
scroll-mode="keep-visible"
focus-on-move=""
></gr-cursor-manager>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -47,7 +47,6 @@ import {
RepoName,
} from '../../../types/common';
import {AppElementDashboardParams, AppElementParams} from '../../gr-app-types';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GrDialog} from '../../shared/gr-dialog/gr-dialog';
import {GrCreateCommandsDialog} from '../gr-create-commands-dialog/gr-create-commands-dialog';
import {
@@ -64,7 +63,6 @@ const PROJECT_PLACEHOLDER_PATTERN = /\$\{project\}/g;
export interface GrDashboardView {
$: {
restAPI: RestApiService & Element;
confirmDeleteDialog: GrDialog;
commandsDialog: GrCreateCommandsDialog;
destinationDialog: GrCreateDestinationDialog;
@@ -120,6 +118,8 @@ export class GrDashboardView extends GestureEventListeners(
private reporting = appContext.reportingService;
private restApiService = appContext.restApiService;
constructor() {
super();
}
@@ -135,9 +135,9 @@ export class GrDashboardView extends GestureEventListeners(
}
_loadPreferences() {
return this.$.restAPI.getLoggedIn().then(loggedIn => {
return this.restApiService.getLoggedIn().then(loggedIn => {
if (loggedIn) {
this.$.restAPI.getPreferences().then(preferences => {
this.restApiService.getPreferences().then(preferences => {
this.preferences = preferences;
});
} else {
@@ -153,7 +153,7 @@ export class GrDashboardView extends GestureEventListeners(
const errFn = (response?: Response | null) => {
firePageError(this, response);
};
return this.$.restAPI
return this.restApiService
.getDashboard(project, dashboard, errFn)
.then(response => {
if (!response) {
@@ -206,7 +206,7 @@ export class GrDashboardView extends GestureEventListeners(
const {project, dashboard, title, user, sections} = params;
const dashboardPromise: Promise<UserDashboard | undefined> = project
? this._getProjectDashboard(project, dashboard)
: this.$.restAPI
: this.restApiService
.getConfig()
.then(config =>
Promise.resolve(
@@ -272,7 +272,7 @@ export class GrDashboardView extends GestureEventListeners(
}
}
return this.$.restAPI.getChanges(undefined, queries).then(changes => {
return this.restApiService.getChanges(undefined, queries).then(changes => {
if (!changes) {
throw new Error('getChanges returns undefined');
}
@@ -351,11 +351,14 @@ export class GrDashboardView extends GestureEventListeners(
}
_handleToggleStar(e: CustomEvent<ChangeStarToggleStarDetail>) {
this.$.restAPI.saveChangeStarred(e.detail.change._number, e.detail.starred);
this.restApiService.saveChangeStarred(
e.detail.change._number,
e.detail.starred
);
}
_handleToggleReviewed(e: CustomEvent<ChangeListToggleReviewedDetail>) {
this.$.restAPI.saveChangeReviewed(
this.restApiService.saveChangeReviewed(
e.detail.change._number,
e.detail.reviewed
);
@@ -402,7 +405,7 @@ export class GrDashboardView extends GestureEventListeners(
_handleConfirmDelete() {
this.$.confirmDeleteDialog.disabled = true;
return this.$.restAPI.deleteDraftComments('-is:open').then(() => {
return this.restApiService.deleteDraftComments('-is:open').then(() => {
this._closeConfirmDeleteOverlay();
this._reload(this.params);
});

View File

@@ -125,5 +125,4 @@ export const htmlTemplate = html`
on-confirm="_handleDestinationConfirm"
></gr-create-destination-dialog>
<gr-create-commands-dialog id="commandsDialog"></gr-create-commands-dialog>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -39,7 +39,7 @@ suite('gr-dashboard-view tests', () => {
});
element = basicFixture.instantiate();
getChangesStub = sinon.stub(element.$.restAPI, 'getChanges').callsFake(
getChangesStub = sinon.stub(element.restApiService, 'getChanges').callsFake(
(_, qs) => Promise.resolve(qs.map(() => [])));
let resolver;
@@ -124,14 +124,14 @@ suite('gr-dashboard-view tests', () => {
const deleteDraftCommentsPromise = new Promise(resolve => {
deleteDraftCommentsPromiseResolver = resolve;
});
sinon.stub(element.$.restAPI, 'deleteDraftComments')
sinon.stub(element.restApiService, 'deleteDraftComments')
.returns(deleteDraftCommentsPromise);
// Open confirmation dialog and tap confirm button.
await element.$.confirmDeleteOverlay.open();
MockInteractions.tap(element.$.confirmDeleteDialog.$.confirm);
flush();
assert.isTrue(element.$.restAPI.deleteDraftComments
assert.isTrue(element.restApiService.deleteDraftComments
.calledWithExactly('-is:open'));
assert.isTrue(element.$.confirmDeleteDialog.disabled);
assert.equal(element._reload.callCount, 0);
@@ -254,7 +254,7 @@ suite('gr-dashboard-view tests', () => {
suite('_getProjectDashboard', () => {
test('dashboard with foreach', () => {
sinon.stub(element.$.restAPI, 'getDashboard')
sinon.stub(element.restApiService, 'getDashboard')
.callsFake( () => Promise.resolve({
title: 'title',
foreach: 'foreach for ${project}',
@@ -280,7 +280,7 @@ suite('gr-dashboard-view tests', () => {
});
test('dashboard without foreach', () => {
sinon.stub(element.$.restAPI, 'getDashboard').callsFake(
sinon.stub(element.restApiService, 'getDashboard').callsFake(
() => Promise.resolve({
title: 'title',
sections: [
@@ -308,7 +308,7 @@ suite('gr-dashboard-view tests', () => {
{name: 'test2', query: 'test2', hideIfEmpty: true},
];
getChangesStub.restore();
sinon.stub(element.$.restAPI, 'getChanges')
sinon.stub(element.restApiService, 'getChanges')
.returns(Promise.resolve([[], ['nonempty']]));
return element._fetchDashboardChanges({sections}, false).then(() => {
@@ -323,7 +323,7 @@ suite('gr-dashboard-view tests', () => {
{name: 'test2', query: 'test2'},
];
getChangesStub.restore();
sinon.stub(element.$.restAPI, 'getChanges')
sinon.stub(element.restApiService, 'getChanges')
.returns(Promise.resolve([[], []]));
return element._fetchDashboardChanges({sections}, false).then(() => {
@@ -374,7 +374,7 @@ suite('gr-dashboard-view tests', () => {
test('404 page', done => {
const response = {status: 404};
sinon.stub(element.$.restAPI, 'getDashboard').callsFake(
sinon.stub(element.restApiService, 'getDashboard').callsFake(
async (project, dashboard, errFn) => {
errFn(response);
});

View File

@@ -30,5 +30,4 @@ export const htmlTemplate = html`
<hr />
<div><span>Detail:</span> <a href$="[[_repoUrl]]">Repo settings</a></div>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -28,15 +28,9 @@ import {PolymerElement} from '@polymer/polymer/polymer-element';
import {htmlTemplate} from './gr-user-header_html';
import {GerritNav} from '../../core/gr-navigation/gr-navigation';
import {customElement, property} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {AccountDetailInfo, AccountId} from '../../../types/common';
import {getDisplayName} from '../../../utils/display-name-util';
export interface GrUserHeader {
$: {
restAPI: RestApiService & Element;
};
}
import {appContext} from '../../../services/app-context';
@customElement('gr-user-header')
export class GrUserHeader extends GestureEventListeners(
@@ -61,6 +55,8 @@ export class GrUserHeader extends GestureEventListeners(
@property({type: String})
_status = '';
private restApiService = appContext.restApiService;
_accountChanged(userId?: AccountId) {
if (!userId) {
this._accountDetails = null;
@@ -68,7 +64,7 @@ export class GrUserHeader extends GestureEventListeners(
return;
}
this.$.restAPI.getAccountDetails(userId).then(details => {
this.restApiService.getAccountDetails(userId).then(details => {
this._accountDetails = details ?? null;
this._status = details?.status ?? '';
});

View File

@@ -66,5 +66,4 @@ export const htmlTemplate = html`
<a href$="[[_computeDashboardUrl(_accountDetails)]]">View dashboard</a>
</div>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -28,7 +28,7 @@ suite('gr-user-header tests', () => {
});
test('loads and clears account info', done => {
sinon.stub(element.$.restAPI, 'getAccountDetails')
sinon.stub(element.restApiService, 'getAccountDetails')
.returns(Promise.resolve({
name: 'foo',
email: 'bar',

View File

@@ -65,7 +65,6 @@ import {
ActionPriority,
ActionType,
ErrorCallback,
RestApiService,
} from '../../../services/services/gr-rest-api/gr-rest-api';
import {
ActionInfo,
@@ -323,7 +322,6 @@ interface ChangeActionDialog extends HTMLElement {
export interface GrChangeActions {
$: {
jsAPI: GrJsApiInterface;
restAPI: RestApiService & Element;
mainContent: Element;
overlay: GrOverlay;
confirmRebase: GrConfirmRebaseDialog;
@@ -549,6 +547,8 @@ export class GrChangeActions
@property({type: Object})
_config?: ServerInfo;
private restApiService = appContext.restApiService;
/** @override */
created() {
super.created();
@@ -564,7 +564,7 @@ export class GrChangeActions
ready() {
super.ready();
this.$.jsAPI.addElement(TargetElement.CHANGE_ACTIONS, this);
this.$.restAPI.getConfig().then(config => {
this.restApiService.getConfig().then(config => {
this._config = config;
});
this._handleLoadingComplete();
@@ -600,7 +600,7 @@ export class GrChangeActions
const change = this.change;
this._loading = true;
return this.$.restAPI
return this.restApiService
.getChangeRevisionActions(this.changeNum, this.latestPatchNum)
.then(revisionActions => {
if (!revisionActions) {
@@ -1086,7 +1086,7 @@ export class GrChangeActions
if (!this.changeNum) {
return;
}
this.$.restAPI
this.restApiService
.getChangeActionURL(this.changeNum, patchNum, '/' + action.__key)
.then(url => (action.__url = url));
}
@@ -1148,7 +1148,7 @@ export class GrChangeActions
/* A chromium plugin expects that the modifyRevertMsg hook will only
be called after the revert button is pressed, hence we populate the
revert dialog after revert button is pressed. */
this.$.restAPI.getChanges(0, query).then(changes => {
this.restApiService.getChanges(0, query).then(changes => {
if (!changes) {
console.error('changes is undefined');
return;
@@ -1162,7 +1162,7 @@ export class GrChangeActions
const change = this.change;
if (!change) return;
const query = `submissionid:${change.submission_id}`;
this.$.restAPI.getChanges(0, query).then(changes => {
this.restApiService.getChanges(0, query).then(changes => {
if (!changes) {
console.error('changes is undefined');
return;
@@ -1594,14 +1594,14 @@ export class GrChangeActions
if (!labels) {
return Promise.resolve(undefined);
}
return this.$.restAPI.saveChangeReview(newChangeId, CURRENT, {labels});
return this.restApiService.saveChangeReview(newChangeId, CURRENT, {labels});
}
_handleResponse(action: UIActionInfo, response?: Response) {
if (!response) {
return;
}
return this.$.restAPI.getResponseObject(response).then(obj => {
return this.restApiService.getResponseObject(response).then(obj => {
switch (action.__key) {
case ChangeActions.REVERT: {
const revertChangeInfo: ChangeInfo = (obj as unknown) as ChangeInfo;
@@ -1729,7 +1729,7 @@ export class GrChangeActions
new Error('Properties change and changeNum must be set.')
);
}
return fetchChangeUpdates(change, this.$.restAPI).then(result => {
return fetchChangeUpdates(change, this.restApiService).then(result => {
if (!result.isLatest) {
this.dispatchEvent(
new CustomEvent('show-alert', {
@@ -1760,7 +1760,7 @@ export class GrChangeActions
return Promise.resolve(undefined);
}
const patchNum = revisionAction ? this.latestPatchNum : undefined;
return this.$.restAPI
return this.restApiService
.executeChangeAction(
changeNum,
method,
@@ -1790,14 +1790,16 @@ export class GrChangeActions
ListChangesOption.MESSAGES,
ListChangesOption.ALL_REVISIONS
);
this.$.restAPI.getChanges(0, query, undefined, options).then(changes => {
if (!changes) {
console.error('getChanges returns undefined');
return;
}
this.$.confirmCherrypick.updateChanges(changes);
this._showActionDialog(this.$.confirmCherrypick);
});
this.restApiService
.getChanges(0, query, undefined, options)
.then(changes => {
if (!changes) {
console.error('getChanges returns undefined');
return;
}
this.$.confirmCherrypick.updateChanges(changes);
this._showActionDialog(this.$.confirmCherrypick);
});
}
_handleMoveTap() {
@@ -2052,7 +2054,7 @@ export class GrChangeActions
const check = () => {
attempsRemaining--;
// Pass a no-op error handler to avoid the "not found" error toast.
this.$.restAPI
this.restApiService
.getChange(changeNum, () => {})
.then(response => {
// If the response is 404, the response will be undefined.

View File

@@ -270,5 +270,4 @@ export const htmlTemplate = html`
</gr-dialog>
</gr-overlay>
<gr-js-api-interface id="jsAPI"></gr-js-api-interface>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -25,6 +25,7 @@ import {
createChangeMessages,
createRevisions,
} from '../../../test/test-data-generators.js';
import {appContext} from '../../../services/app-context.js';
const basicFixture = fixtureFromElement('gr-change-actions');
@@ -104,10 +105,8 @@ suite('gr-change-actions tests', () => {
enabled: true,
},
};
sinon.stub(element.$.confirmCherrypick.$.restAPI,
'getRepoBranches').returns(Promise.resolve([]));
sinon.stub(element.$.confirmMove.$.restAPI,
'getRepoBranches').returns(Promise.resolve([]));
sinon.stub(appContext.restApiService, 'getRepoBranches').returns(
Promise.resolve([]));
return element.reload();
});
@@ -143,14 +142,14 @@ suite('gr-change-actions tests', () => {
});
test('plugin revision actions', done => {
sinon.stub(element.$.restAPI, 'getChangeActionURL').returns(
sinon.stub(element.restApiService, 'getChangeActionURL').returns(
Promise.resolve('the-url'));
element.revisionActions = {
'plugin~action': {},
};
assert.isOk(element.revisionActions['plugin~action']);
flush(() => {
assert.isTrue(element.$.restAPI.getChangeActionURL.calledWith(
assert.isTrue(element.restApiService.getChangeActionURL.calledWith(
element.changeNum, element.latestPatchNum, '/plugin~action'));
assert.equal(element.revisionActions['plugin~action'].__url, 'the-url');
done();
@@ -158,14 +157,14 @@ suite('gr-change-actions tests', () => {
});
test('plugin change actions', async () => {
sinon.stub(element.$.restAPI, 'getChangeActionURL').returns(
sinon.stub(element.restApiService, 'getChangeActionURL').returns(
Promise.resolve('the-url'));
element.actions = {
'plugin~action': {},
};
assert.isOk(element.actions['plugin~action']);
await flush();
assert.isTrue(element.$.restAPI.getChangeActionURL.calledWith(
assert.isTrue(element.restApiService.getChangeActionURL.calledWith(
element.changeNum, undefined, '/plugin~action'));
assert.equal(element.actions['plugin~action'].__url, 'the-url');
});
@@ -273,7 +272,7 @@ suite('gr-change-actions tests', () => {
test('submit change', () => {
const showSpy = sinon.spy(element, '_showActionDialog');
sinon.stub(element.$.restAPI, 'getFromProjectLookup')
sinon.stub(element.restApiService, 'getFromProjectLookup')
.returns(Promise.resolve('test'));
sinon.stub(element.$.overlay, 'open').returns(Promise.resolve());
element.change = {
@@ -295,7 +294,7 @@ suite('gr-change-actions tests', () => {
test('submit change, tap on icon', done => {
sinon.stub(element.$.confirmSubmitDialog, 'resetFocus').callsFake( done);
sinon.stub(element.$.restAPI, 'getFromProjectLookup')
sinon.stub(element.restApiService, 'getFromProjectLookup')
.returns(Promise.resolve('test'));
sinon.stub(element.$.overlay, 'open').returns(Promise.resolve());
element.change = {
@@ -399,7 +398,7 @@ suite('gr-change-actions tests', () => {
test('rebase change fires reload event', done => {
const eventStub = sinon.stub(element, 'dispatchEvent');
sinon.stub(element.$.restAPI, 'getResponseObject').returns(
sinon.stub(element.restApiService, 'getResponseObject').returns(
Promise.resolve({}));
element._handleResponse({__key: 'rebase'}, {});
flush(() => {
@@ -429,24 +428,21 @@ suite('gr-change-actions tests', () => {
});
});
test('two dialogs are not shown at the same time', done => {
test('two dialogs are not shown at the same time', async () => {
element._hasKnownChainState = true;
flush(() => {
const rebaseButton = element.shadowRoot
.querySelector('gr-button[data-action-key="rebase"]');
assert.ok(rebaseButton);
MockInteractions.tap(rebaseButton);
flush();
assert.isFalse(element.$.confirmRebase.hidden);
sinon.stub(element.$.restAPI, 'getChanges')
.returns(Promise.resolve([]));
element._handleCherrypickTap();
flush(() => {
assert.isTrue(element.$.confirmRebase.hidden);
assert.isFalse(element.$.confirmCherrypick.hidden);
done();
});
});
await flush();
const rebaseButton = element.shadowRoot
.querySelector('gr-button[data-action-key="rebase"]');
assert.ok(rebaseButton);
MockInteractions.tap(rebaseButton);
await flush();
assert.isFalse(element.$.confirmRebase.hidden);
sinon.stub(element.restApiService, 'getChanges')
.returns(Promise.resolve([]));
element._handleCherrypickTap();
await flush();
assert.isTrue(element.$.confirmRebase.hidden);
assert.isFalse(element.$.confirmCherrypick.hidden);
});
test('fullscreen-overlay-opened hides content', () => {
@@ -473,7 +469,7 @@ suite('gr-change-actions tests', () => {
const labels = {'Foo': 1, 'Bar-Baz': -2};
const changeId = 1234;
sinon.stub(element.$.jsAPI, 'getLabelValuesPostRevert').returns(labels);
const saveStub = sinon.stub(element.$.restAPI, 'saveChangeReview')
const saveStub = sinon.stub(element.restApiService, 'saveChangeReview')
.returns(Promise.resolve());
return element._setLabelValuesOnRevert(changeId).then(() => {
assert.isTrue(saveStub.calledOnce);
@@ -748,7 +744,7 @@ suite('gr-change-actions tests', () => {
},
];
setup(done => {
sinon.stub(element.$.restAPI, 'getChanges')
sinon.stub(element.restApiService, 'getChanges')
.returns(Promise.resolve(changes));
element._handleCherrypickTap();
flush(() => {
@@ -994,7 +990,7 @@ suite('gr-change-actions tests', () => {
element.change = {
current_revision: 'abc1234',
};
sinon.stub(element.$.restAPI, 'getChanges')
sinon.stub(element.restApiService, 'getChanges')
.returns(Promise.resolve([
{change_id: '12345678901234', topic: 'T', subject: 'random'},
{change_id: '23456', topic: 'T', subject: 'a'.repeat(100)},
@@ -1019,7 +1015,7 @@ suite('gr-change-actions tests', () => {
submission_id: '199 0',
current_revision: '2000',
};
getChangesStub = sinon.stub(element.$.restAPI, 'getChanges')
getChangesStub = sinon.stub(element.restApiService, 'getChanges')
.returns(Promise.resolve([
{change_id: '12345678901234', topic: 'T', subject: 'random'},
{change_id: '23456', topic: 'T', subject: 'a'.repeat(100)},
@@ -1129,7 +1125,7 @@ suite('gr-change-actions tests', () => {
submission_id: '199',
current_revision: '2000',
};
sinon.stub(element.$.restAPI, 'getChanges')
sinon.stub(element.restApiService, 'getChanges')
.returns(Promise.resolve([
{change_id: '12345678901234', topic: 'T', subject: 'random'},
]));
@@ -1810,7 +1806,7 @@ suite('gr-change-actions tests', () => {
};
test('succeed', () => {
sinon.stub(element.$.restAPI, 'getChange')
sinon.stub(element.restApiService, 'getChange')
.callsFake( makeGetChange(5));
return element._waitForChangeReachable(123).then(success => {
assert.isTrue(success);
@@ -1818,7 +1814,7 @@ suite('gr-change-actions tests', () => {
});
test('fail', () => {
sinon.stub(element.$.restAPI, 'getChange')
sinon.stub(element.restApiService, 'getChange')
.callsFake( makeGetChange(6));
return element._waitForChangeReachable(123).then(success => {
assert.isFalse(success);
@@ -1855,16 +1851,16 @@ suite('gr-change-actions tests', () => {
suite('happy path', () => {
let sendStub;
setup(() => {
sinon.stub(element.$.restAPI, 'getChangeDetail')
sinon.stub(element.restApiService, 'getChangeDetail')
.returns(Promise.resolve({
...createChange(),
// element has latest info
revisions: createRevisions(element.latestPatchNum),
messages: createChangeMessages(1),
}));
sendStub = sinon.stub(element.$.restAPI, 'executeChangeAction')
sendStub = sinon.stub(element.restApiService, 'executeChangeAction')
.returns(Promise.resolve({}));
getResponseObjectStub = sinon.stub(element.$.restAPI,
getResponseObjectStub = sinon.stub(element.restApiService,
'getResponseObject');
sinon.stub(GerritNav,
'navigateToChange').returns(Promise.resolve(true));
@@ -1882,7 +1878,7 @@ suite('gr-change-actions tests', () => {
setup(() => {
element.change.submission_id = '199';
element.change.current_revision = '2000';
sinon.stub(element.$.restAPI, 'getChanges')
sinon.stub(element.restApiService, 'getChanges')
.returns(Promise.resolve([
{change_id: '12345678901234', topic: 'T', subject: 'random'},
{change_id: '23456', topic: 'T', subject: 'a'.repeat(100)},
@@ -1974,14 +1970,14 @@ suite('gr-change-actions tests', () => {
suite('failure modes', () => {
test('non-latest', () => {
sinon.stub(element.$.restAPI, 'getChangeDetail')
sinon.stub(element.restApiService, 'getChangeDetail')
.returns(Promise.resolve({
...createChange(),
// new patchset was uploaded
revisions: createRevisions(element.latestPatchNum + 1),
messages: createChangeMessages(1),
}));
const sendStub = sinon.stub(element.$.restAPI,
const sendStub = sinon.stub(element.restApiService,
'executeChangeAction');
return element._send('DELETE', payload, '/endpoint', true, cleanup)
@@ -1994,14 +1990,14 @@ suite('gr-change-actions tests', () => {
});
test('send fails', () => {
sinon.stub(element.$.restAPI, 'getChangeDetail')
sinon.stub(element.restApiService, 'getChangeDetail')
.returns(Promise.resolve({
...createChange(),
// element has latest info
revisions: createRevisions(element.latestPatchNum),
messages: createChangeMessages(1),
}));
const sendStub = sinon.stub(element.$.restAPI,
const sendStub = sinon.stub(element.restApiService,
'executeChangeAction').callsFake(
(num, method, patchNum, endpoint, payload, onErr) => {
onErr();
@@ -2062,10 +2058,8 @@ suite('gr-change-actions tests', () => {
element.changeNum = '42';
element.latestPatchNum = '2';
sinon.stub(element.$.confirmCherrypick.$.restAPI,
'getRepoBranches').returns(Promise.resolve([]));
sinon.stub(element.$.confirmMove.$.restAPI,
'getRepoBranches').returns(Promise.resolve([]));
sinon.stub(appContext.restApiService, 'getRepoBranches').returns(
Promise.resolve([]));
return element.reload();
});

View File

@@ -73,7 +73,6 @@ import {
TopicName,
} from '../../../types/common';
import {assertNever} from '../../../utils/common-util';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GrEditableLabel} from '../../shared/gr-editable-label/gr-editable-label';
import {GrLinkedChip} from '../../shared/gr-linked-chip/gr-linked-chip';
import {appContext} from '../../../services/app-context';
@@ -117,7 +116,6 @@ interface PushCertificateValidationInfo {
export interface GrChangeMetadata {
$: {
restAPI: RestApiService & Element;
webLinks: HTMLElement;
};
}
@@ -213,6 +211,8 @@ export class GrChangeMetadata extends GestureEventListeners(
flagsService = appContext.flagsService;
restApiService = appContext.restApiService;
/** @override */
ready() {
super.ready();
@@ -250,13 +250,13 @@ export class GrChangeMetadata extends GestureEventListeners(
return;
}
this.set(['change', 'assignee'], acct);
this.$.restAPI.setAssignee(this.change._number, acct._account_id);
this.restApiService.setAssignee(this.change._number, acct._account_id);
} else {
if (!this.change.assignee) {
return;
}
this.set(['change', 'assignee'], undefined);
this.$.restAPI.deleteAssignee(this.change._number);
this.restApiService.deleteAssignee(this.change._number);
}
}
@@ -309,7 +309,7 @@ export class GrChangeMetadata extends GestureEventListeners(
const topic = e.detail.length ? e.detail : undefined;
this._settingTopic = true;
const topicChangedForChangeNumber = this.change._number;
this.$.restAPI
this.restApiService
.setChangeTopic(topicChangedForChangeNumber, topic)
.then(newTopic => {
if (this.change?._number !== topicChangedForChangeNumber) return;
@@ -357,7 +357,7 @@ export class GrChangeMetadata extends GestureEventListeners(
}
const newHashtag = this._newHashtag;
this._newHashtag = '' as Hashtag;
this.$.restAPI
this.restApiService
.setChangeHashtag(this.change._number, {add: [newHashtag]})
.then(newHashtag => {
this.set(['change', 'hashtags'], newHashtag);
@@ -512,7 +512,7 @@ export class GrChangeMetadata extends GestureEventListeners(
}
const target = (dom(e) as EventApi).rootTarget as GrLinkedChip;
target.disabled = true;
this.$.restAPI
this.restApiService
.setChangeTopic(this.change._number)
.then(() => {
target.disabled = false;
@@ -533,7 +533,7 @@ export class GrChangeMetadata extends GestureEventListeners(
}
const target = (dom(e) as EventApi).rootTarget as GrLinkedChip;
target.disabled = true;
this.$.restAPI
this.restApiService
.setChangeHashtag(this.change._number, {remove: [target.text as Hashtag]})
.then(newHashtags => {
target.disabled = false;
@@ -677,7 +677,7 @@ export class GrChangeMetadata extends GestureEventListeners(
return undefined;
}
const provider = GrReviewerSuggestionsProvider.create(
this.$.restAPI,
this.restApiService,
change._number,
SUGGESTIONS_PROVIDERS_USERS_TYPES.ANY
);

View File

@@ -432,5 +432,4 @@ export const htmlTemplate = html`
></gr-endpoint-param>
</gr-endpoint-decorator>
</gr-external-style>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -839,8 +839,8 @@ suite('gr-change-metadata tests', () => {
let setStub: SinonStubbedMember<RestApiService['setAssignee']>;
setup(() => {
deleteStub = sinon.stub(element.$.restAPI, 'deleteAssignee');
setStub = sinon.stub(element.$.restAPI, 'setAssignee');
deleteStub = sinon.stub(element.restApiService, 'deleteAssignee');
setStub = sinon.stub(element.restApiService, 'setAssignee');
element.serverConfig = {
...createServerInfo(),
change: {
@@ -887,7 +887,7 @@ suite('gr-change-metadata tests', () => {
test('changing topic', () => {
const newTopic = 'the new topic' as TopicName;
const setChangeTopicStub = sinon
.stub(element.$.restAPI, 'setChangeTopic')
.stub(element.restApiService, 'setChangeTopic')
.returns(Promise.resolve(newTopic));
element._handleTopicChanged(new CustomEvent('test', {detail: newTopic}));
const topicChangedSpy = sinon.spy();
@@ -904,7 +904,7 @@ suite('gr-change-metadata tests', () => {
test('topic removal', () => {
const newTopic = 'the new topic' as TopicName;
const setChangeTopicStub = sinon
.stub(element.$.restAPI, 'setChangeTopic')
.stub(element.restApiService, 'setChangeTopic')
.returns(Promise.resolve(newTopic));
const chip = element.shadowRoot!.querySelector('gr-linked-chip');
const remove = chip!.$.remove;
@@ -925,7 +925,7 @@ suite('gr-change-metadata tests', () => {
element._newHashtag = 'new hashtag' as Hashtag;
const newHashtag: Hashtag[] = ['new hashtag' as Hashtag];
const setChangeHashtagStub = sinon
.stub(element.$.restAPI, 'setChangeHashtag')
.stub(element.restApiService, 'setChangeHashtag')
.returns(Promise.resolve(newHashtag));
element._handleHashtagChanged();
assert.isTrue(

View File

@@ -76,7 +76,6 @@ import {
import {changeStatuses, changeStatusString} from '../../../utils/change-util';
import {EventType as PluginEventType} from '../../plugins/gr-plugin-types';
import {customElement, property, observe} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GrJsApiInterface} from '../../shared/gr-js-api-interface/gr-js-api-interface-element';
import {GrApplyFixDialog} from '../../diff/gr-apply-fix-dialog/gr-apply-fix-dialog';
import {GrFileListHeader} from '../gr-file-list-header/gr-file-list-header';
@@ -205,7 +204,6 @@ const ROBOT_COMMENTS_LIMIT = 10;
export interface GrChangeView {
$: {
restAPI: RestApiService & Element;
jsAPI: GrJsApiInterface;
commentAPI: GrCommentApi;
applyFixDialog: GrApplyFixDialog;
@@ -538,6 +536,8 @@ export class GrChangeView extends KeyboardShortcutMixin(
_isChecksEnabled = false;
restApiService = appContext.restApiService;
keyboardShortcuts() {
return {
[Shortcut.SEND_REPLY]: null, // DOC_ONLY binding
@@ -615,7 +615,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
this._getLoggedIn().then(loggedIn => {
this._loggedIn = loggedIn;
if (loggedIn) {
this.$.restAPI.getAccount().then(acct => {
this.restApiService.getAccount().then(acct => {
this._account = acct;
});
}
@@ -847,7 +847,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
this.$.jsAPI.handleCommitMessage(this._change, message);
this.$.commitMessageEditor.disabled = true;
this.$.restAPI
this.restApiService
.putChangeCommitMessage(this._changeNum, message)
.then(resp => {
this.$.commitMessageEditor.disabled = false;
@@ -1242,7 +1242,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
}
if (value.changeNum && value.project) {
this.$.restAPI.setInProjectLookup(value.changeNum, value.project);
this.restApiService.setInProjectLookup(value.changeNum, value.project);
}
const patchChanged =
@@ -1861,16 +1861,16 @@ export class GrChangeView extends KeyboardShortcutMixin(
}
_getLoggedIn() {
return this.$.restAPI.getLoggedIn();
return this.restApiService.getLoggedIn();
}
_getServerConfig() {
return this.$.restAPI.getConfig();
return this.restApiService.getConfig();
}
_getProjectConfig() {
if (!this._change) throw new Error('missing required change property');
return this.$.restAPI
return this.restApiService
.getProjectConfig(this._change.project)
.then(config => {
this._projectConfig = config;
@@ -1878,7 +1878,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
}
_getPreferences() {
return this.$.restAPI.getPreferences();
return this.restApiService.getPreferences();
}
_prepareCommitMsgForLinkify(msg: string) {
@@ -1928,8 +1928,9 @@ export class GrChangeView extends KeyboardShortcutMixin(
_getChangeDetail() {
if (!this._changeNum)
throw new Error('missing required changeNum property');
const detailCompletes = this.$.restAPI.getChangeDetail(this._changeNum, r =>
this._handleGetChangeDetailError(r)
const detailCompletes = this.restApiService.getChangeDetail(
this._changeNum,
r => this._handleGetChangeDetailError(r)
);
const editCompletes = this._getEdit();
const prefCompletes = this._getPreferences();
@@ -2018,7 +2019,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
_getEdit() {
if (!this._changeNum)
return Promise.reject(new Error('missing required changeNum property'));
return this.$.restAPI.getChangeEdit(this._changeNum, true);
return this.restApiService.getChangeEdit(this._changeNum, true);
}
_getLatestCommitMessage() {
@@ -2027,7 +2028,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
const lastpatchNum = computeLatestPatchNum(this._allPatchSets);
if (lastpatchNum === undefined)
throw new Error('missing lastPatchNum property');
return this.$.restAPI
return this.restApiService
.getChangeCommitInfo(this._changeNum, lastpatchNum)
.then(commitInfo => {
if (!commitInfo) return;
@@ -2065,7 +2066,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
throw new Error('missing required _patchRange property');
if (this._patchRange.patchNum === undefined)
throw new Error('missing required patchNum property');
return this.$.restAPI
return this.restApiService
.getChangeCommitInfo(this._changeNum, this._patchRange.patchNum)
.then(commitInfo => {
this._commitInfo = commitInfo;
@@ -2303,11 +2304,13 @@ export class GrChangeView extends KeyboardShortcutMixin(
}
this._mergeable = null;
return this.$.restAPI.getMergeable(this._changeNum).then(mergableInfo => {
if (mergableInfo) {
this._mergeable = mergableInfo.mergeable;
}
});
return this.restApiService
.getMergeable(this._changeNum)
.then(mergableInfo => {
if (mergableInfo) {
this._mergeable = mergableInfo.mergeable;
}
});
}
_computeCanStartReview(change: ChangeInfo) {
@@ -2490,7 +2493,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
this._updateCheckTimerHandle = this.async(() => {
if (!this._change) throw new Error('missing required change property');
const change = this._change;
fetchChangeUpdates(change, this.$.restAPI).then(result => {
fetchChangeUpdates(change, this.restApiService).then(result => {
let toastMessage = null;
if (!result.isLatest) {
toastMessage = ReloadToastMessage.NEWER_REVISION;
@@ -2689,7 +2692,10 @@ export class GrChangeView extends KeyboardShortcutMixin(
}
_handleToggleStar(e: CustomEvent<{change: ChangeInfo; starred: boolean}>) {
this.$.restAPI.saveChangeStarred(e.detail.change._number, e.detail.starred);
this.restApiService.saveChangeStarred(
e.detail.change._number,
e.detail.starred
);
}
_getRevisionInfo(change: ChangeInfo | ParsedChangeInfo) {

View File

@@ -793,6 +793,5 @@ export const htmlTemplate = html`
</gr-reply-dialog>
</gr-overlay>
<gr-js-api-interface id="jsAPI"></gr-js-api-interface>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
<gr-comment-api id="commentAPI"></gr-comment-api>
`;

View File

@@ -704,7 +704,7 @@ suite('gr-change-view tests', () => {
messages: createChangeMessages(1),
};
element._change.labels = {};
sinon.stub(element.$.restAPI, 'getChangeDetail').callsFake(() =>
sinon.stub(element.restApiService, 'getChangeDetail').callsFake(() =>
Promise.resolve({
...createChange(),
// element has latest info
@@ -1474,7 +1474,7 @@ suite('gr-change-view tests', () => {
test('diffMode defaults to side by side without preferences', done => {
sinon
.stub(element.$.restAPI, 'getPreferences')
.stub(element.restApiService, 'getPreferences')
.returns(Promise.resolve(createPreferences()));
// No user prefs or diff view mode set.
@@ -1485,7 +1485,7 @@ suite('gr-change-view tests', () => {
});
test('diffMode defaults to preference when not already set', done => {
sinon.stub(element.$.restAPI, 'getPreferences').returns(
sinon.stub(element.restApiService, 'getPreferences').returns(
Promise.resolve({
...createPreferences(),
default_diff_view: DiffViewMode.UNIFIED,
@@ -1500,7 +1500,7 @@ suite('gr-change-view tests', () => {
test('existing diffMode overrides preference', done => {
element.viewState.diffMode = DiffViewMode.SIDE_BY_SIDE;
sinon.stub(element.$.restAPI, 'getPreferences').returns(
sinon.stub(element.restApiService, 'getPreferences').returns(
Promise.resolve({
...createPreferences(),
default_diff_view: DiffViewMode.UNIFIED,
@@ -1647,7 +1647,7 @@ suite('gr-change-view tests', () => {
element._change = createChange();
// Response code is 500, because we want to avoid window reloading
const putStub = sinon
.stub(element.$.restAPI, 'putChangeCommitMessage')
.stub(element.restApiService, 'putChangeCommitMessage')
.returns(Promise.resolve(new Response(null, {status: 500})));
const mockEvent = (content: string) => {
@@ -1764,7 +1764,7 @@ suite('gr-change-view tests', () => {
test('topic is coalesced to null', done => {
sinon.stub(element, '_changeChanged');
sinon.stub(element.$.restAPI, 'getChangeDetail').callsFake(() =>
sinon.stub(element.restApiService, 'getChangeDetail').callsFake(() =>
Promise.resolve({
...createChange(),
labels: {},
@@ -1781,7 +1781,7 @@ suite('gr-change-view tests', () => {
test('commit sha is populated from getChangeDetail', done => {
sinon.stub(element, '_changeChanged');
sinon.stub(element.$.restAPI, 'getChangeDetail').callsFake(() =>
sinon.stub(element.restApiService, 'getChangeDetail').callsFake(() =>
Promise.resolve({
...createChange(),
labels: {},
@@ -1799,7 +1799,7 @@ suite('gr-change-view tests', () => {
test('edit is added to change', () => {
sinon.stub(element, '_changeChanged');
const changeRevision = createRevision();
sinon.stub(element.$.restAPI, 'getChangeDetail').callsFake(() =>
sinon.stub(element.restApiService, 'getChangeDetail').callsFake(() =>
Promise.resolve({
...createChange(),
labels: {},
@@ -1957,7 +1957,7 @@ suite('gr-change-view tests', () => {
test('revert dialog opened with revert param', done => {
sinon
.stub(element.$.restAPI, 'getLoggedIn')
.stub(element.restApiService, 'getLoggedIn')
.callsFake(() => Promise.resolve(true));
const awaitPluginsLoadedStub = sinon
.stub(getPluginLoader(), 'awaitPluginsLoaded')
@@ -2034,7 +2034,7 @@ suite('gr-change-view tests', () => {
messages: createChangeMessages(1),
};
element._change.labels = {};
sinon.stub(element.$.restAPI, 'getChangeDetail').callsFake(() =>
sinon.stub(element.restApiService, 'getChangeDetail').callsFake(() =>
Promise.resolve({
...createChange(),
// element has latest info
@@ -2126,7 +2126,7 @@ suite('gr-change-view tests', () => {
messages: createChangeMessages(1),
};
element._change.labels = {};
sinon.stub(element.$.restAPI, 'getChangeDetail').callsFake(() =>
sinon.stub(element.restApiService, 'getChangeDetail').callsFake(() =>
Promise.resolve({
...createChange(),
// new patchset was uploaded
@@ -2306,7 +2306,7 @@ suite('gr-change-view tests', () => {
test('_startUpdateCheckTimer negative delay', () => {
const getChangeDetailStub = sinon
.stub(element.$.restAPI, 'getChangeDetail')
.stub(element.restApiService, 'getChangeDetail')
.callsFake(() =>
Promise.resolve({
...createChange(),
@@ -2328,7 +2328,7 @@ suite('gr-change-view tests', () => {
test('_startUpdateCheckTimer up-to-date', async () => {
const getChangeDetailStub = sinon
.stub(element.$.restAPI, 'getChangeDetail')
.stub(element.restApiService, 'getChangeDetail')
.callsFake(() =>
Promise.resolve({
...createChange(),
@@ -2351,7 +2351,7 @@ suite('gr-change-view tests', () => {
});
test('_startUpdateCheckTimer out-of-date shows an alert', done => {
sinon.stub(element.$.restAPI, 'getChangeDetail').callsFake(() =>
sinon.stub(element.restApiService, 'getChangeDetail').callsFake(() =>
Promise.resolve({
...createChange(),
// new patchset was uploaded
@@ -2374,7 +2374,7 @@ suite('gr-change-view tests', () => {
});
test('_startUpdateCheckTimer respects _loading', async () => {
sinon.stub(element.$.restAPI, 'getChangeDetail').callsFake(() =>
sinon.stub(element.restApiService, 'getChangeDetail').callsFake(() =>
Promise.resolve({
...createChange(),
// new patchset was uploaded
@@ -2396,7 +2396,7 @@ suite('gr-change-view tests', () => {
});
test('_startUpdateCheckTimer new status shows an alert', done => {
sinon.stub(element.$.restAPI, 'getChangeDetail').callsFake(() =>
sinon.stub(element.restApiService, 'getChangeDetail').callsFake(() =>
Promise.resolve({
...createChange(),
// element has latest info
@@ -2418,7 +2418,7 @@ suite('gr-change-view tests', () => {
});
test('_startUpdateCheckTimer new messages shows an alert', done => {
sinon.stub(element.$.restAPI, 'getChangeDetail').callsFake(() =>
sinon.stub(element.restApiService, 'getChangeDetail').callsFake(() =>
Promise.resolve({
...createChange(),
revisions: {rev1: createRevision()},
@@ -2660,7 +2660,7 @@ suite('gr-change-view tests', () => {
test('_selectedRevision updates when patchNum is changed', () => {
const revision1: RevisionInfo = createRevision(1);
const revision2: RevisionInfo = createRevision(2);
sinon.stub(element.$.restAPI, 'getChangeDetail').returns(
sinon.stub(element.restApiService, 'getChangeDetail').returns(
Promise.resolve({
...createChange(),
revisions: {
@@ -2689,7 +2689,7 @@ suite('gr-change-view tests', () => {
const revision1 = createRevision(1);
const revision2 = createRevision(2);
const revision3 = createEditRevision();
sinon.stub(element.$.restAPI, 'getChangeDetail').returns(
sinon.stub(element.restApiService, 'getChangeDetail').returns(
Promise.resolve({
...createChange(),
revisions: {
@@ -2839,7 +2839,7 @@ suite('gr-change-view tests', () => {
setup(() => {
element._change = {...createChange(), labels: {}};
getMergeableStub = sinon
.stub(element.$.restAPI, 'getMergeable')
.stub(element.restApiService, 'getMergeable')
.returns(Promise.resolve({...createMergeable(), mergeable: true}));
});
@@ -2873,7 +2873,7 @@ suite('gr-change-view tests', () => {
test('_paramsChanged sets in projectLookup', () => {
sinon.stub(element.$.relatedChanges, 'reload');
sinon.stub(element, '_reload').returns(Promise.resolve([]));
const setStub = sinon.stub(element.$.restAPI, 'setInProjectLookup');
const setStub = sinon.stub(element.restApiService, 'setInProjectLookup');
element._paramsChanged({
view: GerritNav.View.CHANGE,
changeNum: 101 as NumericChangeId,

View File

@@ -35,7 +35,6 @@ import {
} from '../../../types/common';
import {ReportingService} from '../../../services/gr-reporting/gr-reporting';
import {customElement, property, observe} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {
GrAutocomplete,
AutocompleteSuggestion,
@@ -68,7 +67,6 @@ declare global {
// is converted
export interface GrConfirmCherrypickDialog {
$: {
restAPI: RestApiService & Element;
branchInput: GrAutocomplete;
};
}
@@ -142,6 +140,8 @@ export class GrConfirmCherrypickDialog extends GestureEventListeners(
@property({type: Object})
reporting: ReportingService;
private restApiService = appContext.restApiService;
constructor() {
super();
this._statuses = {};
@@ -301,7 +301,7 @@ export class GrConfirmCherrypickDialog extends GestureEventListeners(
};
// revisions and current_revision must exist hence casting
const patchNum = change.revisions![change.current_revision!]._number;
this.$.restAPI
this.restApiService
.executeChangeAction(
change._number,
HttpMethod.POST,
@@ -366,7 +366,7 @@ export class GrConfirmCherrypickDialog extends GestureEventListeners(
if (input.startsWith('refs/heads/')) {
input = input.substring('refs/heads/'.length);
}
return this.$.restAPI
return this.restApiService
.getRepoBranches(input, this.project, SUGGESTIONS_LIMIT)
.then((response: BranchInfo[] | undefined) => {
const branches = [];

View File

@@ -212,5 +212,4 @@ export const htmlTemplate = html`
</template>
</div>
</gr-dialog>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -113,7 +113,7 @@ suite('gr-confirm-cherrypick-dialog tests', () => {
test('cherry pick topic submit', done => {
element.branch = 'master';
const executeChangeActionStub = sinon.stub(element.$.restAPI,
const executeChangeActionStub = sinon.stub(element.restApiService,
'executeChangeAction').returns(Promise.resolve([]));
MockInteractions.tap(element.shadowRoot.
querySelector('gr-dialog').$.confirm);

View File

@@ -24,17 +24,12 @@ import {PolymerElement} from '@polymer/polymer/polymer-element';
import {htmlTemplate} from './gr-confirm-move-dialog_html';
import {KeyboardShortcutMixin} from '../../../mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin';
import {customElement, property} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {RepoName, BranchName} from '../../../types/common';
import {AutocompleteSuggestion} from '../../shared/gr-autocomplete/gr-autocomplete';
import {appContext} from '../../../services/app-context';
const SUGGESTIONS_LIMIT = 15;
export interface GrConfirmMoveDialog {
$: {
restAPI: RestApiService & Element;
};
}
@customElement('gr-confirm-move-dialog')
export class GrConfirmMoveDialog extends KeyboardShortcutMixin(
GestureEventListeners(LegacyElementMixin(PolymerElement))
@@ -73,6 +68,8 @@ export class GrConfirmMoveDialog extends KeyboardShortcutMixin(
};
}
private restApiService = appContext.restApiService;
constructor() {
super();
this._query = () => this._getProjectBranchesSuggestions();
@@ -108,7 +105,7 @@ export class GrConfirmMoveDialog extends KeyboardShortcutMixin(
if (input.startsWith('refs/heads/')) {
input = input.substring('refs/heads/'.length);
}
return this.$.restAPI
return this.restApiService
.getRepoBranches(input, this.project, SUGGESTIONS_LIMIT)
.then(response => {
const branches: AutocompleteSuggestion[] = [];

View File

@@ -79,5 +79,4 @@ export const htmlTemplate = html`
></iron-autogrow-textarea>
</div>
</gr-dialog>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -30,7 +30,7 @@ import {
AutocompleteQuery,
AutocompleteSuggestion,
} from '../../shared/gr-autocomplete/gr-autocomplete';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {appContext} from '../../../services/app-context';
interface RebaseChange {
name: string;
@@ -43,7 +43,6 @@ export interface ConfirmRebaseEventDetail {
export interface GrConfirmRebaseDialog {
$: {
restAPI: RestApiService & Element;
parentInput: GrAutocomplete;
rebaseOnParentInput: HTMLInputElement;
rebaseOnOtherInput: HTMLInputElement;
@@ -92,6 +91,8 @@ export class GrConfirmRebaseDialog extends GestureEventListeners(
@property({type: Array})
_recentChanges?: RebaseChange[];
private restApiService = appContext.restApiService;
constructor() {
super();
this._query = input => this._getChangeSuggestions(input);
@@ -104,7 +105,7 @@ export class GrConfirmRebaseDialog extends GestureEventListeners(
// in case there are new/updated changes in the generic query since the
// last time it was run.
fetchRecentChanges() {
return this.$.restAPI
return this.restApiService
.getChanges(undefined, 'is:open -age:90d')
.then(response => {
if (!response) return [];

View File

@@ -127,5 +127,4 @@ export const htmlTemplate = html`
</div>
</div>
</gr-dialog>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -118,7 +118,7 @@ suite('gr-confirm-rebase-dialog tests', () => {
},
];
sinon.stub(element.$.restAPI, 'getChanges').returns(Promise.resolve(
sinon.stub(element.restApiService, 'getChanges').returns(Promise.resolve(
[
{
_number: 123,
@@ -141,13 +141,13 @@ suite('gr-confirm-rebase-dialog tests', () => {
return element._getRecentChanges()
.then(() => {
assert.deepEqual(element._recentChanges, recentChanges);
assert.equal(element.$.restAPI.getChanges.callCount, 1);
assert.equal(element.restApiService.getChanges.callCount, 1);
// When called a second time, should not re-request recent changes.
element._getRecentChanges();
})
.then(() => {
assert.equal(element._getRecentChanges.callCount, 2);
assert.equal(element.$.restAPI.getChanges.callCount, 1);
assert.equal(element.restApiService.getChanges.callCount, 1);
});
});

View File

@@ -81,5 +81,4 @@ export const htmlTemplate = html`
</gr-endpoint-decorator>
</div>
</gr-dialog>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -53,8 +53,8 @@ import {DiffPreferencesInfo} from '../../../types/diff';
import {ChangeComments} from '../../diff/gr-comment-api/gr-comment-api';
import {GrDiffModeSelector} from '../../diff/gr-diff-mode-selector/gr-diff-mode-selector';
import {DiffViewMode} from '../../../constants/constants';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GrButton} from '../../shared/gr-button/gr-button';
import {appContext} from '../../../services/app-context';
// Maximum length for patch set descriptions.
const PATCH_DESC_MAX_LENGTH = 500;
@@ -69,7 +69,6 @@ declare global {
export interface GrFileListHeader {
$: {
modeSelect: GrDiffModeSelector;
restAPI: RestApiService & Element;
expandBtn: GrButton;
collapseBtn: GrButton;
};
@@ -169,6 +168,8 @@ export class GrFileListHeader extends KeyboardShortcutMixin(
@property({type: Object})
revisionInfo?: RevisionInfo;
private readonly restApiService = appContext.restApiService;
@computed('loggedIn', 'change', 'account')
get _descriptionReadOnly(): boolean {
if (
@@ -294,7 +295,7 @@ export class GrFileListHeader extends KeyboardShortcutMixin(
this.patchNum
)!;
const sha = this._getPatchsetHash(this.change.revisions, rev);
return this.$.restAPI
return this.restApiService
.setDescription(this.changeNum, this.patchNum, desc)
.then((res: Response) => {
if (res.ok) {

View File

@@ -273,5 +273,4 @@ export const htmlTemplate = html`
</div>
</div>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -86,7 +86,7 @@ suite('gr-file-list-header tests', () => {
});
test('description editing', () => {
const putDescStub = sinon.stub(element.$.restAPI, 'setDescription')
const putDescStub = sinon.stub(element.restApiService, 'setDescription')
.returns(Promise.resolve({ok: true}));
element.changeNum = '42';

View File

@@ -54,7 +54,6 @@ import {
specialFilePathCompare,
} from '../../../utils/path-list-util';
import {customElement, observe, property} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {
ConfigInfo,
ElementPropertyDeepChange,
@@ -107,7 +106,6 @@ const FILE_ROW_CLASS = 'file-row';
export interface GrFileList {
$: {
restAPI: RestApiService & Element;
diffPreferencesDialog: GrDiffPreferencesDialog;
diffCursor: GrDiffCursor;
fileCursor: GrCursorManager;
@@ -334,6 +332,8 @@ export class GrFileList extends KeyboardShortcutMixin(
private readonly reporting = appContext.reportingService;
private readonly restApiService = appContext.restApiService;
get keyBindings() {
return {
esc: '_handleEscKey',
@@ -457,7 +457,7 @@ export class GrFileList extends KeyboardShortcutMixin(
const promises = [];
promises.push(
this.$.restAPI
this.restApiService
.getChangeOrEditFiles(changeNum, patchRange)
.then(filesByPath => {
this._filesByPath = filesByPath;
@@ -544,11 +544,11 @@ export class GrFileList extends KeyboardShortcutMixin(
}
_getDiffPreferences() {
return this.$.restAPI.getDiffPreferences();
return this.restApiService.getDiffPreferences();
}
_getPreferences() {
return this.$.restAPI.getPreferences();
return this.restApiService.getPreferences();
}
private _toggleFileExpanded(file: PatchSetFile) {
@@ -765,7 +765,7 @@ export class GrFileList extends KeyboardShortcutMixin(
throw new Error('changeNum and patchRange must be set');
}
return this.$.restAPI.saveFileReviewed(
return this.restApiService.saveFileReviewed(
this.changeNum,
this.patchRange.patchNum,
path,
@@ -774,14 +774,14 @@ export class GrFileList extends KeyboardShortcutMixin(
}
_getLoggedIn() {
return this.$.restAPI.getLoggedIn();
return this.restApiService.getLoggedIn();
}
_getReviewedFiles(changeNum: NumericChangeId, patchRange: PatchRange) {
if (this.editMode) {
return Promise.resolve([]);
}
return this.$.restAPI.getReviewedFiles(changeNum, patchRange.patchNum);
return this.restApiService.getReviewedFiles(changeNum, patchRange.patchNum);
}
_normalizeChangeFilesResponse(

View File

@@ -763,7 +763,6 @@ export const htmlTemplate = html`
on-reload-diff-preference="_handleReloadingDiffPreference"
>
</gr-diff-preferences-dialog>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
<gr-storage id="storage"></gr-storage>
<gr-diff-cursor id="diffCursor"></gr-diff-cursor>
<gr-cursor-manager

View File

@@ -1837,7 +1837,7 @@ suite('gr-file-list tests', () => {
});
test('_getReviewedFiles does not call API', () => {
const apiSpy = sinon.spy(element.$.restAPI, 'getReviewedFiles');
const apiSpy = sinon.spy(element.restApiService, 'getReviewedFiles');
element.editMode = true;
return element._getReviewedFiles().then(files => {
assert.equal(files.length, 0);

View File

@@ -24,13 +24,7 @@ import {PolymerElement} from '@polymer/polymer/polymer-element';
import {htmlTemplate} from './gr-included-in-dialog_html';
import {customElement, property} from '@polymer/decorators';
import {IncludedInInfo, NumericChangeId} from '../../../types/common';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
export interface GrIncludedInDialog {
$: {
restAPI: RestApiService & Element;
};
}
import {appContext} from '../../../services/app-context';
interface DisplayGroup {
title: string;
@@ -63,18 +57,22 @@ export class GrIncludedInDialog extends GestureEventListeners(
@property({type: String})
_filterText = '';
private readonly restApiService = appContext.restApiService;
loadData() {
if (!this.changeNum) {
return Promise.reject(new Error('missing required property changeNum'));
}
this._filterText = '';
return this.$.restAPI.getChangeIncludedIn(this.changeNum).then(configs => {
if (!configs) {
return;
}
this._includedIn = configs;
this._loaded = true;
});
return this.restApiService
.getChangeIncludedIn(this.changeNum)
.then(configs => {
if (!configs) {
return;
}
this._includedIn = configs;
this._loaded = true;
});
}
_resetData() {

View File

@@ -100,5 +100,4 @@ export const htmlTemplate = html`
</ul>
</div>
</template>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -41,9 +41,9 @@ import {
NumericChangeId,
ChangeMessageId,
} from '../../../types/common';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {CommentThread} from '../../../utils/comment-util';
import {hasOwnProperty} from '../../../utils/common-util';
import {appContext} from '../../../services/app-context';
const PATCH_SET_PREFIX_PATTERN = /^(?:Uploaded\s*)?(?:P|p)atch (?:S|s)et \d+:\s*(.*)/;
const LABEL_TITLE_SCORE_PATTERN = /^(-?)([A-Za-z0-9-]+?)([+-]\d+)?[.]?$/;
@@ -58,12 +58,6 @@ export interface MessageAnchorTapDetail {
id: ChangeMessageId;
}
export interface GrMessage {
$: {
restAPI: RestApiService & Element;
};
}
interface ChangeMessage extends ChangeMessageInfo {
// TODO(TS): maybe should be an enum instead
type: string;
@@ -192,6 +186,8 @@ export class GrMessage extends GestureEventListeners(
})
_commentCountText = '';
private readonly restApiService = appContext.restApiService;
created() {
super.created();
this.addEventListener('click', e => this._handleClick(e));
@@ -199,13 +195,13 @@ export class GrMessage extends GestureEventListeners(
attached() {
super.attached();
this.$.restAPI.getConfig().then(config => {
this.restApiService.getConfig().then(config => {
this.config = config;
});
this.$.restAPI.getLoggedIn().then(loggedIn => {
this.restApiService.getLoggedIn().then(loggedIn => {
this._loggedIn = loggedIn;
});
this.$.restAPI.getIsAdmin().then(isAdmin => {
this.restApiService.getIsAdmin().then(isAdmin => {
this._isAdmin = !!isAdmin;
});
}
@@ -472,7 +468,7 @@ export class GrMessage extends GestureEventListeners(
e.preventDefault();
if (!this.message || !this.message.id || !this.changeNum) return;
this._isDeletingChangeMsg = true;
this.$.restAPI
this.restApiService
.deleteChangeCommitMessage(this.changeNum, this.message.id)
.then(() => {
this._isDeletingChangeMsg = false;
@@ -488,7 +484,7 @@ export class GrMessage extends GestureEventListeners(
@observe('projectName')
_projectNameChanged(name: string) {
this.$.restAPI.getProjectConfig(name as RepoName).then(config => {
this.restApiService.getProjectConfig(name as RepoName).then(config => {
this._projectConfig = config;
});
}

View File

@@ -306,5 +306,4 @@ export const htmlTemplate = html`
</span>
</div>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -30,7 +30,6 @@ import {patchNumEquals} from '../../../utils/patch-set-util';
import {changeIsOpen} from '../../../utils/change-util';
import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints';
import {customElement, observe, property} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {
ChangeId,
ChangeInfo,
@@ -43,12 +42,7 @@ import {
SubmittedTogetherInfo,
} from '../../../types/common';
import {ParsedChangeInfo} from '../../shared/gr-rest-api-interface/gr-reviewer-updates-parser';
export interface GrRelatedChangesList {
$: {
restAPI: RestApiService & Element;
};
}
import {appContext} from '../../../services/app-context';
function getEmptySubmitTogetherInfo(): SubmittedTogetherInfo {
return {changes: [], non_visible_changes: 0};
@@ -117,6 +111,8 @@ export class GrRelatedChangesList extends GestureEventListeners(
@property({type: Array})
_sameTopic?: ChangeInfo[] = [];
private readonly restApiService = appContext.restApiService;
clear() {
this.loading = true;
this.hidden = true;
@@ -135,7 +131,7 @@ export class GrRelatedChangesList extends GestureEventListeners(
const change = this.change;
this.loading = true;
const promises: Array<Promise<void>> = [
this.$.restAPI
this.restApiService
.getRelatedChanges(change._number, this.patchNum)
.then(response => {
if (!response) {
@@ -148,13 +144,13 @@ export class GrRelatedChangesList extends GestureEventListeners(
response.changes
);
}),
this.$.restAPI
this.restApiService
.getChangesSubmittedTogether(change._number)
.then(response => {
this._submittedTogether = response;
this._fireReloadEvent();
}),
this.$.restAPI
this.restApiService
.getChangeCherryPicks(change.project, change.change_id, change._number)
.then(response => {
this._cherryPicks = response || [];
@@ -165,12 +161,14 @@ export class GrRelatedChangesList extends GestureEventListeners(
// Get conflicts if change is open and is mergeable.
if (changeIsOpen(change) && this.mergeable) {
promises.push(
this.$.restAPI.getChangeConflicts(change._number).then(response => {
// Because the server doesn't always return a response and the
// template expects an array, always return an array.
this._conflicts = response ? response : [];
this._fireReloadEvent();
})
this.restApiService
.getChangeConflicts(change._number)
.then(response => {
// Because the server doesn't always return a response and the
// template expects an array, always return an array.
this._conflicts = response ? response : [];
this._fireReloadEvent();
})
);
}
@@ -181,7 +179,7 @@ export class GrRelatedChangesList extends GestureEventListeners(
throw new Error('_getServerConfig returned undefined ');
}
if (!config.change.submit_whole_topic) {
return this.$.restAPI
return this.restApiService
.getChangesWithSameTopic(change.topic, change._number)
.then(response => {
this._sameTopic = response;
@@ -222,7 +220,7 @@ export class GrRelatedChangesList extends GestureEventListeners(
}
_getServerConfig() {
return this.$.restAPI.getConfig();
return this.restApiService.getConfig();
}
_computeChangeURL(

View File

@@ -214,5 +214,4 @@ export const htmlTemplate = html`
</gr-endpoint-decorator>
</div>
<div hidden$="[[!loading]]">Loading...</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
`;

View File

@@ -237,13 +237,13 @@ suite('gr-related-changes-list tests', () => {
};
element.mergeable = true;
element.addEventListener('new-section-loaded', loadedStub);
sinon.stub(element.$.restAPI, 'getRelatedChanges')
sinon.stub(element.restApiService, 'getRelatedChanges')
.returns(Promise.resolve({changes: []}));
sinon.stub(element.$.restAPI, 'getChangesSubmittedTogether')
sinon.stub(element.restApiService, 'getChangesSubmittedTogether')
.returns(Promise.resolve());
sinon.stub(element.$.restAPI, 'getChangeCherryPicks')
sinon.stub(element.restApiService, 'getChangeCherryPicks')
.returns(Promise.resolve());
sinon.stub(element.$.restAPI, 'getChangeConflicts')
sinon.stub(element.restApiService, 'getChangeConflicts')
.returns(Promise.resolve());
return element.reload().then(() => {
@@ -257,13 +257,13 @@ suite('gr-related-changes-list tests', () => {
setup(() => {
element = basicFixture.instantiate();
sinon.stub(element.$.restAPI, 'getRelatedChanges')
sinon.stub(element.restApiService, 'getRelatedChanges')
.returns(Promise.resolve({changes: []}));
sinon.stub(element.$.restAPI, 'getChangesSubmittedTogether')
sinon.stub(element.restApiService, 'getChangesSubmittedTogether')
.returns(Promise.resolve());
sinon.stub(element.$.restAPI, 'getChangeCherryPicks')
sinon.stub(element.restApiService, 'getChangeCherryPicks')
.returns(Promise.resolve());
sinon.stub(element.$.restAPI, 'getChangeConflicts')
sinon.stub(element.restApiService, 'getChangeConflicts')
.returns(Promise.resolve());
});
@@ -286,13 +286,13 @@ suite('gr-related-changes-list tests', () => {
setup(() => {
element = basicFixture.instantiate();
sinon.stub(element.$.restAPI, 'getRelatedChanges')
sinon.stub(element.restApiService, 'getRelatedChanges')
.returns(Promise.resolve({changes: []}));
sinon.stub(element.$.restAPI, 'getChangesSubmittedTogether')
sinon.stub(element.restApiService, 'getChangesSubmittedTogether')
.returns(Promise.resolve());
sinon.stub(element.$.restAPI, 'getChangeCherryPicks')
sinon.stub(element.restApiService, 'getChangeCherryPicks')
.returns(Promise.resolve());
conflictsStub = sinon.stub(element.$.restAPI, 'getChangeConflicts')
conflictsStub = sinon.stub(element.restApiService, 'getChangeConflicts')
.returns(Promise.resolve());
});

View File

@@ -51,10 +51,7 @@ import {getDisplayName} from '../../../utils/display-name-util';
import {IronA11yAnnouncer} from '@polymer/iron-a11y-announcer/iron-a11y-announcer';
import {TargetElement} from '../../plugins/gr-plugin-types';
import {customElement, observe, property} from '@polymer/decorators';
import {
ErrorCallback,
RestApiService,
} from '../../../services/services/gr-rest-api/gr-rest-api';
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
import {FixIronA11yAnnouncer} from '../../../types/types';
import {
AccountAddition,
@@ -158,7 +155,6 @@ const PENDING_REMOVAL_KEYS: (keyof PendingRemovals)[] = [
export interface GrReplyDialog {
$: {
restAPI: RestApiService & Element;
jsAPI: JsApiService & Element;
reviewers: GrAccountList;
ccs: GrAccountList;
@@ -374,6 +370,8 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
@property({type: Array, computed: '_computeAllReviewers(_reviewers.*)'})
_allReviewers: (AccountInfo | GroupInfo)[] = [];
private readonly restApiService = appContext.restApiService;
get keyBindings() {
return {
esc: '_handleEscKey',
@@ -431,7 +429,7 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
open(focusTarget?: FocusTarget) {
if (!this.change) throw new Error('missing required change property');
this.knownLatestState = LatestPatchState.CHECKING;
fetchChangeUpdates(this.change, this.$.restAPI).then(result => {
fetchChangeUpdates(this.change, this.restApiService).then(result => {
this.knownLatestState = result.isLatest
? LatestPatchState.LATEST
: LatestPatchState.NOT_LATEST;
@@ -446,9 +444,9 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
// Otherwise, check for an unsaved draft in localstorage.
this.draft = this._loadStoredDraft();
}
if (this.$.restAPI.hasPendingDiffDrafts()) {
if (this.restApiService.hasPendingDiffDrafts()) {
this._savingComments = true;
this.$.restAPI.awaitPendingDiffDrafts().then(() => {
this.restApiService.awaitPendingDiffDrafts().then(() => {
this.dispatchEvent(
new CustomEvent('comment-refresh', {
composed: true,
@@ -611,7 +609,7 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
return;
}
return this.$.restAPI
return this.restApiService
.removeChangeReviewer(this.change._number, accountKey(account))
.then((response?: Response) => {
if (!response?.ok || !this.change) return;
@@ -811,7 +809,7 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
// Using response.clone() here, because getResponseObject() and
// potentially the generic error handler will want to call text() on the
// response object, which can only be done once per object.
const jsonPromise = this.$.restAPI.getResponseObject(response.clone());
const jsonPromise = this.restApiService.getResponseObject(response.clone());
return jsonPromise.then((parsed: ParsedJSON) => {
const result = parsed as ReviewResult;
// Only perform custom error handling for 400s and a parseable
@@ -1224,7 +1222,7 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
}
_getAccount() {
return this.$.restAPI.getAccount();
return this.restApiService.getAccount();
}
_cancelTapHandler(e: Event) {
@@ -1291,7 +1289,7 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
_saveReview(review: ReviewInput, errFn?: ErrorCallback) {
if (!this.change) throw new Error('missing required change property');
if (!this.patchNum) throw new Error('missing required patchNum property');
return this.$.restAPI.saveChangeReview(
return this.restApiService.saveChangeReview(
this.change._number,
this.patchNum,
review,
@@ -1467,7 +1465,7 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
_getReviewerSuggestionsProvider(change: ChangeInfo) {
const provider = GrReviewerSuggestionsProvider.create(
this.$.restAPI,
this.restApiService,
change._number,
SUGGESTIONS_PROVIDERS_USERS_TYPES.REVIEWER
);
@@ -1477,7 +1475,7 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
_getCcSuggestionsProvider(change: ChangeInfo) {
const provider = GrReviewerSuggestionsProvider.create(
this.$.restAPI,
this.restApiService,
change._number,
SUGGESTIONS_PROVIDERS_USERS_TYPES.CC
);

View File

@@ -617,6 +617,5 @@ export const htmlTemplate = html`
</div>
</div>
<gr-js-api-interface id="jsAPI"></gr-js-api-interface>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
<gr-storage id="storage"></gr-storage>
`;

View File

@@ -131,7 +131,7 @@ suite('gr-reply-dialog tests', () => {
try {
const result = jsonResponseProducer(review) || {};
const resultStr =
element.$.restAPI.JSON_PREFIX + JSON.stringify(result);
element.restApiService.JSON_PREFIX + JSON.stringify(result);
resolve({
ok: true,
text() {
@@ -977,7 +977,7 @@ suite('gr-reply-dialog tests', () => {
});
test('_removeAccount', done => {
sinon.stub(element.$.restAPI, 'removeChangeReviewer')
sinon.stub(element.restApiService, 'removeChangeReviewer')
.returns(Promise.resolve({ok: true}));
const arr = [makeAccount(), makeAccount()];
element.change.reviewers = {
@@ -1283,7 +1283,7 @@ suite('gr-reply-dialog tests', () => {
setup(() => {
startReviewStub = sinon.stub(
element.$.restAPI,
element.restApiService,
'startReview')
.callsFake(() => Promise.resolve());
});
@@ -1371,8 +1371,9 @@ suite('gr-reply-dialog tests', () => {
const refreshHandler = sinon.stub();
element.addEventListener('comment-refresh', refreshHandler);
sinon.stub(element.$.restAPI, 'hasPendingDiffDrafts').returns(true);
element.$.restAPI._pendingRequests.sendDiffDraft = [promise];
sinon.stub(element.restApiService, 'hasPendingDiffDrafts').returns(
true);
element.restApiService._pendingRequests.sendDiffDraft = [promise];
element.open();
assert.isFalse(refreshHandler.called);
@@ -1380,14 +1381,15 @@ suite('gr-reply-dialog tests', () => {
promise.resolve();
return element.$.restAPI.awaitPendingDiffDrafts().then(() => {
return element.restApiService.awaitPendingDiffDrafts().then(() => {
assert.isTrue(refreshHandler.called);
assert.isFalse(element._savingComments);
});
});
test('no', () => {
sinon.stub(element.$.restAPI, 'hasPendingDiffDrafts').returns(false);
sinon.stub(element.restApiService, 'hasPendingDiffDrafts').returns(
false);
element.open();
assert.notOk(element._savingComments);
});

View File

@@ -39,16 +39,10 @@ import {
} from '../../../types/common';
import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
import {GrAccountChip} from '../../shared/gr-account-chip/gr-account-chip';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {hasOwnProperty} from '../../../utils/common-util';
import {isRemovableReviewer} from '../../../utils/change-util';
import {ReviewerState} from '../../../constants/constants';
export interface GrReviewerList {
$: {
restAPI: RestApiService & Element;
};
}
import {appContext} from '../../../services/app-context';
@customElement('gr-reviewer-list')
export class GrReviewerList extends GestureEventListeners(
@@ -94,6 +88,8 @@ export class GrReviewerList extends GestureEventListeners(
@property({type: Object})
_xhrPromise?: Promise<Response | undefined>;
private readonly restApiService = appContext.restApiService;
@computed('ccsOnly')
get _addLabel() {
return this.ccsOnly ? 'Add CC' : 'Add reviewer';
@@ -323,6 +319,6 @@ export class GrReviewerList extends GestureEventListeners(
_removeReviewer(id: AccountId | EmailAddress): Promise<Response | undefined> {
if (!this.change) return Promise.resolve(undefined);
return this.$.restAPI.removeChangeReviewer(this.change._number, id);
return this.restApiService.removeChangeReviewer(this.change._number, id);
}
}

Some files were not shown because too many files have changed in this diff Show More