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
55 changes: 55 additions & 0 deletions ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ impl MonoApiService {
pub async fn get_sorted_changed_file_list(
&self,
mr_link: &str,
path: Option<&str>,
) -> Result<Vec<String>, MegaError> {
let mr = self
.storage
Expand All @@ -600,6 +601,13 @@ impl MonoApiService {
let file_paths: Vec<String> = sorted_changed_files
.iter()
.map(|f| f.path().to_string_lossy().to_string())
.filter(|file_path| {
if let Some(prefix) = path {
file_path.starts_with(prefix)
} else {
true
}
})
.collect();

Ok(file_paths)
Expand Down Expand Up @@ -965,6 +973,53 @@ mod test {
assert_eq!(old_blobs[0].0, PathBuf::from("deleted_file.txt"));
}

#[test]
fn test_file_lists_with_roots() {
let all_files = vec![
"src/main.rs".to_string(),
"src/utils/math.rs".to_string(),
"src/utils/io.rs".to_string(),
"README.md".to_string(),
];

let root: Option<&str> = None;
let filtered_none: Vec<String> = all_files
.iter()
.filter(|file_path| {
if let Some(prefix) = root {
file_path.starts_with(prefix)
} else {
true
}
})
.cloned()
.collect();

assert_eq!(filtered_none.len(), 4);
assert_eq!(filtered_none, all_files);

let filtered_some: Vec<String> = all_files
.iter()
.filter(|file_path| {
if let Some(prefix) = Some("src/utils") {
file_path.starts_with(prefix)
} else {
true
}
})
.cloned()
.collect();

assert_eq!(filtered_some.len(), 2);
assert_eq!(
filtered_some,
vec![
"src/utils/math.rs".to_string(),
"src/utils/io.rs".to_string()
]
);
}

#[test]
fn test_collect_page_blobs_modified_files() {
let service = MonoApiService {
Expand Down
2 changes: 1 addition & 1 deletion ceres/src/merge_checker/gpg_signature_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Checker for GpgSignatureChecker {
}

Err(e) => {
res.status = ConditionResult::PASSED;
res.status = ConditionResult::FAILED;
Comment thread
AidCheng marked this conversation as resolved.
res.message = format!("Error during GPG signature verification: {e}");
}
};
Expand Down
1 change: 1 addition & 0 deletions mono/src/api/mr/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ pub struct ReviewerInfo {
pub username: String,
pub approved: bool,
}

12 changes: 8 additions & 4 deletions mono/src/api/mr/mr_router.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::path::PathBuf;

use axum::{
extract::{Path, State},
extract::{Path, Query, State},
Json,
};
use callisto::sea_orm_active_enums::{ConvTypeEnum, MergeStatusEnum};
use ceres::model::git::TreeQuery;
use common::{
errors::MegaError,
model::{CommonPage, CommonResult, PageParams},
Expand All @@ -13,8 +14,7 @@ use jupiter::service::mr_service::MRService;
use utoipa_axum::{router::OpenApiRouter, routes};

use crate::api::mr::model::{
ChangeReviewStatePayload, ChangeReviewerStatePayload, ReviewerInfo, ReviewerPayload,
ReviewersResponse,
ChangeReviewStatePayload, ChangeReviewerStatePayload, ReviewerInfo, ReviewerPayload, ReviewersResponse
};
use crate::api::{
api_common::{
Expand Down Expand Up @@ -271,6 +271,7 @@ async fn mr_detail(
get,
params(
("link", description = "MR link"),
TreeQuery,
),
path = "/{link}/mui-tree",
responses(
Expand All @@ -280,9 +281,12 @@ async fn mr_detail(
)]
async fn mr_mui_tree(
Path(link): Path<String>,
Query(query): Query<TreeQuery>,
state: State<MonoApiServiceState>,
) -> Result<Json<CommonResult<Vec<MuiTreeNode>>>, ApiError> {
let files = state.monorepo().get_sorted_changed_file_list(&link).await?;
let path = query.path.clone();

let files = state.monorepo().get_sorted_changed_file_list(&link, Some(&path)).await?;
let mui_trees = build_forest(files);
Ok(Json(CommonResult::success(Some(mui_trees))))
}
Expand Down
Loading