Skip to content

Commit d77a8fd

Browse files
committed
style: lint code api files
1 parent ab33bb4 commit d77a8fd

13 files changed

Lines changed: 297 additions & 287 deletions

dprint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"typescript": {
3+
"quoteStyle": "alwaysSingle"
34
},
45
"json": {
56
},

packages/code-api/src/atomgit/atomgit.service.ts

Lines changed: 88 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1+
import { request, RequestOptions } from '@codeblitzjs/ide-common';
12
import { Autowired, Injectable } from '@opensumi/di';
3+
import { isObject, MessageType, URI } from '@opensumi/ide-core-common';
4+
import { CODE_PLATFORM_CONFIG, HelperService } from '../common';
25
import {
3-
TreeEntry,
4-
EntryParam,
5-
ICodeAPIService,
6-
IRepositoryModel,
7-
BranchOrTag,
8-
CommitParams,
96
Branch,
10-
Project,
7+
BranchOrTag,
8+
CodePlatform,
119
CommitFileChange,
10+
CommitParams,
1211
CommitRecord,
12+
EntryInfo,
13+
EntryParam,
1314
FileAction,
1415
FileActionHeader,
15-
ISearchResults,
16-
CodePlatform,
1716
GitlensBlame,
18-
EntryInfo,
17+
ICodeAPIService,
18+
IRepositoryModel,
19+
ISearchResults,
20+
Project,
21+
TreeEntry,
1922
} from '../common/types';
20-
import { request, RequestOptions } from '@codeblitzjs/ide-common';
21-
import { CODE_PLATFORM_CONFIG, HelperService } from '../common';
22-
import { URI, MessageType, isObject } from '@opensumi/ide-core-common';
2323
import { CodeAPI as ConflictAPI } from '../common/types';
2424
import { API } from './types';
2525

@@ -36,7 +36,7 @@ export class AtomGitAPIService implements ICodeAPIService {
3636
if (!this._PRIVATE_TOKEN) {
3737
this._PRIVATE_TOKEN = this.helper.ATOMGIT_TOKEN;
3838
return this._PRIVATE_TOKEN;
39-
};
39+
}
4040

4141
return this._PRIVATE_TOKEN;
4242
}
@@ -50,16 +50,22 @@ export class AtomGitAPIService implements ICodeAPIService {
5050
getBranchNames?(repo: IRepositoryModel): Promise<string[]> {
5151
throw new Error('Method not implemented.');
5252
}
53-
createPullRequest(repo: IRepositoryModel, sourceBranch: string, targetBranch: string, title: string, autoMerge?: boolean | undefined): Promise<ConflictAPI.ResponseCreatePR> {
53+
createPullRequest(
54+
repo: IRepositoryModel,
55+
sourceBranch: string,
56+
targetBranch: string,
57+
title: string,
58+
autoMerge?: boolean | undefined,
59+
): Promise<ConflictAPI.ResponseCreatePR> {
5460
throw new Error('Method not implemented.');
5561
}
5662

5763
private sleep(t: number) {
5864
return new Promise(res => {
5965
setTimeout(() => {
60-
res(undefined)
61-
}, t)
62-
})
66+
res(undefined);
67+
}, t);
68+
});
6369
}
6470

6571
private async checkAccessToken(): Promise<boolean> {
@@ -72,12 +78,16 @@ export class AtomGitAPIService implements ICodeAPIService {
7278
message: '检测到 OAuth 未授权',
7379
type: MessageType.Info,
7480
closable: false,
75-
buttons: ['去授权']
81+
buttons: ['去授权'],
7682
});
7783

7884
let popupWindow;
7985
if (btn === '去授权') {
80-
popupWindow = window.open(`${this.config.origin}login/oauth/authorize?client_id=9d8b531661f441d1`, '_blank', 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=800,height=520,top=150,left=150');
86+
popupWindow = window.open(
87+
`${this.config.origin}login/oauth/authorize?client_id=9d8b531661f441d1`,
88+
'_blank',
89+
'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=800,height=520,top=150,left=150',
90+
);
8191
}
8292

8393
const handleMessage = async (event: MessageEvent) => {
@@ -90,13 +100,13 @@ export class AtomGitAPIService implements ICodeAPIService {
90100
resolve(false);
91101
return;
92102
}
93-
103+
94104
// 清理过期的 token;
95105
this.clearToken();
96106

97107
this.helper.ATOMGIT_TOKEN = token;
98108
this.helper.reinitializeCodeService(true);
99-
109+
100110
resolve(true);
101111
}
102112
} catch (error) {
@@ -134,8 +144,8 @@ export class AtomGitAPIService implements ICodeAPIService {
134144
headers: {
135145
...(privateToken
136146
? {
137-
'Authorization': `Bearer ${privateToken}`,
138-
}
147+
'Authorization': `Bearer ${privateToken}`,
148+
}
139149
: {}),
140150
...headers,
141151
},
@@ -161,25 +171,29 @@ export class AtomGitAPIService implements ICodeAPIService {
161171
}
162172

163173
async getCommit(repo: IRepositoryModel, ref: string): Promise<string> {
164-
const commitInfo = await this.request<API.ResponseCommit>(`/repos/${this.getProjectPath(repo)}/branches/${encodeURIComponent(ref)}`);
174+
const commitInfo = await this.request<API.ResponseCommit>(
175+
`/repos/${this.getProjectPath(repo)}/branches/${encodeURIComponent(ref)}`,
176+
);
165177
return commitInfo.commit.sha;
166178
}
167179
async getTree(repo: IRepositoryModel, path: string): Promise<TreeEntry[]> {
168180
const { owner, name, commit } = repo;
169181
const res = await this.request<API.ResponseFileTree[]>(`/repos/${owner}/${name}/trees/${commit}`, {
170182
params: {
171-
file_path: path
183+
file_path: path,
172184
},
173185
});
174-
175-
return Array.isArray(res) ? res.map(data => {
176-
const name = URI.parse(data.path).displayName;
177186

178-
return {
179-
...data,
180-
name
181-
} as TreeEntry
182-
}) : [];
187+
return Array.isArray(res)
188+
? res.map(data => {
189+
const name = URI.parse(data.path).displayName;
190+
191+
return {
192+
...data,
193+
name,
194+
} as TreeEntry;
195+
})
196+
: [];
183197
}
184198
async getBlob(repo: IRepositoryModel, entry: EntryParam): Promise<Uint8Array> {
185199
const { path } = entry;
@@ -189,17 +203,17 @@ export class AtomGitAPIService implements ICodeAPIService {
189203
{
190204
params: {
191205
ref,
192-
path
193-
}
194-
}
206+
path,
207+
},
208+
},
195209
);
196210

197211
const { content, encoding, type } = res;
198212

199213
if (type !== 'file') {
200214
throw new Error(`${path} is not a file.`);
201215
}
202-
216+
203217
if (encoding === 'base64') {
204218
return Buffer.from(decodeURIComponent(escape(atob(content))));
205219
}
@@ -222,9 +236,9 @@ export class AtomGitAPIService implements ICodeAPIService {
222236
return branches.map((data) => ({
223237
name: data.name,
224238
commit: {
225-
id: data.commit.sha
239+
id: data.commit.sha,
226240
},
227-
protected: data.protected
241+
protected: data.protected,
228242
}));
229243
}
230244
async getTags(_repo: IRepositoryModel): Promise<BranchOrTag[]> {
@@ -233,18 +247,26 @@ export class AtomGitAPIService implements ICodeAPIService {
233247
transformStaticResource(_repo: IRepositoryModel, _path: string): string {
234248
throw new Error('Method not implemented.');
235249
}
236-
async searchContent(_repo: IRepositoryModel, _searchString: string, _options: { limit: number; }): Promise<ISearchResults> {
250+
async searchContent(
251+
_repo: IRepositoryModel,
252+
_searchString: string,
253+
_options: { limit: number },
254+
): Promise<ISearchResults> {
237255
return [];
238256
}
239-
async searchFile(_repo: IRepositoryModel, _searchString: string, _options: { limit?: number | undefined; }): Promise<string[]> {
257+
async searchFile(
258+
_repo: IRepositoryModel,
259+
_searchString: string,
260+
_options: { limit?: number | undefined },
261+
): Promise<string[]> {
240262
return [];
241263
}
242264
async getFileBlame(repo: IRepositoryModel, filepath: string): Promise<Uint8Array> {
243265
const res = await this.request<API.ResponseFileBlame[]>(`/repos/${this.getProjectPath(repo)}/files/blame`, {
244266
params: {
245267
file_path: filepath,
246-
sha: repo.commit
247-
}
268+
sha: repo.commit,
269+
},
248270
});
249271

250272
const blameHash = {};
@@ -274,8 +296,8 @@ export class AtomGitAPIService implements ICodeAPIService {
274296
committed_date: new Date(commit.created_at).getTime(),
275297
message: commit.title,
276298
author: {
277-
avatar_url: commit?.user?.avatar_url || ''
278-
}
299+
avatar_url: commit?.user?.avatar_url || '',
300+
},
279301
},
280302
lines: [
281303
{
@@ -311,21 +333,36 @@ export class AtomGitAPIService implements ICodeAPIService {
311333
getUser(_repo: IRepositoryModel): Promise<any> {
312334
throw new Error('Method not implemented.');
313335
}
314-
336+
315337
public async getProject(repo: IRepositoryModel): Promise<Project> {
316338
const repoInfo = await this.request<API.ResponseRepoInfo>(`/repos/${this.getProjectPath(repo)}`);
317339
return {
318340
id: repoInfo.name,
319-
default_branch: repoInfo.default_branch
341+
default_branch: repoInfo.default_branch,
320342
};
321343
}
322-
canResolveConflict(_repo: IRepositoryModel, _sourceBranch: string, _targetBranch: string, _prId: string): Promise<ConflictAPI.CanResolveConflictResponse> {
344+
canResolveConflict(
345+
_repo: IRepositoryModel,
346+
_sourceBranch: string,
347+
_targetBranch: string,
348+
_prId: string,
349+
): Promise<ConflictAPI.CanResolveConflictResponse> {
323350
throw new Error('Method not implemented.');
324351
}
325-
resolveConflict(_repo: IRepositoryModel, _content: ConflictAPI.ResolveConflict, _sourceBranch: string, _targetBranch: string, _prId?: string | undefined): Promise<ConflictAPI.ResolveConflictResponse> {
352+
resolveConflict(
353+
_repo: IRepositoryModel,
354+
_content: ConflictAPI.ResolveConflict,
355+
_sourceBranch: string,
356+
_targetBranch: string,
357+
_prId?: string | undefined,
358+
): Promise<ConflictAPI.ResolveConflictResponse> {
326359
throw new Error('Method not implemented.');
327360
}
328-
getConflict(_repo: IRepositoryModel, _sourceBranch: string, _targetBranch: string): Promise<ConflictAPI.ConflictResponse> {
361+
getConflict(
362+
_repo: IRepositoryModel,
363+
_sourceBranch: string,
364+
_targetBranch: string,
365+
): Promise<ConflictAPI.ConflictResponse> {
329366
throw new Error('Method not implemented.');
330367
}
331368
mergeBase(_repo: IRepositoryModel, _target: string, _source: string): Promise<ConflictAPI.ResponseCommit> {
@@ -336,5 +373,4 @@ export class AtomGitAPIService implements ICodeAPIService {
336373
this._PRIVATE_TOKEN = null;
337374
this.helper.ATOMGIT_TOKEN = null;
338375
}
339-
340376
}

packages/code-api/src/code-api.provider.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
import { Autowired, Injector, INJECTOR_TOKEN, ConstructorOf } from '@opensumi/di';
1+
import { Autowired, ConstructorOf, Injector, INJECTOR_TOKEN } from '@opensumi/di';
2+
import { ClientAppContribution, Domain, getExternalIcon, getIcon, SlotLocation } from '@opensumi/ide-core-browser';
23
import { Deferred } from '@opensumi/ide-core-common';
3-
import {
4-
SlotLocation,
5-
getIcon,
6-
Domain,
7-
ClientAppContribution,
8-
getExternalIcon,
9-
} from '@opensumi/ide-core-browser';
10-
import { IIconService } from '@opensumi/ide-theme';
114
import { IMainLayoutService } from '@opensumi/ide-main-layout';
12-
import { ICodePlatform, ICodeAPIProvider, ICodeAPIService, CodePlatform } from './common/types';
5+
import { IIconService } from '@opensumi/ide-theme';
6+
import { AtomGitAPIService } from './atomgit/atomgit.service';
7+
import { CodeUPAPIService } from './codeup/codeup.service';
8+
import { CodePlatform, ICodeAPIProvider, ICodeAPIService, ICodePlatform } from './common/types';
9+
import { GiteeAPIService } from './gitee/gitee.service';
1310
import { GitHubAPIService } from './github/github.service';
14-
import { GitLabAPIService } from './gitlab/gitlab.service';
1511
import { GitHubView } from './github/github.view';
12+
import { GitLabAPIService } from './gitlab/gitlab.service';
1613
import { GitLabView } from './gitlab/gitlab.view';
17-
import { AtomGitAPIService } from './atomgit/atomgit.service';
1814
import { GitLinkAPIService } from './gitlink/gitlink.service';
19-
import { CodeUPAPIService } from './codeup/codeup.service';
20-
import { GiteeAPIService } from './gitee/gitee.service';
15+
2116
@Domain(ClientAppContribution)
2217
export class CodeAPIProvider implements ICodeAPIProvider, ClientAppContribution {
2318
@Autowired(INJECTOR_TOKEN)
@@ -26,7 +21,6 @@ export class CodeAPIProvider implements ICodeAPIProvider, ClientAppContribution
2621
@Autowired(IMainLayoutService)
2722
private mainLayoutService: IMainLayoutService;
2823

29-
3024
@Autowired(IIconService)
3125
iconService: IIconService;
3226

@@ -59,7 +53,7 @@ export class CodeAPIProvider implements ICodeAPIProvider, ClientAppContribution
5953
iconClass: getExternalIcon('github'),
6054
title: 'GitHub',
6155
},
62-
SlotLocation.left
56+
SlotLocation.left,
6357
);
6458
});
6559
},
@@ -81,7 +75,7 @@ export class CodeAPIProvider implements ICodeAPIProvider, ClientAppContribution
8175
iconClass: getIcon('Gitlab-fill'),
8276
title: 'GitLab',
8377
},
84-
SlotLocation.left
78+
SlotLocation.left,
8579
);
8680
});
8781
},
@@ -90,19 +84,19 @@ export class CodeAPIProvider implements ICodeAPIProvider, ClientAppContribution
9084
provider: GitLinkAPIService,
9185
});
9286
this.registerPlatformProvider(CodePlatform.atomgit, {
93-
provider: AtomGitAPIService
87+
provider: AtomGitAPIService,
9488
});
9589
this.registerPlatformProvider(CodePlatform.codeup, {
9690
provider: CodeUPAPIService,
9791
});
9892
this.registerPlatformProvider(CodePlatform.gitee, {
9993
provider: GiteeAPIService,
100-
})
94+
});
10195
}
10296

10397
registerPlatformProvider(
10498
platform: ICodePlatform,
105-
provider: { provider: ConstructorOf<ICodeAPIService>; onCreate?: () => void }
99+
provider: { provider: ConstructorOf<ICodeAPIService>; onCreate?: () => void },
106100
) {
107101
if (!this.apiProviderMap.has(platform)) {
108102
this.apiProviderMap.set(platform, provider);

packages/code-api/src/common/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export const extendPlatformConfig = (
182182
origin?: string;
183183
endpoint?: string;
184184
token?: string;
185-
}
185+
},
186186
) => {
187187
const config = CODE_PLATFORM_CONFIG[platform];
188188
if (!config) {

0 commit comments

Comments
 (0)