1+ import { request , RequestOptions } from '@codeblitzjs/ide-common' ;
12import { Autowired , Injectable } from '@opensumi/di' ;
3+ import { isObject , MessageType , URI } from '@opensumi/ide-core-common' ;
4+ import { CODE_PLATFORM_CONFIG , HelperService } from '../common' ;
25import {
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' ;
2323import { CodeAPI as ConflictAPI } from '../common/types' ;
2424import { 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}
0 commit comments