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
4 changes: 2 additions & 2 deletions ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl ApiHandler for MonoApiService {
}

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

Expand Down Expand Up @@ -264,7 +264,7 @@ impl MonoApiService {
// add conversation
self.context
.mr_stg()
.add_mr_conversation(&mr.link, 0, ConvTypeEnum::Merged, None)
.add_mr_conversation(&mr.link, user_id, ConvTypeEnum::Merged, None)
.await
.unwrap();
// update mr status last
Expand Down
9 changes: 7 additions & 2 deletions ceres/src/pack/monorepo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,12 @@ impl MonoRepo {
let comment = self.comment_for_force_update(&mr.to_hash, &self.to_hash);
mr.to_hash = self.to_hash.clone();
storage
.add_mr_conversation(&mr.link, 0, ConvTypeEnum::ForcePush, Some(comment))
.add_mr_conversation(
&mr.link,
String::new(),
ConvTypeEnum::ForcePush,
Some(comment),
)
.await
.unwrap();
} else {
Expand All @@ -379,7 +384,7 @@ impl MonoRepo {
storage
.add_mr_conversation(
&mr.link,
0,
String::new(),
ConvTypeEnum::Closed,
Some("Mega closed MR due to conflict".to_string()),
)
Expand Down
2 changes: 2 additions & 0 deletions common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ pub struct OauthConfig {
pub github_client_secret: String,
pub ui_domain: String,
pub cookie_domain: String,
pub campsite_api_domain: String,
pub allowed_cors_origins: Vec<String>,
}

#[cfg(test)]
Expand Down
6 changes: 6 additions & 0 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@ 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"

# allowed cors origins
allowed_cors_origins = ["http://local.gitmega.com", "http://app.gitmega.com"]
2 changes: 1 addition & 1 deletion jupiter/callisto/src/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: i64,
pub user_id: i64,
pub user_id: String,
#[sea_orm(column_type = "Text")]
pub token: String,
pub created_at: DateTime,
Expand Down
2 changes: 1 addition & 1 deletion jupiter/callisto/src/mega_conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: i64,
pub link: String,
pub user_id: i64,
pub user_id: String,
pub conv_type: ConvTypeEnum,
#[sea_orm(column_type = "Text", nullable)]
pub comment: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion jupiter/callisto/src/mega_mr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Model {
pub title: String,
pub merge_date: Option<DateTime>,
pub status: MergeStatusEnum,
#[sea_orm(column_type = "Text", unique)]
#[sea_orm(column_type = "Text")]
Comment thread
genedna marked this conversation as resolved.
pub path: String,
pub from_hash: String,
pub to_hash: String,
Expand Down
2 changes: 1 addition & 1 deletion jupiter/callisto/src/ssh_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: i64,
pub user_id: i64,
pub user_id: String,
#[sea_orm(column_type = "Text")]
pub title: String,
#[sea_orm(column_type = "Text")]
Expand Down
2 changes: 2 additions & 0 deletions jupiter/migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use sea_orm_migration::schema::big_integer;
mod m20250314_025943_init;
mod m20250427_031332_add_mr_refs_tag;
mod m20250605_013340_alter_mega_mr_index;
mod m20250613_033821_alter_user_id;

pub struct Migrator;

Expand All @@ -14,6 +15,7 @@ impl MigratorTrait for Migrator {
Box::new(m20250314_025943_init::Migration),
Box::new(m20250427_031332_add_mr_refs_tag::Migration),
Box::new(m20250605_013340_alter_mega_mr_index::Migration),
Box::new(m20250613_033821_alter_user_id::Migration),
]
}
}
Expand Down
82 changes: 82 additions & 0 deletions jupiter/migration/src/m20250613_033821_alter_user_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use sea_orm_migration::{prelude::*, sea_orm::DatabaseBackend};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let backend = manager.get_database_backend();

match backend {
DatabaseBackend::Postgres | DatabaseBackend::MySql => {
manager
.alter_table(
Table::alter()
.table(MegaConversation::Table)
.modify_column(
ColumnDef::new(Alias::new("user_id"))
.string()
.not_null()
.to_owned(),
)
.to_owned(),
)
.await?;

manager
.alter_table(
Table::alter()
.table(AccessToken::Table)
.modify_column(
ColumnDef::new(Alias::new("user_id"))
.string()
.not_null()
.to_owned(),
)
.to_owned(),
)
.await?;

manager
.alter_table(
Table::alter()
.table(SshKeys::Table)
.modify_column(
ColumnDef::new(Alias::new("user_id"))
.string()
.not_null()
.to_owned(),
)
.to_owned(),
)
.await?;
}

DatabaseBackend::Sqlite => {

}
}

Ok(())
}

async fn down(&self, _: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
}

#[derive(DeriveIden)]
enum MegaConversation {
Table,
}

#[derive(DeriveIden)]
enum SshKeys {
Table,
}

#[derive(DeriveIden)]
enum AccessToken {
Table,
}
2 changes: 1 addition & 1 deletion jupiter/src/storage/issue_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl IssueStorage {
pub async fn add_issue_conversation(
&self,
link: &str,
user_id: i64,
user_id: String,
comment: Option<String>,
) -> Result<i64, MegaError> {
let conversation = mega_conversation::Model {
Expand Down
6 changes: 3 additions & 3 deletions jupiter/src/storage/mr_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl MrStorage {
pub async fn close_mr(
&self,
model: mega_mr::Model,
user_id: i64,
user_id: String,
username: &str,
) -> Result<(), MegaError> {
self.update_mr(model.clone()).await.unwrap();
Expand All @@ -96,7 +96,7 @@ impl MrStorage {
pub async fn reopen_mr(
&self,
model: mega_mr::Model,
user_id: i64,
user_id: String,
username: &str,
) -> Result<(), MegaError> {
self.update_mr(model.clone()).await.unwrap();
Expand Down Expand Up @@ -141,7 +141,7 @@ impl MrStorage {
pub async fn add_mr_conversation(
&self,
link: &str,
user_id: i64,
user_id: String,
conv_type: ConvTypeEnum,
comment: Option<String>,
) -> Result<i64, MegaError> {
Expand Down
14 changes: 7 additions & 7 deletions jupiter/src/storage/user_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl UserStorage {

pub async fn save_ssh_key(
&self,
user_id: i64,
user_id: String,
title: &str,
ssh_key: &str,
finger: &str,
Expand All @@ -71,15 +71,15 @@ impl UserStorage {
Ok(())
}

pub async fn list_user_ssh(&self, user_id: i64) -> Result<Vec<ssh_keys::Model>, MegaError> {
pub async fn list_user_ssh(&self, user_id: String) -> Result<Vec<ssh_keys::Model>, MegaError> {
let res = ssh_keys::Entity::find()
.filter(ssh_keys::Column::UserId.eq(user_id))
.all(self.get_connection())
.await?;
Ok(res)
}

pub async fn delete_ssh_key(&self, user_id: i64, id: i64) -> Result<(), MegaError> {
pub async fn delete_ssh_key(&self, user_id: String, id: i64) -> Result<(), MegaError> {
let res = ssh_keys::Entity::find()
.filter(ssh_keys::Column::Id.eq(id))
.filter(ssh_keys::Column::UserId.eq(user_id))
Expand All @@ -102,7 +102,7 @@ impl UserStorage {
Ok(res)
}

pub async fn generate_token(&self, user_id: i64) -> Result<String, MegaError> {
pub async fn generate_token(&self, user_id: String) -> Result<String, MegaError> {
let token_str = Uuid::new_v4().to_string();
let model = access_token::Model {
id: generate_id(),
Expand All @@ -115,7 +115,7 @@ impl UserStorage {
Ok(token_str.to_owned())
}

pub async fn delete_token(&self, user_id: i64, id: i64) -> Result<(), MegaError> {
pub async fn delete_token(&self, user_id: String, id: i64) -> Result<(), MegaError> {
let res = access_token::Entity::find()
.filter(access_token::Column::Id.eq(id))
.filter(access_token::Column::UserId.eq(user_id))
Expand All @@ -127,15 +127,15 @@ impl UserStorage {
Ok(())
}

pub async fn list_token(&self, user_id: i64) -> Result<Vec<access_token::Model>, MegaError> {
pub async fn list_token(&self, user_id: String) -> Result<Vec<access_token::Model>, MegaError> {
let res = access_token::Entity::find()
.filter(access_token::Column::UserId.eq(user_id))
.all(self.get_connection())
.await?;
Ok(res)
}

pub async fn check_token(&self, user_id: i64, token: &str) -> Result<bool, MegaError> {
pub async fn check_token(&self, user_id: String, token: &str) -> Result<bool, MegaError> {
let res = access_token::Entity::find()
.filter(access_token::Column::UserId.eq(user_id))
.filter(access_token::Column::Token.eq(token))
Expand Down
3 changes: 2 additions & 1 deletion mono/src/api/api_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use http::StatusCode;
use ceres::{
api_service::ApiHandler,
model::git::{
BlobContentQuery, CodePreviewQuery, CreateFileInfo, LatestCommitInfo, TreeBriefItem, TreeCommitItem, TreeHashItem, TreeQuery
BlobContentQuery, CodePreviewQuery, CreateFileInfo, LatestCommitInfo, TreeBriefItem,
TreeCommitItem, TreeHashItem, TreeQuery,
},
};
use common::model::CommonResult;
Expand Down
14 changes: 9 additions & 5 deletions mono/src/api/issue/issue_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ use utoipa_axum::{router::OpenApiRouter, routes};

use common::model::{CommonPage, CommonResult, PageParams};

use crate::api::issue::{IssueDetail, IssueItem, NewIssue};
use crate::api::mr::SaveCommentRequest;
use crate::api::MonoApiServiceState;
use crate::api::{
issue::{IssueDetail, IssueItem, NewIssue},
oauth::model::LoginUser,
};
use crate::{api::error::ApiError, server::https_server::ISSUE_TAG};

pub fn routers() -> OpenApiRouter<MonoApiServiceState> {
Expand Down Expand Up @@ -104,14 +107,14 @@ async fn issue_detail(
tag = ISSUE_TAG
)]
async fn new_issue(
// user: LoginUser,
user: LoginUser,
state: State<MonoApiServiceState>,
Json(json): Json<NewIssue>,
) -> Result<Json<CommonResult<String>>, ApiError> {
let stg = state.issue_stg().clone();
let res = stg.save_issue(0, &json.title).await.unwrap();
let res = stg
.add_issue_conversation(&res.link, 0, Some(json.description))
.add_issue_conversation(&res.link, user.campsite_user_id, Some(json.description))
.await;
let res = match res {
Ok(_) => CommonResult::success(None),
Expand Down Expand Up @@ -182,14 +185,14 @@ async fn reopen_issue(
tag = ISSUE_TAG
)]
async fn save_comment(
// user: LoginUser,
user: LoginUser,
Path(link): Path<String>,
state: State<MonoApiServiceState>,
Json(payload): Json<SaveCommentRequest>,
) -> Result<Json<CommonResult<String>>, ApiError> {
let res = match state
.issue_stg()
.add_issue_conversation(&link, 0, Some(payload.content))
.add_issue_conversation(&link, user.campsite_user_id, Some(payload.content))
.await
{
Ok(_) => CommonResult::success(None),
Expand All @@ -211,6 +214,7 @@ async fn save_comment(
tag = ISSUE_TAG
)]
async fn delete_comment(
_: LoginUser,
Path(id): Path<i64>,
state: State<MonoApiServiceState>,
) -> Result<Json<CommonResult<String>>, ApiError> {
Expand Down
11 changes: 9 additions & 2 deletions mono/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use jupiter::{
storage::{issue_storage::IssueStorage, mr_storage::MrStorage, user_storage::UserStorage},
};

use crate::api::oauth::campsite_store::CampsiteApiStore;

pub mod api_router;
pub mod error;
pub mod issue;
Expand Down Expand Up @@ -52,12 +54,17 @@ pub type GithubClient<
pub struct MonoApiServiceState {
pub context: Context,
pub oauth_client: Option<GithubClient>,
// TODO: Replace MemoryStore
pub store: Option<MemoryStore>,
pub store: Option<CampsiteApiStore>,
pub listen_addr: String,
}

impl FromRef<MonoApiServiceState> for MemoryStore {
fn from_ref(_: &MonoApiServiceState) -> Self {
MemoryStore::new()
}
}

impl FromRef<MonoApiServiceState> for CampsiteApiStore {
fn from_ref(state: &MonoApiServiceState) -> Self {
state.store.clone().unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion mono/src/api/mr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl From<mega_mr::Model> for MRDetail {
#[derive(Serialize, Deserialize, ToSchema)]
pub struct MegaConversation {
pub id: i64,
pub user_id: i64,
pub user_id: String,
pub conv_type: ConvTypeEnum,
pub comment: Option<String>,
pub created_at: i64,
Expand Down
Loading
Loading