Skip to content

Commit 2c683fe

Browse files
authored
feat: support get entry info (#152)
1 parent 3681d3f commit 2c683fe

13 files changed

Lines changed: 58 additions & 30 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
EntryParam,
1414
FileAction,
1515
FileActionHeader,
16+
GetEntryInfoParam,
1617
GitlensBlame,
1718
ICodeAPIService,
1819
IRepositoryModel,
@@ -44,7 +45,7 @@ export class AtomGitAPIService implements ICodeAPIService {
4445
constructor() {
4546
this._PRIVATE_TOKEN = this.config.token || this.helper.ATOMGIT_TOKEN || '';
4647
}
47-
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo> {
48+
getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam): Promise<EntryInfo> {
4849
throw new Error('Method not implemented.');
4950
}
5051
getBranchNames?(repo: IRepositoryModel): Promise<string[]> {

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IReporterService, localize, LRUCache, MessageType } from '@opensumi/ide
55
import { DEFAULT_SEARCH_IN_WORKSPACE_LIMIT } from '@opensumi/ide-search';
66
import { CodePlatformRegistry } from '../common/config';
77
import { HelperService } from '../common/service';
8-
import { Branch, FileAction, FileActionHeader, FileActionResult, Project } from '../common/types';
8+
import { Branch, FileAction, FileActionHeader, FileActionResult, GetEntryInfoParam, Project } from '../common/types';
99
import {
1010
BranchOrTag,
1111
CodePlatform,
@@ -194,21 +194,21 @@ export class CodeUPAPIService implements ICodeAPIService {
194194
return new Uint8Array(new TextEncoder().encode(infoAndBlobs?.content || ''));
195195
}
196196

197-
// async getEntryInfo(repo: IRepositoryModel, entry: EntryParam) {
198-
// const data = await this.request<API.ResponseGetEntry>(
199-
// `/api/v3/projects/${this.getProjectId(repo)}/repository/tree_entry`,
200-
// {
201-
// params: {
202-
// ref_name: repo.commit,
203-
// path: entry.path,
204-
// },
205-
// }
206-
// );
207-
// return {
208-
// size: data.size,
209-
// fileType: data.render === 'download' ? 'binary' : data.render,
210-
// } as const;
211-
// }
197+
async getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam) {
198+
const data = await this.request<API.ResponseGetEntry>(
199+
`/api/v3/projects/${this.getProjectId(repo)}/repository/tree_entry`,
200+
{
201+
params: {
202+
ref_name: repo.commit,
203+
path: entry.path,
204+
},
205+
}
206+
);
207+
return {
208+
...data,
209+
fileType: data.render === 'download' ? 'binary' : data.render,
210+
} as const;
211+
}
212212

213213
async getBranches(repo: IRepositoryModel): Promise<BranchOrTag[]> {
214214
return this.request<API.ResponseGetRefs>(

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export interface EntryInfo {
183183
* file size
184184
*/
185185
size: number;
186+
mode: string;
186187
/**
187188
* file type
188189
*/
@@ -306,6 +307,11 @@ export interface Branch {
306307
};
307308
}
308309

310+
export interface GetEntryInfoParam {
311+
ref_name: string;
312+
path: string;
313+
}
314+
309315
export interface User {
310316
email: string;
311317
name: string;
@@ -404,7 +410,7 @@ export interface ICodeAPIService {
404410
/**
405411
* 获取 entry 相关信息
406412
*/
407-
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo>;
413+
getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam): Promise<EntryInfo>;
408414
/**
409415
* 获取所有分支
410416
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
FileAction,
1717
FileActionHeader,
1818
FileActionResult,
19+
GetEntryInfoParam,
1920
GitlensBlame,
2021
ICodeAPIService,
2122
IRepositoryModel,
@@ -64,7 +65,7 @@ export class GiteeAPIService implements ICodeAPIService {
6465
this._PRIVATE_TOKEN = this.config.token || this.helper.GITEE_TOKEN || '';
6566
}
6667

67-
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo> {
68+
getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam): Promise<EntryInfo> {
6869
throw new Error('Method not implemented.');
6970
}
7071
getBranchNames?(repo: IRepositoryModel): Promise<string[]> {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
TreeEntry,
2222
User,
2323
} from '../common/types';
24-
import type { EntryParam, IRepositoryModel } from '../common/types';
24+
import type { EntryParam, GetEntryInfoParam, IRepositoryModel } from '../common/types';
2525
import { CodeAPI as ConflictAPI, CodePlatform, CommitFileStatus } from '../common/types';
2626
import { retry, RetryError } from '../common/utils';
2727
import { API } from './types';
@@ -93,7 +93,7 @@ export class GitHubAPIService implements ICodeAPIService {
9393
): Promise<ConflictAPI.ResponseCommit> {
9494
throw new Error('Method not implemented.');
9595
}
96-
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo> {
96+
getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam): Promise<EntryInfo> {
9797
throw new Error('Method not implemented.');
9898
}
9999
getBranchNames?(repo: IRepositoryModel): Promise<string[]> {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
CommitParams,
1010
EntryInfo,
1111
EntryParam,
12+
GetEntryInfoParam,
1213
ICodeAPIService,
1314
IRepositoryModel,
1415
Project,
@@ -80,7 +81,7 @@ export class GitLabAPIService implements ICodeAPIService {
8081
): Promise<ConflictAPI.ResponseCommit> {
8182
throw new Error('Method not implemented.');
8283
}
83-
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo> {
84+
getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam): Promise<EntryInfo> {
8485
throw new Error('Method not implemented.');
8586
}
8687
getBranchNames?(repo: IRepositoryModel): Promise<string[]> {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
EntryParam,
1212
FileAction,
1313
FileActionHeader,
14+
GetEntryInfoParam,
1415
GitlensBlame,
1516
ICodeAPIService,
1617
IRepositoryModel,
@@ -74,7 +75,7 @@ export class GitLinkAPIService implements ICodeAPIService {
7475
): Promise<ConflictAPI.ResponseCommit> {
7576
throw new Error('Method not implemented.');
7677
}
77-
getEntryInfo?(_repo: IRepositoryModel, _entry: EntryParam): Promise<EntryInfo> {
78+
getEntryInfo(_repo: IRepositoryModel, _entry: GetEntryInfoParam): Promise<EntryInfo> {
7879
throw new Error('Method not implemented.');
7980
}
8081
getBranchNames?(_repo: IRepositoryModel): Promise<string[]> {

packages/code-service/src/commands.contribution.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CodeAPI, CodePlatform, CommitFileChange, CommitParams, CommitRecord } from '@codeblitzjs/ide-code-api';
1+
import { CodeAPI, CodePlatform, CommitFileChange, CommitParams, CommitRecord, EntryInfo } from '@codeblitzjs/ide-code-api';
22
import { Autowired } from '@opensumi/di';
33
import { IClipboardService, IOpenerService } from '@opensumi/ide-core-browser';
44
import { Command, CommandContribution, CommandRegistry, Disposable, Domain } from '@opensumi/ide-core-common';
@@ -58,6 +58,7 @@ export class CommandsContribution extends Disposable implements CommandContribut
5858
CODE_SERVICE_COMMANDS.COMMIT_DETAIL,
5959
CODE_SERVICE_COMMANDS.COMMIT_COMPARE,
6060
CODE_SERVICE_COMMANDS.COMMIT_FILE,
61+
CODE_SERVICE_COMMANDS.GET_ENTRY_INFO,
6162
CODE_SERVICE_COMMANDS.REMOTE_URL,
6263
CODE_SERVICE_COMMANDS.CHECKOUT_BRANCH,
6364
CODE_SERVICE_COMMANDS.CHECKOUT_COMMIT,
@@ -244,9 +245,21 @@ export class CommandsContribution extends Disposable implements CommandContribut
244245
options?: any,
245246
): Promise<Uint8Array> {
246247
const repo = this.codeModel.getRepository(repoPath);
247-
if (!repo) throw new Error(`${filePath} not exists`);
248+
if (!repo) throw new Error(`repo ${repoPath} not exists`);
248249
return repo.request.getBlobByCommitPath(commitHash, filePath, options);
249250
}
251+
async getEntryInfo(
252+
repoPath: string,
253+
refName: string,
254+
filePath: string,
255+
): Promise<EntryInfo> {
256+
const repo = this.codeModel.getRepository(repoPath);
257+
if (!repo) throw new Error(`repo ${repoPath} not exists`);
258+
return repo.request.getEntryInfo({
259+
ref_name: refName,
260+
path: filePath,
261+
});
262+
}
250263

251264
async remoteUrl(repoPath: string): Promise<string | null> {
252265
const repo = this.codeModel.getRepository(repoPath);

packages/code-service/src/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export namespace CODE_SERVICE_COMMANDS {
4949
category: CATEGORY,
5050
};
5151

52+
export const GET_ENTRY_INFO: Command = {
53+
id: 'code-service.getEntryInfo',
54+
category: CATEGORY,
55+
};
56+
5257
export const REMOTE_URL: Command = {
5358
id: 'code-service.remoteUrl',
5459
category: CATEGORY,

packages/startup/src/code/startup.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import {
33
ComponentContribution,
44
ComponentRegistry,
55
getIcon,
6-
} from '@codeblitzjs/ide-core/lib/modules/opensumi__ide-core-browser';
6+
} from '@opensumi/ide-core-browser';
77
import {
88
IMainLayoutService,
99
MainLayoutContribution,
10-
} from '@codeblitzjs/ide-core/lib/modules/opensumi__ide-main-layout';
10+
} from '@opensumi/ide-main-layout';
1111
import { Autowired, Injectable, Provider } from '@opensumi/di';
1212
import {
1313
BrowserModule,

0 commit comments

Comments
 (0)