fix: adjust get_latest_commit && get_blob API#1576
Conversation
Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
There was a problem hiding this comment.
Pull Request Overview
This PR adjusts two API endpoints related to Git operations: get_latest_commit and get_blob. The changes provide committer binding data directly in the commit response and add a refs parameter to the blob retrieval API for branch/tag-specific queries.
- Adds
refsparameter toget_blob_as_stringAPI for retrieving blobs from specific references - Modifies
get_latest_committo populate author/committer data from commit bindings instead of returning separate binding info - Adds author email and username fields to
EditFilePayloadto support commit-to-user binding
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| mono/src/api/router/preview_router.rs | Passes refs parameter to blob retrieval; adds commit binding logic after file edits |
| mono/src/api/mod.rs | Updates blob retrieval call to include new refs parameter (None value) |
| ceres/src/model/git.rs | Adds refs field to BlobContentQuery; removes binding_info from LatestCommitInfo; adds author fields to EditFilePayload |
| ceres/src/api_service/mod.rs | Updates get_blob_as_string signature with refs parameter; modifies commit info population to inline binding data into author/committer fields |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| .api_handler(query.path.as_ref()) | ||
| .await? | ||
| .get_blob_as_string(query.path.into()) | ||
| .get_blob_as_string(query.path.clone().into(), Some(query.refs.as_str())) |
There was a problem hiding this comment.
The query.path is cloned here but was previously consumed by into(). Since query.path is used only once, consider using query.path.into() without cloning to avoid unnecessary allocation.
| .get_blob_as_string(query.path.clone().into(), Some(query.refs.as_str())) | |
| .get_blob_as_string(query.path.into(), Some(query.refs.as_str())) |
| // Fill both author and committer for UI consumption | ||
| commit_info.author.display_name = display.clone(); | ||
| commit_info.author.avatar_url = avatar.clone(); | ||
| commit_info.committer.display_name = display; | ||
| commit_info.committer.avatar_url = avatar; |
There was a problem hiding this comment.
The binding information unconditionally overwrites both author and committer data. This loses the original Git commit author/committer information. Consider preserving the original data or making this behavior explicit, as it may confuse users expecting to see actual Git metadata.
| // Fill both author and committer for UI consumption | |
| commit_info.author.display_name = display.clone(); | |
| commit_info.author.avatar_url = avatar.clone(); | |
| commit_info.committer.display_name = display; | |
| commit_info.committer.avatar_url = avatar; | |
| // Fill author fields with binding info, preserve original committer info | |
| commit_info.author.display_name = display.clone(); | |
| commit_info.author.avatar_url = avatar.clone(); | |
| // Do not overwrite committer fields to preserve original Git metadata | |
| // commit_info.committer.display_name = display; | |
| // commit_info.committer.avatar_url = avatar; |
| false, | ||
| ) | ||
| .await | ||
| .map_err(|e| ApiError::from(anyhow::anyhow!("Failed to update commit binding: {}", e)))?; |
There was a problem hiding this comment.
The error message 'Failed to update commit binding' is misleading since upsert_binding performs both insert and update operations. Consider using 'Failed to save commit binding' for clarity.
| .map_err(|e| ApiError::from(anyhow::anyhow!("Failed to update commit binding: {}", e)))?; | |
| .map_err(|e| ApiError::from(anyhow::anyhow!("Failed to save commit binding: {}", e)))?; |
Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
|
link #1555 |
Provide committer data to the get_latest_commit API;
Provide the refs parameter for the get blob API.