-
Notifications
You must be signed in to change notification settings - Fork 27
feat: support atomgit bulkChangeFiles & createBranch api #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| } | ||
| return []; | ||
| } | ||
| createBranch(_repo: IRepositoryModel, _newBranch: string, _ref: string): Promise<Branch> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createBranch 可以一起实现吗?否则功能还是不完整的(因为 WebSCM 可以创建分支提交代码)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,我找后端提供下接口
|
/next |
📝 Walkthrough📝 Walkthrough📝 WalkthroughWalkthrough此次更改在 Changes
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 或空数组
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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
📒 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: 建议增加错误处理和验证机制
从架构设计角度建议:
- 考虑添加重试机制,处理临时性网络问题
- 添加请求超时设置
- 考虑批量操作的事务性,确保原子性
- 添加详细的日志记录
packages/code-api/src/atomgit/types.ts (1)
43-54: 请确认更新后的 ResponseCommit 接口的兼容性
新的 ResponseCommit 接口添加了多个属性,请确保代码库中所有使用 ResponseCommit 接口的地方都已相应更新,以避免类型不匹配或运行时错误。
运行以下脚本以查找代码库中使用 ResponseCommit 接口的所有位置,并检查是否需要更新:
| 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 []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
实现需要多处改进
代码存在以下几个问题需要注意:
- 使用
toLocaleLowerCase()可能导致意外的转换结果 previous_path直接使用file_path可能不正确- 缺少错误处理机制
- 类型检查不完整
建议按照以下方式修改:
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.
| 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'); | |
| } |
|
CI 挂了 |
There was a problem hiding this 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
📒 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)信息。
| 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
创建分支的实现需要修正参数顺序并增加错误处理
当前实现存在以下问题:
- 请求参数
sha和ref的顺序似乎颠倒了 - 缺少参数验证
- 没有处理
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.
| 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; |
| 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 []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要改进批量修改文件的实现
代码存在以下问题:
- 缺少输入验证
- 错误处理机制不完善
previous_path直接使用file_path可能导致重命名操作失败- 使用
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.
| 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'); | |
| } |
|
/next |
|
🎉 PR Next publish successful! 0.0.20241118064056-featiles.0 |
|
需要 rebase 一下,或者从 v2.3 cherrypick一下? |
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>
…n atomgit service
acc2751 to
39f172e
Compare
我先关闭这个pr,还有两个接口需要实现,我从v2.3 cherry-pick后再提pr |
Types
Background or solution
ChangeLog
Summary by CodeRabbit
新功能
变更
bulkChangeFiles方法的签名,以支持新的参数和返回类型。createBranch方法的签名,以实现分支创建功能。