Skip to content

Commit

Permalink
Merge pull request #436 from benjamin-747/main
Browse files Browse the repository at this point in the history
refactor ui
  • Loading branch information
genedna authored Jul 4, 2024
2 parents a632d8a + 489aece commit eea221e
Show file tree
Hide file tree
Showing 54 changed files with 1,342 additions and 7,526 deletions.
2 changes: 1 addition & 1 deletion ceres/src/api_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use mercury::{

use crate::model::{
create_file::CreateFileInfo,
objects::{LatestCommitInfo, TreeBriefItem, TreeCommitItem, UserInfo},
tree::{LatestCommitInfo, TreeBriefItem, TreeCommitItem, UserInfo},
};

pub mod import_api_service;
Expand Down
41 changes: 34 additions & 7 deletions ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{HashMap, VecDeque};
use std::path::{Path, PathBuf};
use std::str::FromStr;

Expand All @@ -15,11 +15,11 @@ use mercury::internal::object::blob::Blob;
use mercury::internal::object::commit::Commit;
use mercury::internal::object::tree::{Tree, TreeItem, TreeItemMode};
use venus::monorepo::converter;
use venus::monorepo::mr::MergeOperation;

use crate::api_service::ApiHandler;
use crate::model::create_file::CreateFileInfo;
use crate::model::objects::MrInfoItem;
use crate::model::mr::{MRDetail, MrInfoItem};
use crate::model::tree::MRFileTree;

#[derive(Clone)]
pub struct MonoApiService {
Expand Down Expand Up @@ -197,21 +197,48 @@ impl MonoApiService {
} else if status == "closed" {
vec![MergeStatus::Closed, MergeStatus::Merged]
} else {
return Err(MegaError::with_message("Invalid status name"));
vec![MergeStatus::Open, MergeStatus::Closed, MergeStatus::Merged]
// return Err(MegaError::with_message("Invalid status name"));
};
let storage = self.context.services.mega_storage.clone();
let mr_list = storage.get_mr_by_status(status).await.unwrap();
Ok(mr_list.into_iter().map(|m| m.into()).collect())
}

pub async fn merge_mr(&self, op: MergeOperation) -> Result<(), MegaError> {
pub async fn mr_detail(&self, mr_id: i64) -> Result<Option<MRDetail>, MegaError> {
let storage = self.context.services.mega_storage.clone();
if let Some(mut mr) = storage.get_open_mr_by_id(op.mr_id).await.unwrap() {
let model = storage.get_mr(mr_id).await.unwrap();
if let Some(model) = model {
let mut detail: MRDetail = model.into();
let conversions = storage.get_mr_conversations(mr_id).await.unwrap();
detail.conversions = conversions.into_iter().map(|x| x.into()).collect();
return Ok(Some(detail));
}
Ok(None)
}

pub async fn mr_tree_files(&self, mr_id: i64) -> Result<MRFileTree, MegaError> {
let storage = self.context.services.mega_storage.clone();
let model = storage.get_mr(mr_id).await.unwrap();
if let Some(model) = model {
let start_tree = storage.get_commit_by_hash(&model.to_hash).await.unwrap().unwrap().tree;
let mut stack = VecDeque::new();
stack.push_back(start_tree);
// while let Some(_) = stack.pop_front() {

// }
}
Err(MegaError::with_message("Can not find related MR by id"))
}

pub async fn merge_mr(&self, mr_id: i64) -> Result<(), MegaError> {
let storage = self.context.services.mega_storage.clone();
if let Some(mut mr) = storage.get_open_mr_by_id(mr_id).await.unwrap() {
let refs = storage.get_ref(&mr.path).await.unwrap().unwrap();

if mr.from_hash == refs.ref_commit_hash {
// update mr
mr.merge(op.comment);
mr.merge();
storage.update_mr(mr.clone()).await.unwrap();

let commit: Commit = storage
Expand Down
7 changes: 3 additions & 4 deletions ceres/src/http/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ pub async fn git_upload_pack(
.git_upload_pack(&mut upload_request.freeze())
.await
.unwrap();
let mut res_bytes = BytesMut::new();
res_bytes.extend(protocol_buf);

let resp = build_res_header("application/x-git-upload-pack-result".to_owned());

let body_stream = async_stream::stream! {
tracing::info!("send ack/nak message buf: {:?}", &res_bytes);
yield Ok::<_, Infallible>(Bytes::copy_from_slice(&res_bytes));
tracing::info!("send ack/nak message buf: {:?}", &protocol_buf);
yield Ok::<_, Infallible>(Bytes::copy_from_slice(&protocol_buf));
// send packdata with sideband64k
while let Some(chunk) = send_pack_data.next().await {
let mut reader = chunk.as_slice();
loop {
Expand Down
30 changes: 29 additions & 1 deletion ceres/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
use serde::{Deserialize, Serialize};

pub mod create_file;
pub mod objects;
pub mod mr;
pub mod query;
pub mod tree;

#[derive(PartialEq, Eq, Debug, Clone, Default, Serialize, Deserialize)]

pub struct CommonResult<T> {
pub req_result: bool,
pub data: Option<T>,
pub err_message: String,
}

impl<T> CommonResult<T> {
pub fn success(data: Option<T>) -> Self {
CommonResult {
req_result: true,
data,
err_message: "".to_owned(),
}
}
pub fn failed(err_message: &str) -> Self {
CommonResult {
req_result: false,
data: None,
err_message: err_message.to_string(),
}
}
}
66 changes: 66 additions & 0 deletions ceres/src/model/mr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use serde::{Deserialize, Serialize};

use callisto::{mega_mr, mega_mr_conv};

#[derive(Serialize, Deserialize)]
pub struct MrInfoItem {
pub id: i64,
pub title: String,
pub status: String,
pub open_timestamp: i64,
pub merge_timestamp: Option<i64>,
}

impl From<mega_mr::Model> for MrInfoItem {
fn from(value: mega_mr::Model) -> Self {
Self {
id: value.id,
title: String::new(),
status: value.status.to_string(),
open_timestamp: value.created_at.and_utc().timestamp(),
merge_timestamp: value.merge_date.map(|dt| dt.and_utc().timestamp()),
}
}
}

#[derive(Serialize, Deserialize)]
pub struct MRDetail {
pub id: i64,
pub title: String,
pub status: String,
pub open_timestamp: i64,
pub merge_timestamp: Option<i64>,
pub conversions: Vec<MRConversion>,
}

#[derive(Serialize, Deserialize)]
pub struct MRConversion {
pub user_id: i64,
pub conv_type: String,
pub created_at: i64,
pub updated_at: i64,
}

impl From<mega_mr::Model> for MRDetail {
fn from(value: mega_mr::Model) -> Self {
Self {
id: value.id,
title: String::new(),
status: value.status.to_string(),
open_timestamp: value.created_at.and_utc().timestamp(),
merge_timestamp: value.merge_date.map(|dt| dt.and_utc().timestamp()),
conversions: vec![],
}
}
}

impl From<mega_mr_conv::Model> for MRConversion {
fn from(value: mega_mr_conv::Model) -> Self {
Self {
user_id: value.user_id,
conv_type: value.conv_type.to_string(),
created_at: value.created_at.and_utc().timestamp(),
updated_at: value.updated_at.and_utc().timestamp(),
}
}
}
50 changes: 4 additions & 46 deletions ceres/src/model/objects.rs → ceres/src/model/tree.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use callisto::mega_mr;
use serde::{Deserialize, Serialize};

use mercury::internal::object::tree::{TreeItem, TreeItemMode};

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -73,51 +73,9 @@ impl From<TreeItem> for TreeBriefItem {
}
}

// #[derive(Serialize, Deserialize)]
// pub struct BlobObjects {
// pub plain_text: String,
// }

#[derive(Serialize, Deserialize)]
pub struct MrInfoItem {
pub struct MRFileTree {
pub title: String,
pub status: String,
pub open_date: String,
pub merge_date: String,
}

impl From<mega_mr::Model> for MrInfoItem {
fn from(value: mega_mr::Model) -> Self {
Self {
title: String::new(),
status: value.status.to_string(),
open_date: value.created_at.to_string(),
merge_date: value.merge_date.unwrap().to_string(),
}
}
}

#[derive(PartialEq, Eq, Debug, Clone, Default, Serialize, Deserialize)]

pub struct CommonResult<T> {
pub req_result: bool,
pub data: Option<T>,
pub err_message: String,
}

impl <T> CommonResult<T> {
pub fn success(data: Option<T>) -> Self {
CommonResult {
req_result: true,
data,
err_message: "".to_owned(),
}
}
pub fn failed(err_message: &str) -> Self {
CommonResult {
req_result: false,
data: None,
err_message: err_message.to_string(),
}
}
pub id: i64,
pub children: Vec<MRFileTree>,
}
12 changes: 6 additions & 6 deletions ceres/src/pack/monorepo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,21 +373,21 @@ impl MonoRepo {
let storage = self.context.services.mega_storage.clone();
let mut entry_list = Vec::new();
let mut join_tasks = vec![];
let mut commit_id = String::new();
let mut current_commit_id = String::new();
for entry in receiver {
if commit_id.is_empty() {
if current_commit_id.is_empty() {
if entry.obj_type == ObjectType::Commit {
commit_id = entry.hash.to_plain_str();
current_commit_id = entry.hash.to_plain_str();
}
} else {
if entry.obj_type == ObjectType::Commit {
return Err(GitError::CustomError(
"only single commit support in each commit".to_string(),
"only single commit support in each push".to_string(),
));
}
if entry_list.len() >= 1000 {
let stg_clone = storage.clone();
let commit_id = commit_id.clone();
let commit_id = current_commit_id.clone();
let handle = tokio::spawn(async move {
stg_clone.save_entry(&commit_id, entry_list).await.unwrap();
});
Expand All @@ -398,7 +398,7 @@ impl MonoRepo {
entry_list.push(entry);
}
join_all(join_tasks).await;
storage.save_entry(&commit_id, entry_list).await.unwrap();
storage.save_entry(&current_commit_id, entry_list).await.unwrap();
Ok(())
}
}
10 changes: 5 additions & 5 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@
7. Start the Mega server for testing.

```bash
# Starting a single https server
$ cargo run service https
# Starting a single http server
$ cargo run service http
# Or Starting multiple server
$ cargo run service start http ssh p2p
$ cargo run service multi http ssh
```

8. Test the `git push` and `git clone`
Expand Down Expand Up @@ -325,9 +325,9 @@

```bash
# Start a single https server
$ cargo run service https
$ cargo run service http
# Or Start multiple server
$ cargo run service start http ssh p2p
$ cargo run service multi http ssh
```

8. Test `git push` and `git clone`
Expand Down
Loading

1 comment on commit eea221e

@vercel
Copy link

@vercel vercel bot commented on eea221e Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mega – ./

mega-git-main-gitmono.vercel.app
gitmega.dev
www.gitmega.dev
mega-gitmono.vercel.app

Please sign in to comment.