Skip to content

Commit

Permalink
feat: support get entry info (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain authored Sep 2, 2024
1 parent 3681d3f commit 2c683fe
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 30 deletions.
3 changes: 2 additions & 1 deletion packages/code-api/src/atomgit/atomgit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EntryParam,
FileAction,
FileActionHeader,
GetEntryInfoParam,
GitlensBlame,
ICodeAPIService,
IRepositoryModel,
Expand Down Expand Up @@ -44,7 +45,7 @@ export class AtomGitAPIService implements ICodeAPIService {
constructor() {
this._PRIVATE_TOKEN = this.config.token || this.helper.ATOMGIT_TOKEN || '';
}
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo> {
getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam): Promise<EntryInfo> {
throw new Error('Method not implemented.');
}
getBranchNames?(repo: IRepositoryModel): Promise<string[]> {
Expand Down
32 changes: 16 additions & 16 deletions packages/code-api/src/codeup/codeup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IReporterService, localize, LRUCache, MessageType } from '@opensumi/ide
import { DEFAULT_SEARCH_IN_WORKSPACE_LIMIT } from '@opensumi/ide-search';
import { CodePlatformRegistry } from '../common/config';
import { HelperService } from '../common/service';
import { Branch, FileAction, FileActionHeader, FileActionResult, Project } from '../common/types';
import { Branch, FileAction, FileActionHeader, FileActionResult, GetEntryInfoParam, Project } from '../common/types';
import {
BranchOrTag,
CodePlatform,
Expand Down Expand Up @@ -194,21 +194,21 @@ export class CodeUPAPIService implements ICodeAPIService {
return new Uint8Array(new TextEncoder().encode(infoAndBlobs?.content || ''));
}

// async getEntryInfo(repo: IRepositoryModel, entry: EntryParam) {
// const data = await this.request<API.ResponseGetEntry>(
// `/api/v3/projects/${this.getProjectId(repo)}/repository/tree_entry`,
// {
// params: {
// ref_name: repo.commit,
// path: entry.path,
// },
// }
// );
// return {
// size: data.size,
// fileType: data.render === 'download' ? 'binary' : data.render,
// } as const;
// }
async getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam) {
const data = await this.request<API.ResponseGetEntry>(
`/api/v3/projects/${this.getProjectId(repo)}/repository/tree_entry`,
{
params: {
ref_name: repo.commit,
path: entry.path,
},
}
);
return {
...data,
fileType: data.render === 'download' ? 'binary' : data.render,
} as const;
}

async getBranches(repo: IRepositoryModel): Promise<BranchOrTag[]> {
return this.request<API.ResponseGetRefs>(
Expand Down
8 changes: 7 additions & 1 deletion packages/code-api/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export interface EntryInfo {
* file size
*/
size: number;
mode: string;
/**
* file type
*/
Expand Down Expand Up @@ -306,6 +307,11 @@ export interface Branch {
};
}

export interface GetEntryInfoParam {
ref_name: string;
path: string;
}

export interface User {
email: string;
name: string;
Expand Down Expand Up @@ -404,7 +410,7 @@ export interface ICodeAPIService {
/**
* 获取 entry 相关信息
*/
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo>;
getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam): Promise<EntryInfo>;
/**
* 获取所有分支
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/code-api/src/gitee/gitee.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
FileAction,
FileActionHeader,
FileActionResult,
GetEntryInfoParam,
GitlensBlame,
ICodeAPIService,
IRepositoryModel,
Expand Down Expand Up @@ -64,7 +65,7 @@ export class GiteeAPIService implements ICodeAPIService {
this._PRIVATE_TOKEN = this.config.token || this.helper.GITEE_TOKEN || '';
}

getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo> {
getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam): Promise<EntryInfo> {
throw new Error('Method not implemented.');
}
getBranchNames?(repo: IRepositoryModel): Promise<string[]> {
Expand Down
4 changes: 2 additions & 2 deletions packages/code-api/src/github/github.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
TreeEntry,
User,
} from '../common/types';
import type { EntryParam, IRepositoryModel } from '../common/types';
import type { EntryParam, GetEntryInfoParam, IRepositoryModel } from '../common/types';
import { CodeAPI as ConflictAPI, CodePlatform, CommitFileStatus } from '../common/types';
import { retry, RetryError } from '../common/utils';
import { API } from './types';
Expand Down Expand Up @@ -93,7 +93,7 @@ export class GitHubAPIService implements ICodeAPIService {
): Promise<ConflictAPI.ResponseCommit> {
throw new Error('Method not implemented.');
}
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo> {
getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam): Promise<EntryInfo> {
throw new Error('Method not implemented.');
}
getBranchNames?(repo: IRepositoryModel): Promise<string[]> {
Expand Down
3 changes: 2 additions & 1 deletion packages/code-api/src/gitlab/gitlab.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
CommitParams,
EntryInfo,
EntryParam,
GetEntryInfoParam,
ICodeAPIService,
IRepositoryModel,
Project,
Expand Down Expand Up @@ -80,7 +81,7 @@ export class GitLabAPIService implements ICodeAPIService {
): Promise<ConflictAPI.ResponseCommit> {
throw new Error('Method not implemented.');
}
getEntryInfo?(repo: IRepositoryModel, entry: EntryParam): Promise<EntryInfo> {
getEntryInfo(repo: IRepositoryModel, entry: GetEntryInfoParam): Promise<EntryInfo> {
throw new Error('Method not implemented.');
}
getBranchNames?(repo: IRepositoryModel): Promise<string[]> {
Expand Down
3 changes: 2 additions & 1 deletion packages/code-api/src/gitlink/gitlink.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
EntryParam,
FileAction,
FileActionHeader,
GetEntryInfoParam,
GitlensBlame,
ICodeAPIService,
IRepositoryModel,
Expand Down Expand Up @@ -74,7 +75,7 @@ export class GitLinkAPIService implements ICodeAPIService {
): Promise<ConflictAPI.ResponseCommit> {
throw new Error('Method not implemented.');
}
getEntryInfo?(_repo: IRepositoryModel, _entry: EntryParam): Promise<EntryInfo> {
getEntryInfo(_repo: IRepositoryModel, _entry: GetEntryInfoParam): Promise<EntryInfo> {
throw new Error('Method not implemented.');
}
getBranchNames?(_repo: IRepositoryModel): Promise<string[]> {
Expand Down
17 changes: 15 additions & 2 deletions packages/code-service/src/commands.contribution.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeAPI, CodePlatform, CommitFileChange, CommitParams, CommitRecord } from '@codeblitzjs/ide-code-api';
import { CodeAPI, CodePlatform, CommitFileChange, CommitParams, CommitRecord, EntryInfo } from '@codeblitzjs/ide-code-api';
import { Autowired } from '@opensumi/di';
import { IClipboardService, IOpenerService } from '@opensumi/ide-core-browser';
import { Command, CommandContribution, CommandRegistry, Disposable, Domain } from '@opensumi/ide-core-common';
Expand Down Expand Up @@ -58,6 +58,7 @@ export class CommandsContribution extends Disposable implements CommandContribut
CODE_SERVICE_COMMANDS.COMMIT_DETAIL,
CODE_SERVICE_COMMANDS.COMMIT_COMPARE,
CODE_SERVICE_COMMANDS.COMMIT_FILE,
CODE_SERVICE_COMMANDS.GET_ENTRY_INFO,
CODE_SERVICE_COMMANDS.REMOTE_URL,
CODE_SERVICE_COMMANDS.CHECKOUT_BRANCH,
CODE_SERVICE_COMMANDS.CHECKOUT_COMMIT,
Expand Down Expand Up @@ -244,9 +245,21 @@ export class CommandsContribution extends Disposable implements CommandContribut
options?: any,
): Promise<Uint8Array> {
const repo = this.codeModel.getRepository(repoPath);
if (!repo) throw new Error(`${filePath} not exists`);
if (!repo) throw new Error(`repo ${repoPath} not exists`);
return repo.request.getBlobByCommitPath(commitHash, filePath, options);
}
async getEntryInfo(
repoPath: string,
refName: string,
filePath: string,
): Promise<EntryInfo> {
const repo = this.codeModel.getRepository(repoPath);
if (!repo) throw new Error(`repo ${repoPath} not exists`);
return repo.request.getEntryInfo({
ref_name: refName,
path: filePath,
});
}

async remoteUrl(repoPath: string): Promise<string | null> {
const repo = this.codeModel.getRepository(repoPath);
Expand Down
5 changes: 5 additions & 0 deletions packages/code-service/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export namespace CODE_SERVICE_COMMANDS {
category: CATEGORY,
};

export const GET_ENTRY_INFO: Command = {
id: 'code-service.getEntryInfo',
category: CATEGORY,
};

export const REMOTE_URL: Command = {
id: 'code-service.remoteUrl',
category: CATEGORY,
Expand Down
4 changes: 2 additions & 2 deletions packages/startup/src/code/startup.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {
ComponentContribution,
ComponentRegistry,
getIcon,
} from '@codeblitzjs/ide-core/lib/modules/opensumi__ide-core-browser';
} from '@opensumi/ide-core-browser';
import {
IMainLayoutService,
MainLayoutContribution,
} from '@codeblitzjs/ide-core/lib/modules/opensumi__ide-main-layout';
} from '@opensumi/ide-main-layout';
import { Autowired, Injectable, Provider } from '@opensumi/di';
import {
BrowserModule,
Expand Down
2 changes: 1 addition & 1 deletion packages/startup/src/startup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
IAIBackServiceOption,
IChatProgress,
sleep,
} from '@codeblitzjs/ide-core/lib/modules/opensumi__ide-core-browser';
} from '@opensumi/ide-core-browser';

(window as any).alex = Alex;

Expand Down
2 changes: 1 addition & 1 deletion packages/startup/src/startup/startup.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CodeModelService } from '@codeblitzjs/ide-code-service';
import {
IMainLayoutService,
MainLayoutContribution,
} from '@codeblitzjs/ide-core/lib/modules/opensumi__ide-main-layout';
} from '@opensumi/ide-main-layout';
import { Autowired, Injectable, Provider } from '@opensumi/di';
import {
BrowserModule,
Expand Down
2 changes: 1 addition & 1 deletion packages/startup/src/startup/web-scm.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Uri } from '@codeblitzjs/ide-core';
import type { IPluginAPI } from '@codeblitzjs/ide-core/lib/editor';
import { Deferred } from '@codeblitzjs/ide-core/lib/modules/opensumi__ide-core-browser';
import { Deferred } from '@opensumi/ide-utils';
import * as localforage from 'localforage';

export const PLUGIN_ID = 'web-scm';
Expand Down

0 comments on commit 2c683fe

Please sign in to comment.