Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions ceres/src/api_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ pub trait ApiHandler: Send + Sync {

async fn get_commits_by_hashes(&self, c_hashes: Vec<String>) -> Result<Vec<Commit>, GitError>;

async fn get_blob_as_string(&self, file_path: PathBuf) -> Result<Option<String>, GitError> {
async fn get_blob_as_string(
&self,
file_path: PathBuf,
refs: Option<&str>,
) -> Result<Option<String>, GitError> {
let filename = file_path.file_name().unwrap().to_str().unwrap();
let parent = file_path.parent().unwrap();
if let Some(tree) = self.search_tree_by_path(parent).await?
if let Some(tree) = self.search_tree_by_path_with_refs(parent, refs).await?
&& let Some(item) = tree.tree_items.into_iter().find(|x| x.name == filename)
{
match self.get_raw_blob_by_hash(&item.id.to_string()).await {
Expand All @@ -111,8 +115,14 @@ pub trait ApiHandler: Send + Sync {
let commit = self.get_tree_relate_commit(tree.id, path).await?;
let mut commit_info: LatestCommitInfo = commit.into();

// Build commit binding information
commit_info.binding_info = self.build_commit_binding_info(&commit_info.oid).await?;
if let Some(binding) = self.build_commit_binding_info(&commit_info.oid).await? {
let display = binding.display_name.clone();
let avatar = binding.avatar_url.clone().unwrap_or_default();

// Fill both author for UI consumption
commit_info.author.display_name = display.clone();
commit_info.author.avatar_url = avatar.clone();
}

Ok(commit_info)
}
Expand Down
10 changes: 8 additions & 2 deletions ceres/src/model/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub struct TreeQuery {

#[derive(Debug, Deserialize, IntoParams)]
pub struct BlobContentQuery {
#[serde(default)]
pub refs: String,
#[serde(default = "default_path")]
pub path: String,
}
Expand All @@ -58,7 +60,6 @@ pub struct LatestCommitInfo {
pub author: UserInfo,
pub committer: UserInfo,
pub status: String,
pub binding_info: Option<CommitBindingInfo>,
}

#[derive(Serialize, Deserialize, ToSchema)]
Expand Down Expand Up @@ -89,7 +90,6 @@ impl From<Commit> for LatestCommitInfo {
author,
committer,
status: "success".to_string(),
binding_info: None, // Will be populated at API layer
}
}
}
Expand Down Expand Up @@ -210,6 +210,12 @@ pub struct EditFilePayload {
pub content: String,
/// Commit message to use when creating the commit
pub commit_message: String,
/// author email to bind this commit to a user
#[serde(default)]
pub author_email: Option<String>,
/// platform username (used to verify and bind commit to user)
#[serde(default)]
pub author_username: Option<String>,
}

/// Response body after saving an edited file
Expand Down
2 changes: 1 addition & 1 deletion mono/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub mod util {
let cedar_path = component.join(".mega_cedar.json");
let entity_str = state
.monorepo()
.get_blob_as_string(cedar_path)
.get_blob_as_string(cedar_path, None)
.await
.unwrap();
if let Some(entity_str) = entity_str {
Expand Down
18 changes: 16 additions & 2 deletions mono/src/api/router/preview_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn get_blob_string(
let data = state
.api_handler(query.path.as_ref())
.await?
.get_blob_as_string(query.path.into())
.get_blob_as_string(query.path.into(), Some(query.refs.as_str()))
.await?;
Ok(Json(CommonResult::success(data)))
}
Expand Down Expand Up @@ -378,6 +378,20 @@ async fn save_edit(
Json(payload): Json<EditFilePayload>,
) -> Result<Json<CommonResult<EditFileResult>>, ApiError> {
let handler = state.api_handler(payload.path.as_ref()).await?;
let res = handler.save_file_edit(payload).await?;
let res = handler.save_file_edit(payload.clone()).await?;

// If frontend provided author info, bind commit to that user
if let Some(email) = payload.author_email.as_ref() {
let stg = state.storage.commit_binding_storage();
stg.upsert_binding(
&res.commit_id,
email,
payload.author_username.clone(),
false,
)
.await
.map_err(|e| ApiError::from(anyhow::anyhow!("Failed to save commit binding: {}", e)))?;
}

Ok(Json(CommonResult::success(Some(res))))
}
2 changes: 1 addition & 1 deletion moon/packages/types/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15255,4 +15255,4 @@ Continuously monitors the log file and streams new content as it becomes availab
}
}
}
}
}