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
35 changes: 29 additions & 6 deletions ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl MonoApiService {
&self,
mr_link: &str,
page: Pagination,
) -> Result<(Vec<DiffItem>, Vec<String>, u64), GitError> {
) -> Result<(Vec<DiffItem>, u64), GitError> {
let per_page = page.per_page as usize;
let page_id = page.page as usize;

Expand All @@ -456,10 +456,6 @@ impl MonoApiService {
let sorted_changed_files = self
.mr_files_list(old_blobs.clone(), new_blobs.clone())
.await?;
let file_paths: Vec<String> = sorted_changed_files
.iter()
.map(|f| f.path().to_string_lossy().to_string())
.collect();

// ensure page_id is within bounds
let start = (page_id.saturating_sub(1)) * per_page;
Expand Down Expand Up @@ -487,7 +483,7 @@ impl MonoApiService {
// calculate total pages
let total = sorted_changed_files.len().div_ceil(per_page);

Ok((diff_output, file_paths, total as u64))
Ok((diff_output, total as u64))
}

async fn get_diff_by_blobs(
Expand Down Expand Up @@ -582,6 +578,33 @@ impl MonoApiService {
}
}

pub async fn get_sorted_changed_file_list(
&self,
mr_link: &str,
) -> Result<Vec<String>, MegaError> {
let mr = self
.storage
.mr_storage()
.get_mr(mr_link)
.await
.unwrap()
.ok_or_else(|| MegaError::with_message("Error getting "))?;

let old_files = self.get_commit_blobs(&mr.from_hash.clone()).await?;
let new_files = self.get_commit_blobs(&mr.to_hash.clone()).await?;

// calculate pages
let sorted_changed_files = self
.mr_files_list(old_files.clone(), new_files.clone())
.await?;
let file_paths: Vec<String> = sorted_changed_files
.iter()
.map(|f| f.path().to_string_lossy().to_string())
.collect();

Ok(file_paths)
}

pub async fn mr_files_list(
&self,
old_files: Vec<(PathBuf, SHA1)>,
Expand Down
1 change: 0 additions & 1 deletion mono/src/api/mr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ impl From<MRDetails> for MRDetailRes {

#[derive(Serialize, ToSchema)]
pub struct FilesChangedPage {
pub mui_trees: Vec<MuiTreeNode>,
pub page: CommonPage<DiffItem>,
}

Expand Down
27 changes: 22 additions & 5 deletions mono/src/api/mr/mr_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub fn routers() -> OpenApiRouter<MonoApiServiceState> {
.routes(routes!(merge_no_auth))
.routes(routes!(close_mr))
.routes(routes!(reopen_mr))
.routes(routes!(mr_mui_tree))
.routes(routes!(mr_files_changed_by_page))
.routes(routes!(mr_files_list))
.routes(routes!(save_comment))
Expand All @@ -50,7 +51,6 @@ pub fn routers() -> OpenApiRouter<MonoApiServiceState> {
.routes(routes!(add_reviewers))
.routes(routes!(remove_reviewers))
.routes(routes!(list_reviewers))

.routes(routes!(change_reviewer_state))
.routes(routes!(change_review_resolve_state)),
)
Expand Down Expand Up @@ -267,6 +267,26 @@ async fn mr_detail(
Ok(Json(CommonResult::success(Some(mr_details))))
}

#[utoipa::path(
get,
params(
("link", description = "MR link"),
),
path = "/{link}/mui-tree",
responses(
(status = 200, body = CommonResult<Vec<MuiTreeNode>>, content_type = "application/json")
),
tag = MR_TAG
)]
async fn mr_mui_tree(
Path(link): Path<String>,
state: State<MonoApiServiceState>,
) -> Result<Json<CommonResult<Vec<MuiTreeNode>>>, ApiError> {
let files = state.monorepo().get_sorted_changed_file_list(&link).await?;
let mui_trees = build_forest(files);
Ok(Json(CommonResult::success(Some(mui_trees))))
}

/// Get Merge Request file changed list in Pagination
#[utoipa::path(
post,
Expand All @@ -285,14 +305,11 @@ async fn mr_files_changed_by_page(
state: State<MonoApiServiceState>,
Json(json): Json<PageParams<String>>,
) -> Result<Json<CommonResult<FilesChangedPage>>, ApiError> {
let (items, changed_files_path, total) = state
let (items, total) = state
.monorepo()
.paged_content_diff(&link, json.pagination)
.await?;

let mui_trees = build_forest(changed_files_path);
let res = CommonResult::success(Some(FilesChangedPage {
mui_trees,
page: CommonPage { total, items },
}));
Ok(Json(res))
Expand Down
Loading