Skip to content

Commit

Permalink
Merge pull request #591 from benjamin-747/main
Browse files Browse the repository at this point in the history
[ui & mono] fix some ui issues fix
  • Loading branch information
genedna committed Sep 11, 2024
2 parents cf4315e + d5e6076 commit fb7f9e1
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 99 deletions.
4 changes: 2 additions & 2 deletions ceres/src/api_service/import_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl ApiHandler for ImportApiService {
&self,
path: &Path,
start_commit: Commit,
target: TreeItem,
target: &TreeItem,
) -> Commit {
let mut target_commit = start_commit.clone();
let mut visited = HashSet::new();
Expand All @@ -162,7 +162,7 @@ impl ApiHandler for ImportApiService {
while let Some(commit) = p_stack.pop_front() {
let root_tree = self.get_tree_by_hash(&commit.tree_id.to_plain_str()).await;
let reachable = self
.reachable_in_tree(&root_tree, path, target.clone())
.reachable_in_tree(&root_tree, path, target)
.await
.unwrap();
if reachable {
Expand Down
16 changes: 11 additions & 5 deletions ceres/src/api_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub trait ApiHandler: Send + Sync {
&self,
path: &Path,
commit: Commit,
target: TreeItem,
target: &TreeItem,
) -> Commit;

async fn get_blob_as_string(&self, file_path: PathBuf) -> Result<String, GitError> {
Expand Down Expand Up @@ -166,9 +166,9 @@ pub trait ApiHandler: Send + Sync {
let commit = if let Some(commit) = commit_map.get(commit_id) {
commit
} else {
tracing::error!("failed fecth commit: {}", commit_id);
tracing::warn!("failed fecth commit: {}", commit_id);
&self
.traverse_commit_history(&path, self.get_root_commit().await, item)
.traverse_commit_history(&path, self.get_root_commit().await, &item)
.await
};
info.oid = commit.id.to_plain_str();
Expand All @@ -177,6 +177,12 @@ pub trait ApiHandler: Send + Sync {
}
items.push(info);
}
// sort with type and date
items.sort_by(|a, b| {
a.content_type
.cmp(&b.content_type)
.then(b.date.cmp(&a.date))
});
Ok(items)
}
None => Ok(Vec::new()),
Expand Down Expand Up @@ -385,7 +391,7 @@ pub trait ApiHandler: Send + Sync {
&self,
root_tree: &Tree,
path: &Path,
target: TreeItem,
target: &TreeItem,
) -> Result<bool, GitError> {
let relative_path = self.strip_relative(path).unwrap();
let mut search_tree = root_tree.clone();
Expand All @@ -406,7 +412,7 @@ pub trait ApiHandler: Send + Sync {
}
}
// check item exist under search tree
if search_tree.tree_items.into_iter().any(|x| x == target) {
if search_tree.tree_items.iter().any(|x| x == target) {
return Ok(true);
}
Ok(false)
Expand Down
2 changes: 1 addition & 1 deletion ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl ApiHandler for MonoApiService {
Ok(commits.into_iter().map(|x| x.into()).collect())
}

async fn traverse_commit_history(&self, _: &Path, _: Commit, _: TreeItem) -> Commit {
async fn traverse_commit_history(&self, _: &Path, _: Commit, _: &TreeItem) -> Commit {
unreachable!()
}
}
Expand Down
2 changes: 2 additions & 0 deletions ceres/src/model/mr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct MrInfoItem {
pub status: String,
pub open_timestamp: i64,
pub merge_timestamp: Option<i64>,
pub updated_at: i64,
}

impl From<mega_mr::Model> for MrInfoItem {
Expand All @@ -19,6 +20,7 @@ impl From<mega_mr::Model> for MrInfoItem {
status: value.status.to_string(),
open_timestamp: value.created_at.and_utc().timestamp(),
merge_timestamp: value.merge_date.map(|dt| dt.and_utc().timestamp()),
updated_at: value.updated_at.and_utc().timestamp(),
}
}
}
Expand Down
62 changes: 44 additions & 18 deletions ceres/src/pack/import_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ use tokio_stream::wrappers::ReceiverStream;

use callisto::{mega_tree, raw_blob};
use common::errors::MegaError;
use jupiter::{
context::Context,
storage::batch_save_model,
};
use jupiter::{context::Context, storage::batch_save_model};
use mercury::{
errors::GitError,
internal::{
Expand All @@ -30,12 +27,17 @@ use mercury::{hash::SHA1, internal::pack::encode::PackEncoder};

use crate::{
api_service::{mono_api_service::MonoApiService, ApiHandler},
pack::PackHandler, protocol::{import_refs::{CommandType, RefCommand, Refs}, repo::Repo},
pack::PackHandler,
protocol::{
import_refs::{CommandType, RefCommand, Refs},
repo::Repo,
},
};

pub struct ImportRepo {
pub context: Context,
pub repo: Repo,
pub command_list: Vec<RefCommand>,
}

#[async_trait]
Expand All @@ -54,7 +56,6 @@ impl PackHandler for ImportRepo {
}

async fn handle_receiver(&self, receiver: Receiver<Entry>) -> Result<(), GitError> {
self.create_monorepo_parent().await.unwrap();
let storage = self.context.services.git_db_storage.clone();
let mut entry_list = vec![];
let mut join_tasks = vec![];
Expand All @@ -64,14 +65,21 @@ impl PackHandler for ImportRepo {
let stg_clone = storage.clone();
let repo_clone = self.repo.clone();
let handle = tokio::spawn(async move {
stg_clone.save_entry(repo_clone.repo_id, entry_list).await.unwrap();
stg_clone
.save_entry(repo_clone.repo_id, entry_list)
.await
.unwrap();
});
join_tasks.push(handle);
entry_list = vec![];
}
}
join_all(join_tasks).await;
storage.save_entry(self.repo.repo_id, entry_list).await.unwrap();
storage
.save_entry(self.repo.repo_id, entry_list)
.await
.unwrap();
self.attach_to_monorepo_parent().await.unwrap();
Ok(())
}

Expand Down Expand Up @@ -130,7 +138,8 @@ impl PackHandler for ImportRepo {
let sender_clone = entry_tx.clone();
let chunk_clone = chunk.to_vec();
let handler = tokio::spawn(async move {
let mut blob_stream = raw_storage.get_raw_blobs_stream(chunk_clone).await.unwrap();
let mut blob_stream =
raw_storage.get_raw_blobs_stream(chunk_clone).await.unwrap();
while let Some(model) = blob_stream.next().await {
match model {
Ok(m) => {
Expand Down Expand Up @@ -289,9 +298,15 @@ impl PackHandler for ImportRepo {
let storage = self.context.services.git_db_storage.clone();
match refs.command_type {
CommandType::Create => {
storage.save_ref(self.repo.repo_id, refs.clone().into()).await.unwrap();
storage
.save_ref(self.repo.repo_id, refs.clone().into())
.await
.unwrap();
}
CommandType::Delete => storage.remove_ref(self.repo.repo_id, &refs.ref_name).await.unwrap(),
CommandType::Delete => storage
.remove_ref(self.repo.repo_id, &refs.ref_name)
.await
.unwrap(),
CommandType::Update => {
storage
.update_ref(self.repo.repo_id, &refs.ref_name, &refs.new_id)
Expand All @@ -314,13 +329,16 @@ impl PackHandler for ImportRepo {

async fn check_default_branch(&self) -> bool {
let storage = self.context.services.git_db_storage.clone();
storage.default_branch_exist(self.repo.repo_id).await.unwrap()
storage
.default_branch_exist(self.repo.repo_id)
.await
.unwrap()
}
}

impl ImportRepo {
// create monorepo parent for preserve import repo
async fn create_monorepo_parent(&self) -> Result<(), GitError> {
// attach import repo to monorepo parent tree
async fn attach_to_monorepo_parent(&self) -> Result<(), GitError> {
let path = PathBuf::from(self.repo.repo_path.clone());
let mono_api_service = MonoApiService {
context: self.context.clone(),
Expand All @@ -329,13 +347,21 @@ impl ImportRepo {
let save_trees = mono_api_service.search_and_create_tree(&path).await?;

let mut root_ref = storage.get_ref("/").await.unwrap().unwrap();
let commit_id = &self.command_list.first().unwrap().new_id;
let latest_commit: Commit = self
.context
.services
.git_db_storage
.get_commit_by_hash(self.repo.repo_id, commit_id)
.await
.unwrap()
.unwrap()
.into();
let commit_msg = latest_commit.format_message();
let new_commit = Commit::from_tree_id(
save_trees.back().unwrap().id,
vec![SHA1::from_str(&root_ref.ref_commit_hash).unwrap()],
&format!(
"push thrid-part crates {:?} commit",
path.file_name().unwrap()
),
&commit_msg,
);

let save_trees: Vec<mega_tree::ActiveModel> = save_trees
Expand Down
1 change: 1 addition & 0 deletions ceres/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl SmartProtocol {
Ok(Arc::new(ImportRepo {
context: self.context.clone(),
repo,
command_list: self.command_list.clone(),
}))
} else {
let mut res = MonoRepo {
Expand Down
5 changes: 3 additions & 2 deletions mono/src/api/oauth/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ pub struct GitHubUserJson {
pub login: String,
pub id: u32,
pub avatar_url: String,
pub email: String,
// email can be null from github
pub email: Option<String>,
}

impl From<GitHubUserJson> for user::Model {
fn from(value: GitHubUserJson) -> Self {
Self {
id: generate_id(),
name: value.login,
email: value.email,
email: value.email.unwrap_or_default(),
avatar_url: value.avatar_url,
is_github: true,
created_at: chrono::Utc::now().naive_utc(),
Expand Down
31 changes: 3 additions & 28 deletions moon/src/app/(dashboard)/application-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,7 @@ export function ApplicationLayout({
<DropdownButton as={SidebarItem}>
<Avatar src="/images/megaLogo.png" />
<SidebarLabel>Mega</SidebarLabel>
<ChevronDownIcon />
</DropdownButton>
<DropdownMenu className="min-w-80 lg:min-w-64" anchor="bottom start">
<DropdownItem href="/settings">
<Cog8ToothIcon />
<DropdownLabel>Settings</DropdownLabel>
</DropdownItem>
<DropdownDivider />
<DropdownItem href="#">
<Avatar slot="icon" initials="AD" className="bg-purple-500 text-white" />
<DropdownLabel>Admin</DropdownLabel>
</DropdownItem>
<DropdownItem href="#">
<Avatar slot="icon" initials="BE" className="bg-purple-500 text-white" />
<DropdownLabel>Big Events</DropdownLabel>
</DropdownItem>
<DropdownDivider />
<DropdownItem href="#">
<PlusIcon />
<DropdownLabel>New team&hellip;</DropdownLabel>
</DropdownItem>
</DropdownMenu>
</Dropdown>
</SidebarHeader>

Expand All @@ -163,19 +142,15 @@ export function ApplicationLayout({
<TicketIcon />
<SidebarLabel>Merge Request</SidebarLabel>
</SidebarItem>
<SidebarItem href="/settings" current={pathname.startsWith('/settings')}>
<Cog6ToothIcon />
<SidebarLabel>Settings</SidebarLabel>
</SidebarItem>
</SidebarSection>
<SidebarSpacer />

<SidebarSection>
<SidebarItem href="#">
<SidebarItem href="/support">
<QuestionMarkCircleIcon />
<SidebarLabel>Support</SidebarLabel>
</SidebarItem>
<SidebarItem href="#">
<SidebarItem href="/changelog">
<SparklesIcon />
<SidebarLabel>Changelog</SidebarLabel>
</SidebarItem>
Expand All @@ -187,7 +162,7 @@ export function ApplicationLayout({
<Dropdown>
<DropdownButton as={SidebarItem}>
<span className="flex min-w-0 items-center gap-3">
<Avatar src={user.avatar_url} slot="icon" initials="ME" className="size-10 bg-purple-500 text-white" />
<Avatar src={user.avatar_url} slot="icon" className="size-10 text-white" />
<span className="min-w-0">
<span className="block truncate text-sm/5 font-medium text-zinc-950 dark:text-white">{user.name}</span>
<span className="block truncate text-xs/5 font-normal text-zinc-500 dark:text-zinc-400">
Expand Down
8 changes: 8 additions & 0 deletions moon/src/app/(dashboard)/changelog/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function ChangeLogPage() {

return (
<div>
ChangeLog Page
</div>
)
}
8 changes: 8 additions & 0 deletions moon/src/app/(dashboard)/issue/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function IssuePage() {

return (
<div>
Issue Page
</div>
)
}
8 changes: 8 additions & 0 deletions moon/src/app/(dashboard)/support/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function SupportPage() {

return (
<div>
Support Page
</div>
)
}
2 changes: 1 addition & 1 deletion moon/src/app/(dashboard)/user/keys/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export default function KeysPage() {
console.error('Error fetching data:', error);
}
};
useEffect(() => {

useEffect(() => {
fetchData();
}, []);

Expand Down
Loading

1 comment on commit fb7f9e1

@vercel
Copy link

@vercel vercel bot commented on fb7f9e1 Sep 11, 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
mega-gitmono.vercel.app
gitmega.dev
www.gitmega.dev

Please sign in to comment.