Skip to content

Conversation

@yanqianyu
Copy link
Contributor

@yanqianyu yanqianyu commented Nov 15, 2024

Types

  • 🎉 New Features

Background or solution

ChangeLog

  • 支持 atomgit 的 bulkChangeFiles & createBranch 接口

Summary by CodeRabbit

  • 新功能

    • 引入了批量文件更改功能,允许用户在仓库中同时处理多个文件。
    • 更新了提交响应结构,提供更详细的提交信息,包括作者和提交者的详细信息。
    • 增加了创建分支的功能,允许用户在仓库中创建新分支。
  • 变更

    • 更新了 bulkChangeFiles 方法的签名,以支持新的参数和返回类型。
    • 更新了 createBranch 方法的签名,以实现分支创建功能。

@CLAassistant
Copy link

CLAassistant commented Nov 15, 2024

CLA assistant check
All committers have signed the CLA.

}
return [];
}
createBranch(_repo: IRepositoryModel, _newBranch: string, _ref: string): Promise<Branch> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createBranch 可以一起实现吗?否则功能还是不完整的(因为 WebSCM 可以创建分支提交代码)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,我找后端提供下接口

@hacke2
Copy link
Member

hacke2 commented Nov 15, 2024

/next

@hacke2 hacke2 changed the base branch from main to v2.3 November 15, 2024 09:12
@hacke2 hacke2 changed the base branch from v2.3 to main November 15, 2024 09:13
@coderabbitai
Copy link

coderabbitai bot commented Nov 15, 2024

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

此次更改在 AtomGitAPIService 类中引入了一个新方法 bulkChangeFiles,实现了对代码库中多个文件的批量更改功能。该方法的签名已更新,包含 repoactionsheader 参数,并返回一个 FileActionResult[] 类型的 Promise。实现中通过 POST 请求创建提交,并处理响应以生成包含提交信息的 resCommit 对象。此外,createBranch 方法也进行了更新,以实现新分支的创建,并返回包含分支详细信息的 Branch 对象。同时,在 types.ts 文件中新增了 ResponseCommitInfoResponseBranch 接口,以提供更全面的提交和分支信息结构。

Changes

文件路径 更改摘要
packages/code-api/src/atomgit/atomgit.service.ts 新增方法 bulkChangeFiles,更新方法签名并实现批量文件更改功能,移除之前的占位符实现;更新 createBranch 方法以实现新分支创建。
packages/code-api/src/atomgit/types.ts 新增接口 ResponseCommitInfoResponseBranch,以增强提交和分支信息的表示。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AtomGitAPIService
    participant API

    User->>AtomGitAPIService: 调用 bulkChangeFiles(repo, actions, header)
    AtomGitAPIService->>API: POST /create-commit (包含 actions, project ID, target branch, commit message)
    API-->>AtomGitAPIService: 返回提交响应
    AtomGitAPIService->>User: 返回 resCommit 或空数组
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0e8ebb7 and 7a13af4.

📒 Files selected for processing (2)
  • packages/code-api/src/atomgit/atomgit.service.ts (2 hunks)
  • packages/code-api/src/atomgit/types.ts (1 hunks)
🔇 Additional comments (3)
packages/code-api/src/atomgit/atomgit.service.ts (2)

16-16: 导入声明正确且必要!

FileActionResult 的导入符合接口实现的需求。


329-358: 建议增加错误处理和验证机制

从架构设计角度建议:

  1. 考虑添加重试机制,处理临时性网络问题
  2. 添加请求超时设置
  3. 考虑批量操作的事务性,确保原子性
  4. 添加详细的日志记录
packages/code-api/src/atomgit/types.ts (1)

43-54: 请确认更新后的 ResponseCommit 接口的兼容性

新的 ResponseCommit 接口添加了多个属性,请确保代码库中所有使用 ResponseCommit 接口的地方都已相应更新,以避免类型不匹配或运行时错误。

运行以下脚本以查找代码库中使用 ResponseCommit 接口的所有位置,并检查是否需要更新:

Comment on lines 329 to 357
async bulkChangeFiles(repo: IRepositoryModel, actions: FileAction[], header: FileActionHeader): Promise<FileActionResult[]> {
const res = await this.request<API.ResponseCommit>(
`/repos/${this.getProjectPath(repo)}commits/create`,
{
data: {
actions: actions.map((action) => ({
action: action.action_type.toLocaleLowerCase(),
file_path: action.file_path,
content: action.content,
previous_path: action.file_path,
})),
projectId: repo!.projectId,
branch: header.branch,
commit_message: header.commit_message,
},
method: 'post',
},
);
const resCommit = {
branch_created: false,
branch: header.branch,
commit_id: res.id,
file_name: '',
...res,
};
// 没有提交ID 说明提交失败
if (res.id) {
return [resCommit] as FileActionResult[];
}
return [];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

实现需要多处改进

代码存在以下几个问题需要注意:

  1. 使用 toLocaleLowerCase() 可能导致意外的转换结果
  2. previous_path 直接使用 file_path 可能不正确
  3. 缺少错误处理机制
  4. 类型检查不完整

建议按照以下方式修改:

 async bulkChangeFiles(repo: IRepositoryModel, actions: FileAction[], header: FileActionHeader): Promise<FileActionResult[]> {
+    if (!actions?.length) {
+      return [];
+    }
+
     const res = await this.request<API.ResponseCommit>(
       `/repos/${this.getProjectPath(repo)}commits/create`,
       {
         data: {
           actions: actions.map((action) => ({
-            action: action.action_type.toLocaleLowerCase(),
+            action: action.action_type.toLowerCase(),
             file_path: action.file_path,
             content: action.content,
-            previous_path: action.file_path,
+            previous_path: action.previous_path,
           })),
           projectId: repo!.projectId,
           branch: header.branch,
           commit_message: header.commit_message,
         },
         method: 'post',
       },
     );
+
+    if (!res) {
+      throw new Error('批量修改文件失败:服务器响应为空');
+    }
+
     const resCommit = {
       branch_created: false,
       branch: header.branch,
       commit_id: res.id,
       file_name: '',
       ...res,
     };
-    // 没有提交ID 说明提交失败
+    // 检查提交ID是否存在
     if (res.id) {
       return [resCommit] as FileActionResult[];
     }
-    return [];
+    throw new Error('批量修改文件失败:未获取到提交ID');
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async bulkChangeFiles(repo: IRepositoryModel, actions: FileAction[], header: FileActionHeader): Promise<FileActionResult[]> {
const res = await this.request<API.ResponseCommit>(
`/repos/${this.getProjectPath(repo)}commits/create`,
{
data: {
actions: actions.map((action) => ({
action: action.action_type.toLocaleLowerCase(),
file_path: action.file_path,
content: action.content,
previous_path: action.file_path,
})),
projectId: repo!.projectId,
branch: header.branch,
commit_message: header.commit_message,
},
method: 'post',
},
);
const resCommit = {
branch_created: false,
branch: header.branch,
commit_id: res.id,
file_name: '',
...res,
};
// 没有提交ID 说明提交失败
if (res.id) {
return [resCommit] as FileActionResult[];
}
return [];
async bulkChangeFiles(repo: IRepositoryModel, actions: FileAction[], header: FileActionHeader): Promise<FileActionResult[]> {
if (!actions?.length) {
return [];
}
const res = await this.request<API.ResponseCommit>(
`/repos/${this.getProjectPath(repo)}commits/create`,
{
data: {
actions: actions.map((action) => ({
action: action.action_type.toLowerCase(),
file_path: action.file_path,
content: action.content,
previous_path: action.previous_path,
})),
projectId: repo!.projectId,
branch: header.branch,
commit_message: header.commit_message,
},
method: 'post',
},
);
if (!res) {
throw new Error('批量修改文件失败:服务器响应为空');
}
const resCommit = {
branch_created: false,
branch: header.branch,
commit_id: res.id,
file_name: '',
...res,
};
// 检查提交ID是否存在
if (res.id) {
return [resCommit] as FileActionResult[];
}
throw new Error('批量修改文件失败:未获取到提交ID');
}

@hacke2
Copy link
Member

hacke2 commented Nov 15, 2024

CI 挂了

@yanqianyu yanqianyu changed the title feat: support atomgit bulkChangeFiles api feat: support atomgit bulkChangeFiles & createBranch api Nov 15, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
packages/code-api/src/atomgit/types.ts (1)

48-61: 代码结构清晰,建议添加接口文档

接口定义完整,字段命名规范。建议为接口添加 JSDoc 注释,说明各字段的具体用途和格式要求。

建议添加如下文档注释:

+/**
+ * 提交信息的响应接口
+ * @property author_email - 作者邮箱
+ * @property author_name - 作者名称
+ * @property authored_date - 创作日期
+ * @property committed_date - 提交日期
+ * @property message - 提交信息
+ * @property parent_ids - 父提交ID列表
+ */
 export interface ResponseCommitInfo {
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7a13af4 and acc2751.

📒 Files selected for processing (2)
  • packages/code-api/src/atomgit/atomgit.service.ts (2 hunks)
  • packages/code-api/src/atomgit/types.ts (1 hunks)
🔇 Additional comments (1)
packages/code-api/src/atomgit/types.ts (1)

68-74: 分支响应接口设计合理

接口结构符合 Git 的数据模型,包含了必要的分支引用(ref)和对象(object)信息。

Comment on lines +359 to +376
async createBranch(repo: IRepositoryModel, newBranch: string, ref: string): Promise<Branch> {
const res = await this.request<API.ResponseBranch>(`/repos/${this.getProjectPath(repo)}/git/refs`, {
method: 'post',
data: {
sha: newBranch,
ref: ref,
},
});

const resBranch: Branch = {
commit: {
id: res.object?.sha,
},
name: res.ref,
ref: res.ref,
}

return resBranch;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

创建分支的实现需要修正参数顺序并增加错误处理

当前实现存在以下问题:

  1. 请求参数 sharef 的顺序似乎颠倒了
  2. 缺少参数验证
  3. 没有处理 res.object 可能为空的情况

建议按照以下方式修改:

 async createBranch(repo: IRepositoryModel, newBranch: string, ref: string): Promise<Branch> {
+    if (!newBranch || !ref) {
+      throw new Error('创建分支失败:分支名称和引用不能为空');
+    }
+
     const res = await this.request<API.ResponseBranch>(`/repos/${this.getProjectPath(repo)}/git/refs`, {
       method: 'post',
       data: {
-        sha: newBranch,
-        ref: ref,
+        ref: newBranch,
+        sha: ref,
       },
     });

+    if (!res?.object?.sha) {
+      throw new Error('创建分支失败:未获取到有效的提交信息');
+    }

     const resBranch: Branch = {
       commit: {
         id: res.object?.sha,
       },
       name: res.ref,
       ref: res.ref,
     }

     return resBranch;
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async createBranch(repo: IRepositoryModel, newBranch: string, ref: string): Promise<Branch> {
const res = await this.request<API.ResponseBranch>(`/repos/${this.getProjectPath(repo)}/git/refs`, {
method: 'post',
data: {
sha: newBranch,
ref: ref,
},
});
const resBranch: Branch = {
commit: {
id: res.object?.sha,
},
name: res.ref,
ref: res.ref,
}
return resBranch;
async createBranch(repo: IRepositoryModel, newBranch: string, ref: string): Promise<Branch> {
if (!newBranch || !ref) {
throw new Error('创建分支失败:分支名称和引用不能为空');
}
const res = await this.request<API.ResponseBranch>(`/repos/${this.getProjectPath(repo)}/git/refs`, {
method: 'post',
data: {
ref: newBranch,
sha: ref,
},
});
if (!res?.object?.sha) {
throw new Error('创建分支失败:未获取到有效的提交信息');
}
const resBranch: Branch = {
commit: {
id: res.object?.sha,
},
name: res.ref,
ref: res.ref,
}
return resBranch;

Comment on lines +329 to +357
async bulkChangeFiles(repo: IRepositoryModel, actions: FileAction[], header: FileActionHeader): Promise<FileActionResult[]> {
const res = await this.request<API.ResponseCommitInfo>(
`/repos/${this.getProjectPath(repo)}commits/create`,
{
data: {
actions: actions.map((action) => ({
action: action.action_type.toLocaleLowerCase(),
file_path: action.file_path,
content: action.content,
previous_path: action.file_path,
})),
branch: header.branch,
commit_message: header.commit_message,
},
method: 'post',
},
);
const resCommit = {
branch_created: false,
branch: header.branch,
commit_id: res.id,
file_name: '',
...res,
};
// 没有提交ID 说明提交失败
if (res.id) {
return [resCommit] as FileActionResult[];
}
return [];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

需要改进批量修改文件的实现

代码存在以下问题:

  1. 缺少输入验证
  2. 错误处理机制不完善
  3. previous_path 直接使用 file_path 可能导致重命名操作失败
  4. 使用 toLocaleLowerCase() 可能在某些语言环境下产生意外结果

建议按照以下方式修改:

 async bulkChangeFiles(repo: IRepositoryModel, actions: FileAction[], header: FileActionHeader): Promise<FileActionResult[]> {
+    if (!actions?.length) {
+      return [];
+    }
+
     const res = await this.request<API.ResponseCommitInfo>(
       `/repos/${this.getProjectPath(repo)}commits/create`,
       {
         data: {
           actions: actions.map((action) => ({
-            action: action.action_type.toLocaleLowerCase(),
+            action: action.action_type.toLowerCase(),
             file_path: action.file_path,
             content: action.content,
-            previous_path: action.file_path,
+            previous_path: action.previous_path,
           })),
           branch: header.branch,
           commit_message: header.commit_message,
         },
         method: 'post',
       },
     );

+    if (!res) {
+      throw new Error('批量修改文件失败:服务器响应为空');
+    }

     const resCommit = {
       branch_created: false,
       branch: header.branch,
       commit_id: res.id,
       file_name: '',
       ...res,
     };
-    // 没有提交ID 说明提交失败
+    // 检查提交ID是否存在
     if (res.id) {
       return [resCommit] as FileActionResult[];
     }
-    return [];
+    throw new Error('批量修改文件失败:未获取到提交ID');
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async bulkChangeFiles(repo: IRepositoryModel, actions: FileAction[], header: FileActionHeader): Promise<FileActionResult[]> {
const res = await this.request<API.ResponseCommitInfo>(
`/repos/${this.getProjectPath(repo)}commits/create`,
{
data: {
actions: actions.map((action) => ({
action: action.action_type.toLocaleLowerCase(),
file_path: action.file_path,
content: action.content,
previous_path: action.file_path,
})),
branch: header.branch,
commit_message: header.commit_message,
},
method: 'post',
},
);
const resCommit = {
branch_created: false,
branch: header.branch,
commit_id: res.id,
file_name: '',
...res,
};
// 没有提交ID 说明提交失败
if (res.id) {
return [resCommit] as FileActionResult[];
}
return [];
async bulkChangeFiles(repo: IRepositoryModel, actions: FileAction[], header: FileActionHeader): Promise<FileActionResult[]> {
if (!actions?.length) {
return [];
}
const res = await this.request<API.ResponseCommitInfo>(
`/repos/${this.getProjectPath(repo)}commits/create`,
{
data: {
actions: actions.map((action) => ({
action: action.action_type.toLowerCase(),
file_path: action.file_path,
content: action.content,
previous_path: action.previous_path,
})),
branch: header.branch,
commit_message: header.commit_message,
},
method: 'post',
},
);
if (!res) {
throw new Error('批量修改文件失败:服务器响应为空');
}
const resCommit = {
branch_created: false,
branch: header.branch,
commit_id: res.id,
file_name: '',
...res,
};
// 检查提交ID是否存在
if (res.id) {
return [resCommit] as FileActionResult[];
}
throw new Error('批量修改文件失败:未获取到提交ID');
}

@hacke2
Copy link
Member

hacke2 commented Nov 18, 2024

/next

@opensumi
Copy link
Contributor

opensumi bot commented Nov 18, 2024

🎉 PR Next publish successful!

0.0.20241118064056-featiles.0

@yanqianyu yanqianyu changed the base branch from main to v2.3 November 18, 2024 07:05
@hacke2
Copy link
Member

hacke2 commented Nov 18, 2024

需要 rebase 一下,或者从 v2.3 cherrypick一下?

hacke2 and others added 6 commits November 18, 2024 15:56
Bumps [antd](https://github.com/ant-design/ant-design) from 5.20.2 to 5.22.0.
- [Release notes](https://github.com/ant-design/ant-design/releases)
- [Changelog](https://github.com/ant-design/ant-design/blob/master/CHANGELOG.en-US.md)
- [Commits](ant-design/ant-design@5.20.2...5.22.0)

---
updated-dependencies:
- dependency-name: antd
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@yanqianyu yanqianyu force-pushed the feat/atomgit-bulkChangeFiles branch from acc2751 to 39f172e Compare November 18, 2024 07:59
@yanqianyu
Copy link
Contributor Author

需要 rebase 一下,或者从 v2.3 cherrypick一下?

我先关闭这个pr,还有两个接口需要实现,我从v2.3 cherry-pick后再提pr

@yanqianyu yanqianyu closed this Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants