Skip to content

Commit

Permalink
Merge pull request #619 from benjamin-747/main
Browse files Browse the repository at this point in the history
added commit msg in mr title
  • Loading branch information
genedna authored Sep 24, 2024
2 parents 4972a06 + c6c1ba6 commit 1c66321
Show file tree
Hide file tree
Showing 22 changed files with 252 additions and 236 deletions.
3 changes: 1 addition & 2 deletions ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ impl MonoApiService {
vec![MergeStatus::Closed, MergeStatus::Merged]
} else {
vec![MergeStatus::Open, MergeStatus::Closed, MergeStatus::Merged]
// return Err(MegaError::with_message("Invalid status name"));
};
let storage = self.context.services.mono_storage.clone();
let mr_list = storage.get_mr_by_status(status).await.unwrap();
Expand Down Expand Up @@ -301,7 +300,7 @@ impl MonoApiService {

// add conversation
storage
.add_mr_conversation(&mr.mr_link, 0, ConvType::Merged)
.add_mr_conversation(&mr.mr_link, 0, ConvType::Merged, None)
.await
.unwrap();
if mr.path != "/" {
Expand Down
4 changes: 3 additions & 1 deletion ceres/src/model/mr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct MRDetail {
pub struct MRConversion {
pub user_id: i64,
pub conv_type: String,
pub comment: Option<String>,
pub created_at: i64,
pub updated_at: i64,
}
Expand All @@ -49,7 +50,7 @@ impl From<mega_mr::Model> for MRDetail {
Self {
id: value.id,
mr_link: value.mr_link,
title: String::new(),
title: value.title,
status: value.status.to_string(),
open_timestamp: value.created_at.and_utc().timestamp(),
merge_timestamp: value.merge_date.map(|dt| dt.and_utc().timestamp()),
Expand All @@ -63,6 +64,7 @@ impl From<mega_mr_conv::Model> for MRConversion {
Self {
user_id: value.user_id,
conv_type: value.conv_type.to_string(),
comment: value.comment,
created_at: value.created_at.and_utc().timestamp(),
updated_at: value.updated_at.and_utc().timestamp(),
}
Expand Down
77 changes: 35 additions & 42 deletions ceres/src/pack/monorepo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng};
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;

use callisto::raw_blob;
use callisto::{db_enums::ConvType, raw_blob};
use common::{errors::MegaError, utils::MEGA_BRANCH_NAME};
use jupiter::{context::Context, storage::mono_storage::MonoStorage};
use mercury::internal::pack::encode::PackEncoder;
use mercury::internal::{object::ObjectTrait, pack::encode::PackEncoder};
use mercury::{
errors::GitError,
hash::SHA1,
Expand Down Expand Up @@ -123,30 +123,33 @@ impl PackHandler for MonoRepo {
async fn handle_receiver(&self, receiver: Receiver<Entry>) -> Result<(), GitError> {
let storage = self.context.services.mono_storage.clone();
let path_str = self.path.to_str().unwrap();
match storage.get_open_mr_by_path(path_str).await.unwrap() {
Some(mr) => {
let mut mr = mr.into();
self.handle_existing_mr(&mut mr, &storage, receiver).await
}
None => {
let mr_link: String = thread_rng()
.sample_iter(&Alphanumeric)
.take(8)
.map(char::from)
.collect();
let mr = MergeRequest {
path: path_str.to_owned(),
from_hash: self.from_hash.clone(),
to_hash: self.to_hash.clone(),
mr_link: mr_link.to_uppercase(),
..Default::default()
};
let unpack_res = self.save_entry(receiver).await;
if unpack_res.is_ok() {

let unpack_res = self.save_entry(receiver).await;
match unpack_res {
Ok(title) => match storage.get_open_mr_by_path(path_str).await.unwrap() {
Some(mr) => {
let mut mr = mr.into();
self.handle_existing_mr(&mut mr, &storage).await
}
None => {
let mr_link: String = thread_rng()
.sample_iter(&Alphanumeric)
.take(8)
.map(char::from)
.collect();
let mr = MergeRequest {
path: path_str.to_owned(),
from_hash: self.from_hash.clone(),
to_hash: self.to_hash.clone(),
mr_link: mr_link.to_uppercase(),
title,
..Default::default()
};
storage.save_mr(mr.clone().into()).await.unwrap();
Ok(())
}
unpack_res
}
},
Err(err) => Err(err),
}
}

Expand Down Expand Up @@ -332,38 +335,25 @@ impl MonoRepo {
&self,
mr: &mut MergeRequest,
storage: &MonoStorage,
receiver: Receiver<Entry>,
) -> Result<(), GitError> {
if mr.from_hash == self.from_hash {
if mr.to_hash != self.to_hash {
let comment = self.comment_for_force_update(&mr.to_hash, &self.to_hash);
mr.to_hash = self.to_hash.clone();
storage
.add_mr_comment(&mr.mr_link, 0, Some(comment))
.add_mr_conversation(&mr.mr_link, 0, ConvType::Comment, Some(comment))
.await
.unwrap();

let unpack_res = self.save_entry(receiver).await;
if unpack_res.is_err() {
mr.close();
storage
.add_mr_comment(
&mr.mr_link,
0,
Some("Mega closed MR due to multi commit detected".to_string()),
)
.await
.unwrap();
}
} else {
tracing::info!("repeat commit with mr: {}, do nothing", mr.id);
}
} else {
mr.close();
storage
.add_mr_comment(
.add_mr_conversation(
&mr.mr_link,
0,
ConvType::Comment,
Some("Mega closed MR due to conflict".to_string()),
)
.await
Expand All @@ -382,15 +372,18 @@ impl MonoRepo {
)
}

async fn save_entry(&self, receiver: Receiver<Entry>) -> Result<(), GitError> {
async fn save_entry(&self, receiver: Receiver<Entry>) -> Result<String, GitError> {
let storage = self.context.services.mono_storage.clone();
let mut entry_list = Vec::new();
let mut join_tasks = vec![];
let mut current_commit_id = String::new();
let mut mr_title = String::new();
for entry in receiver {
if current_commit_id.is_empty() {
if entry.obj_type == ObjectType::Commit {
current_commit_id = entry.hash.to_plain_str();
let commit = Commit::from_bytes(&entry.data, entry.hash).unwrap();
mr_title = commit.format_message();
}
} else {
if entry.obj_type == ObjectType::Commit {
Expand All @@ -415,6 +408,6 @@ impl MonoRepo {
.save_entry(&current_commit_id, entry_list)
.await
.unwrap();
Ok(())
Ok(mr_title)
}
}
4 changes: 4 additions & 0 deletions ceres/src/protocol/mr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use common::utils::generate_id;
pub struct MergeRequest {
pub id: i64,
pub mr_link: String,
pub title: String,
pub status: MergeStatus,
pub merge_date: Option<NaiveDateTime>,
pub path: String,
Expand All @@ -19,6 +20,7 @@ impl Default for MergeRequest {
Self {
id: generate_id(),
mr_link: String::new(),
title: String::new(),
status: MergeStatus::Open,
merge_date: None,
path: String::new(),
Expand All @@ -44,6 +46,7 @@ impl From<MergeRequest> for mega_mr::Model {
Self {
id: value.id,
mr_link: value.mr_link,
title: value.title,
status: value.status,
merge_date: value.merge_date,
path: value.path,
Expand All @@ -60,6 +63,7 @@ impl From<mega_mr::Model> for MergeRequest {
Self {
id: value.id,
mr_link: value.mr_link,
title: value.title,
status: value.status,
merge_date: value.merge_date,
path: value.path,
Expand Down
2 changes: 1 addition & 1 deletion docker/start-moon.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# user must set the MEGA_HOST,MEGA_INTERNAL_HOST
# user must set the MEGA_HOST, MEGA_INTERNAL_HOST
if [ -z "$MEGA_HOST" ]; then
echo "MEGA_HOST is not set"
exit 1
Expand Down
1 change: 0 additions & 1 deletion jupiter/callisto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub mod mega_blob;
pub mod mega_commit;
pub mod mega_issue;
pub mod mega_mr;
pub mod mega_mr_comment;
pub mod mega_mr_conv;
pub mod mega_refs;
pub mod mega_tag;
Expand Down
1 change: 1 addition & 0 deletions jupiter/callisto/src/mega_mr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: i64,
pub mr_link: String,
pub title: String,
pub merge_date: Option<DateTime>,
pub status: MergeStatus,
#[sea_orm(column_type = "Text")]
Expand Down
19 changes: 0 additions & 19 deletions jupiter/callisto/src/mega_mr_comment.rs

This file was deleted.

2 changes: 2 additions & 0 deletions jupiter/callisto/src/mega_mr_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub struct Model {
pub mr_link: String,
pub user_id: i64,
pub conv_type: ConvType,
#[sea_orm(column_type = "Text", nullable)]
pub comment: Option<String>,
pub created_at: DateTime,
pub updated_at: DateTime,
}
Expand Down
1 change: 0 additions & 1 deletion jupiter/callisto/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub use crate::mega_blob::Entity as MegaBlob;
pub use crate::mega_commit::Entity as MegaCommit;
pub use crate::mega_issue::Entity as MegaIssue;
pub use crate::mega_mr::Entity as MegaMr;
pub use crate::mega_mr_comment::Entity as MegaMrComment;
pub use crate::mega_mr_conv::Entity as MegaMrConv;
pub use crate::mega_refs::Entity as MegaRefs;
pub use crate::mega_tag::Entity as MegaTag;
Expand Down
2 changes: 1 addition & 1 deletion jupiter/src/storage/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn setup_sql(conn: &DatabaseConnection) -> Result<(), TransactionError<DbE
let backend = txn.get_database_backend();

// `include_str!` will expand the file while compiling, so `.sql` is not needed after that
const SETUP_SQL: &str = include_str!("../../../sql/sqlite/sqlite_20240912_init.sql");
const SETUP_SQL: &str = include_str!("../../../sql/sqlite/sqlite_20240923_init.sql");
txn.execute(Statement::from_string(backend, SETUP_SQL)).await?;
Ok(())
})
Expand Down
25 changes: 3 additions & 22 deletions jupiter/src/storage/mono_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sea_orm::{

use callisto::db_enums::{ConvType, MergeStatus};
use callisto::{
mega_blob, mega_commit, mega_mr, mega_mr_comment, mega_mr_conv, mega_refs, mega_tag, mega_tree,
mega_blob, mega_commit, mega_mr, mega_mr_conv, mega_refs, mega_tag, mega_tree,
raw_blob,
};
use common::errors::MegaError;
Expand Down Expand Up @@ -178,12 +178,14 @@ impl MonoStorage {
mr_link: &str,
user_id: i64,
conv_type: ConvType,
comment: Option<String>,
) -> Result<i64, MegaError> {
let conversation = mega_mr_conv::Model {
id: generate_id(),
mr_link: mr_link.to_owned(),
user_id,
conv_type,
comment,
created_at: chrono::Utc::now().naive_utc(),
updated_at: chrono::Utc::now().naive_utc(),
};
Expand All @@ -192,27 +194,6 @@ impl MonoStorage {
Ok(res.id)
}

pub async fn add_mr_comment(
&self,
mr_link: &str,
user_id: i64,
comment: Option<String>,
) -> Result<(), MegaError> {
let conv_id = self
.add_mr_conversation(mr_link, user_id, ConvType::Comment)
.await
.unwrap();
let comment = mega_mr_comment::Model {
id: generate_id(),
conv_id,
comment,
edited: false,
};
let comment = comment.into_active_model();
comment.insert(self.get_connection()).await.unwrap();
Ok(())
}

pub async fn save_entry(
&self,
commit_id: &str,
Expand Down
2 changes: 1 addition & 1 deletion mercury/src/internal/pack/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ impl Pack {
// DO NOT use thread::spawn, because it will block tokio runtime (if single-threaded runtime, like in tests)
tokio::task::spawn_blocking(move || {
self.decode(&mut reader, move |entry, _| {
sender.send(entry).unwrap();
if sender.send(entry).is_ok() {}
}).unwrap();
self
}).await.unwrap()
Expand Down
Loading

1 comment on commit 1c66321

@vercel
Copy link

@vercel vercel bot commented on 1c66321 Sep 24, 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-gitmono.vercel.app
gitmega.dev
mega-git-main-gitmono.vercel.app
www.gitmega.dev

Please sign in to comment.