feat: implement commit-user binding#1420
Conversation
…st version) Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn> feat(commit-message-binding):finish binding commit-message to user (2st version) Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn> feat: implement commit-user binding Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| queryKey: ['commit-binding', sha], | ||
| queryFn: async (): Promise<CommitBindingData> => { | ||
| const baseUrl = process.env.NEXT_PUBLIC_MONO_API_URL || process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000' | ||
| const url = `${baseUrl}/api/v1/mega/commits/${sha}` |
There was a problem hiding this comment.
这里的 URL 和在描述里面写的不一致:
API Endpoints:
GET /api/v1/commits/{sha}/binding - Query commit binding information
PUT /api/v1/commits/{sha}/binding - Create/update commit bindings
There was a problem hiding this comment.
API 请求由swagger 文档直接生成,不建议自己实现
…ev#1409) Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
Signed-off-by: Ruizhi Huang <166112492+231220075@users.noreply.github.com>
Signed-off-by: Ruizhi Huang <166112492+231220075@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR implements commit-user binding functionality to associate Git commits with authenticated users, enabling better user tracking and attribution in the system.
- Added database schema for storing commit-user associations with authentication status
- Implemented storage layer with upsert and query capabilities for commit bindings
- Created API endpoints for retrieving and updating commit binding information
Reviewed Changes
Copilot reviewed 24 out of 25 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| mono/src/api/commit/ | New API module with models and router for commit binding endpoints |
| mono/src/api/api_router.rs | Integration of commit router into main API |
| jupiter/src/storage/ | Database storage implementation and migration for commit_auths table |
| ceres/src/protocol/smart.rs | Git protocol integration for automatic binding during push operations |
| ceres/src/auth/mod.rs | User authentication extraction framework for Git operations |
| docs/ | Updated documentation for database schema and API endpoints |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| commit_binding_storage::CommitBindingStorage, conversation_storage::ConversationStorage, | ||
| git_db_storage::GitDbStorage, issue_storage::IssueStorage, lfs_db_storage::LfsDbStorage, | ||
| mr_reviewer_storage::MrReviewerStorage, mono_storage::MonoStorage, mr_storage::MrStorage, | ||
| raw_db_storage::RawDbStorage,relay_storage::RelayStorage, user_storage::UserStorage, |
There was a problem hiding this comment.
Missing space after comma between raw_db_storage::RawDbStorage and relay_storage::RelayStorage.
| raw_db_storage::RawDbStorage,relay_storage::RelayStorage, user_storage::UserStorage, | |
| raw_db_storage::RawDbStorage, relay_storage::RelayStorage, user_storage::UserStorage, |
| Some(UserInfo { | ||
| id: user.id.to_string(), | ||
| username: user.name.clone(), | ||
| display_name: Some(user.name.clone()), // Use name as display_name since display_name field doesn't exist |
There was a problem hiding this comment.
The comment indicates that display_name field doesn't exist, but the code is setting it to Some(user.name.clone()). This comment should be updated to clarify the actual behavior or the field should be properly implemented.
| display_name: Some(user.name.clone()), // Use name as display_name since display_name field doesn't exist | |
| display_name: Some(user.name.clone()), // Use name as display_name (fallback if no separate display name is available) |
| ) | ||
| } else { | ||
| // Fallback for cases where user is matched but user info is not available | ||
| (binding_model.author_email.split('@').next().unwrap_or(&binding_model.author_email).to_string(), None, false) |
There was a problem hiding this comment.
This line is overly complex and hard to read. Consider extracting the email parsing logic into a separate function for better maintainability.
| let matched_user = user_storage.find_user_by_email(&author_email).await?; | ||
|
|
||
| if let Some(user) = matched_user { | ||
| (Some(user.id.to_string()), false) |
There was a problem hiding this comment.
The code is using user.id.to_string() but should be using user.name.clone() to match the matched_username field which expects a username string, not a user ID.
| let matched_user = user_storage.find_user_by_email(&author_email).await?; | ||
|
|
||
| if let Some(user) = matched_user { | ||
| (Some(user.id.to_string()), false) |
There was a problem hiding this comment.
Similar to the previous comment, these lines are using user.id.to_string() but should be using user.name.clone() to match the expected username format for the matched_username field.
| let matched_user = user_storage.find_user_by_email(&author_email).await?; | ||
|
|
||
| if let Some(user) = matched_user { | ||
| (Some(user.id.to_string()), false) |
There was a problem hiding this comment.
Similar to the previous comment, these lines are using user.id.to_string() but should be using user.name.clone() to match the expected username format for the matched_username field.
| if let Ok(commit_obj) = mercury::internal::object::commit::Commit::from_bytes(&entry.data, entry.hash) { | ||
| let mut commits = commits_to_process.lock().unwrap(); | ||
| commits.push((commit_obj.id.to_string(), commit_obj.author.email.clone())); | ||
| } |
There was a problem hiding this comment.
Parsing commit objects twice (once here and potentially again in the storage layer) is inefficient. Consider reusing the parsed commit object or restructuring to avoid duplicate parsing.
| if let Ok(commit_obj) = mercury::internal::object::commit::Commit::from_bytes(&entry.data, entry.hash) { | |
| let mut commits = commits_to_process.lock().unwrap(); | |
| commits.push((commit_obj.id.to_string(), commit_obj.author.email.clone())); | |
| } | |
| let mut commits = commits_to_process.lock().unwrap(); | |
| commits.push((commit.id.to_string(), commit.author.email.clone())); |
…ev#1409) Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn> fix bugs in ceres/src/protocol/smart.rs Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
Backend Implementation
commit_authstable to store commit-user associationsCommitBindingStoragetrait with upsert and query capabilitiesUserAuthExtractorfor identity extraction from AccessTokenGET /api/v1/commits/{sha}/binding- Query commit binding informationPUT /api/v1/commits/{sha}/binding- Create/update commit bindingsFrontend Integration
useGetCommitBindingwith React Query for efficient data fetchingCommitHistoryandCommitMessageWithAuthorto display user info