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
13 changes: 5 additions & 8 deletions ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use async_trait::async_trait;
use tokio::process::Command;

use callisto::sea_orm_active_enums::ConvTypeEnum;
use callisto::{mega_blob, mega_tree, raw_blob};
use callisto::{mega_blob, mega_mr, mega_tree, raw_blob};
use common::errors::MegaError;
use jupiter::context::Context;
use jupiter::storage::batch_save_model;
Expand All @@ -20,7 +20,6 @@ use mercury::internal::object::tree::{Tree, TreeItem, TreeItemMode};

use crate::api_service::ApiHandler;
use crate::model::git::CreateFileInfo;
use crate::protocol::mr::MergeRequest;

#[derive(Clone)]
pub struct MonoApiService {
Expand Down Expand Up @@ -233,7 +232,7 @@ impl ApiHandler for MonoApiService {
}

impl MonoApiService {
pub async fn merge_mr(&self, user_id: String, mr: &mut MergeRequest) -> Result<(), MegaError> {
pub async fn merge_mr(&self, user_id: String, mr: mega_mr::Model) -> Result<(), MegaError> {
let storage = self.context.services.mono_storage.clone();
let refs = storage.get_ref(&mr.path).await.unwrap().unwrap();

Expand All @@ -259,18 +258,16 @@ impl MonoApiService {
storage.remove_none_mr_refs(&mr.path).await.unwrap();
// TODO: self.clean_dangling_commits().await;
}
// update mr
mr.merge();
// add conversation
self.context
.mr_stg()
.add_mr_conversation(&mr.link, user_id, ConvTypeEnum::Merged, None)
.issue_stg()
.add_conversation(&mr.link, &user_id, None, ConvTypeEnum::Merged)
.await
.unwrap();
// update mr status last
self.context
.mr_stg()
.update_mr(mr.clone().into())
.merge_mr(mr)
.await
.unwrap();
} else {
Expand Down
84 changes: 33 additions & 51 deletions ceres/src/pack/monorepo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use futures::future::join_all;
use tokio::sync::mpsc::{self, UnboundedReceiver};
use tokio_stream::wrappers::ReceiverStream;

use callisto::{raw_blob, sea_orm_active_enums::ConvTypeEnum};
use callisto::{mega_mr, raw_blob, sea_orm_active_enums::ConvTypeEnum};
use common::{
errors::MegaError,
utils::{self, MEGA_BRANCH_NAME},
};
use jupiter::{context::Context, storage::mr_storage::MrStorage};
use jupiter::context::Context;
use mercury::internal::{object::ObjectTrait, pack::encode::PackEncoder};
use mercury::{
errors::GitError,
Expand All @@ -29,10 +29,7 @@ use mercury::{

use crate::{
pack::PackHandler,
protocol::{
import_refs::{RefCommand, Refs},
mr::MergeRequest,
},
protocol::import_refs::{RefCommand, Refs},
};

pub struct MonoRepo {
Expand Down Expand Up @@ -290,7 +287,7 @@ impl PackHandler for MonoRepo {
let storage = self.context.services.mono_storage.clone();

if let Some(c) = commit {
let mr_link = self.handle_mr(&c.format_message()).await?;
let mr_link = self.handle_mr(&c.format_message()).await.unwrap();
let ref_name = utils::mr_ref_name(&mr_link);
if let Some(mut mr_ref) = storage.get_mr_ref(&ref_name).await.unwrap() {
mr_ref.ref_commit_hash = refs.new_id.clone();
Expand Down Expand Up @@ -328,79 +325,64 @@ impl PackHandler for MonoRepo {
}

impl MonoRepo {
async fn handle_mr(&self, title: &str) -> Result<String, GitError> {
async fn handle_mr(&self, title: &str) -> Result<String, MegaError> {
let storage = self.context.mr_stg();
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).await
let link = mr.link.clone();
self.handle_existing_mr(mr).await?;
Ok(link)
}
None => {
if self.from_hash == "0".repeat(40) {
return Err(GitError::CustomError(String::from(
return Err(MegaError::with_message(
"Can not init directory under monorepo directory!",
)));
));
}
let link: String = utils::generate_link();
let mr = MergeRequest {
path: path_str.to_owned(),
from_hash: self.from_hash.clone(),
to_hash: self.to_hash.clone(),
link: link.clone(),
title: title.to_string(),
..Default::default()
};
storage.save_mr(mr.clone().into()).await.unwrap();
let link = storage
.new_mr(path_str, title, &self.from_hash, &self.to_hash)
.await
.unwrap();
Ok(link)
}
}
}

async fn handle_existing_mr(
&self,
mr: &mut MergeRequest,
storage: &MrStorage,
) -> Result<String, GitError> {
async fn handle_existing_mr(&self, mr: mega_mr::Model) -> Result<(), MegaError> {
let mr_stg = self.context.mr_stg();
let issue_stg = self.context.issue_stg();
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_conversation(
issue_stg
.add_conversation(
&mr.link,
String::new(),
"",
Some(format!(
"Mega updated the mr automatic from {} to {}",
&mr.to_hash[..6],
&self.to_hash[..6]
)),
ConvTypeEnum::ForcePush,
Some(comment),
)
.await
.unwrap();
.await?;
mr_stg.update_mr_to_hash(mr, &self.to_hash).await?;
} else {
tracing::info!("repeat commit with mr: {}, do nothing", mr.id);
}
} else {
mr.close();
storage
.add_mr_conversation(
issue_stg
.add_conversation(
&mr.link,
String::new(),
ConvTypeEnum::Closed,
"",
Some("Mega closed MR due to conflict".to_string()),
ConvTypeEnum::Closed,
)
.await
.unwrap();
mr_stg.close_mr(mr).await?;
}

storage.update_mr(mr.clone().into()).await.unwrap();
Ok(mr.link.clone())
}

fn comment_for_force_update(&self, from: &str, to: &str) -> String {
format!(
"Mega updated the mr automatic from {} to {}",
&from[..6],
&to[..6]
)
Ok(())
}
}
1 change: 0 additions & 1 deletion ceres/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use repo::Repo;
use crate::pack::{import_repo::ImportRepo, monorepo::MonoRepo, PackHandler};

pub mod import_refs;
pub mod mr;
pub mod repo;
pub mod smart;

Expand Down
74 changes: 0 additions & 74 deletions ceres/src/protocol/mr.rs

This file was deleted.

2 changes: 1 addition & 1 deletion common/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::model::CommonResult;

pub type MegaResult = Result<(), MegaError>;

#[derive(Debug)]
#[derive(Error, Debug)]
pub struct MegaError {
pub error: Option<anyhow::Error>,
pub code: i32,
Expand Down
8 changes: 8 additions & 0 deletions common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ impl<T> CommonResult<T> {
err_message: err_message.to_string(),
}
}

pub fn common_failed() -> Self {
CommonResult {
req_result: false,
data: None,
err_message: String::from("API request error"),
}
}
}

#[derive(Deserialize, ToSchema)]
Expand Down
6 changes: 3 additions & 3 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ ui_domain = "http://local.gitmega.com"
# Set your own domain here, for example: .gitmono.com
cookie_domain = "localhost"

# Used for call api from campsite server
campsite_api_domain = "http://api.gitmega.com"
# Used for call api from campsite server, for example: http://api.gitmono.test:3001
campsite_api_domain = "http://api.gitmono.test:3001"

# allowed cors origins
allowed_cors_origins = ["http://local.gitmega.com", "http://app.gitmega.com"]
allowed_cors_origins = ["http://local.gitmega.com", "http://app.gitmega.com", "http://app.gitmono.test"]
21 changes: 21 additions & 0 deletions jupiter/callisto/src/item_labels.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.10

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "item_labels")]
pub struct Model {
pub created_at: DateTime,
pub updated_at: DateTime,
#[sea_orm(primary_key, auto_increment = false)]
pub item_id: i64,
#[sea_orm(primary_key, auto_increment = false)]
pub label_id: i64,
pub item_type: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
21 changes: 21 additions & 0 deletions jupiter/callisto/src/label.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.10

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "label")]
pub struct Model {
pub created_at: DateTime,
pub updated_at: DateTime,
#[sea_orm(primary_key, auto_increment = false)]
pub id: i64,
pub name: String,
pub color: String,
pub description: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
2 changes: 1 addition & 1 deletion jupiter/callisto/src/mega_issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ pub struct Model {
#[sea_orm(unique)]
pub link: String,
pub title: String,
pub owner: i64,
pub status: String,
pub created_at: DateTime,
pub updated_at: DateTime,
pub closed_at: Option<DateTime>,
pub user_id: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
2 changes: 2 additions & 0 deletions jupiter/callisto/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub mod git_repo;
pub mod git_tag;
pub mod git_tree;
pub mod import_refs;
pub mod item_labels;
pub mod label;
pub mod lfs_locks;
pub mod lfs_objects;
pub mod lfs_split_relations;
Expand Down
2 changes: 2 additions & 0 deletions jupiter/callisto/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub use super::git_repo::Entity as GitRepo;
pub use super::git_tag::Entity as GitTag;
pub use super::git_tree::Entity as GitTree;
pub use super::import_refs::Entity as ImportRefs;
pub use super::item_labels::Entity as ItemLabels;
pub use super::label::Entity as Label;
pub use super::lfs_locks::Entity as LfsLocks;
pub use super::lfs_objects::Entity as LfsObjects;
pub use super::lfs_split_relations::Entity as LfsSplitRelations;
Expand Down
2 changes: 2 additions & 0 deletions jupiter/callisto/src/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum ConvTypeEnum {
Closed,
#[sea_orm(string_value = "reopen")]
Reopen,
#[sea_orm(string_value = "label")]
Label,
}
#[derive(
Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, ToSchema,
Expand Down
Loading
Loading