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
60 changes: 60 additions & 0 deletions .github/workflows/orion-server-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Orion server deploy
on:
push:
branches:
- main
paths:
- '.github/workflows/orion-server-deploy.yml'
- 'orion-server/**'

env:
AWS_ECS_CLUSTER_NAME: ${{ secrets.AWS_ECS_CLUSTER_NAME }}
AWS_ECS_WEB_SERVICE_NAME: ${{ secrets.AWS_ECS_WEB_SERVICE_NAME }}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
orion-server-deploy:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

- name: Build, tag, and push docker image to Amazon ECR Public
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
REGISTRY_ALIAS: m8q5m4u3
REPOSITORY: mega
IMAGE_TAG: orion-server-0.1.0-pre-release
run: |
docker buildx build -t $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG -f orion-server/Dockerfile .
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG

- name: Force ECS redeploy
run: |
aws ecs update-service \
--cluster ${{ secrets.AWS_ECS_CLUSTER_NAME }} \
--service orion-server-dev-service-om0caign \
--force-new-deployment
env:
AWS_REGION: ap-southeast-2
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
71 changes: 70 additions & 1 deletion ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use mercury::internal::object::tree::{Tree, TreeItem, TreeItemMode};

use crate::api_service::ApiHandler;
use crate::model::git::CreateFileInfo;
use crate::model::mr::MrDiffFile;

#[derive(Clone)]
pub struct MonoApiService {
Expand Down Expand Up @@ -421,14 +422,82 @@ impl MonoApiService {
.await?;
Ok(())
}

pub async fn mr_files_list(
&self,
old_files: Vec<(PathBuf, SHA1)>,
new_files: Vec<(PathBuf, SHA1)>,
) -> Result<Vec<MrDiffFile>, MegaError> {
let old_files: HashMap<PathBuf, SHA1> = old_files.into_iter().collect();
let new_files: HashMap<PathBuf, SHA1> = new_files.into_iter().collect();
let unions: HashSet<PathBuf> = old_files.keys().chain(new_files.keys()).cloned().collect();
let mut res = vec![];
for path in unions {
let old_hash = old_files.get(&path);
let new_hash = new_files.get(&path);
match (old_hash, new_hash) {
(None, None) => {}
(None, Some(new)) => res.push(MrDiffFile::New(path, *new)),
(Some(old), None) => res.push(MrDiffFile::Deleted(path, *old)),
(Some(old), Some(new)) => {
if old == new {
continue;
} else {
res.push(MrDiffFile::Modified(path, *old, *new));
}
}
}
}
Ok(res)
}

pub async fn get_commit_blobs(
&self,
commit_hash: &str,
) -> Result<Vec<(PathBuf, SHA1)>, MegaError> {
let mut res = vec![];
let mono_storage = self.storage.services.mono_storage.clone();
let commit = mono_storage.get_commit_by_hash(commit_hash).await?;
if let Some(commit) = commit {
let tree = mono_storage.get_tree_by_hash(&commit.tree).await?;
if let Some(tree) = tree {
let tree: Tree = tree.into();
res = self.traverse_tree(tree).await?;
}
}
Ok(res)
}

async fn traverse_tree(&self, root_tree: Tree) -> Result<Vec<(PathBuf, SHA1)>, MegaError> {
let mut result = vec![];
let mut stack = vec![(PathBuf::new(), root_tree)];

while let Some((base_path, tree)) = stack.pop() {
for item in tree.tree_items {
let path = base_path.join(&item.name);
if item.is_tree() {
let child = self
.storage
.mono_storage()
.get_tree_by_hash(&item.id.to_string())
.await?
.unwrap();
stack.push((path.clone(), child.into()));
} else {
result.push((path, item.id));
}
}
}
Ok(result)
}
}

#[cfg(test)]
mod test {
use std::path::PathBuf;

#[test]
pub fn test() {
pub fn test_path() {
let mut full_path = PathBuf::from("/project/rust/mega");
for _ in 0..3 {
let cloned_path = full_path.clone(); // Clone full_path
Expand Down
1 change: 1 addition & 0 deletions ceres/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod git;
pub mod mr;
12 changes: 12 additions & 0 deletions ceres/src/model/mr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

use mercury::hash::SHA1;

#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
pub enum MrDiffFile {
New(PathBuf, SHA1),
Deleted(PathBuf, SHA1),
// path, old_hash, new_hash
Modified(PathBuf, SHA1, SHA1),
}
12 changes: 12 additions & 0 deletions mono/src/api/api_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,18 @@ pub async fn get_blob_file(
}
}

// Get tree as file
#[utoipa::path(
get,
path = "/file/tree",
params(
TreeQuery
),
responses(
(status = 200, body = CommonResult<Vec<TreeHashItem>>, content_type = "application/json")
),
tag = GIT_TAG
)]
pub async fn get_tree_file(
state: State<MonoApiServiceState>,
Query(query): Query<TreeQuery>,
Expand Down
32 changes: 32 additions & 0 deletions mono/src/api/mr/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::str::FromStr;

use ceres::model::mr::MrDiffFile;
use serde::{Deserialize, Serialize};

use callisto::{
Expand Down Expand Up @@ -106,3 +109,32 @@ impl MuiTreeNode {
pub struct SaveCommentRequest {
pub content: String,
}

#[derive(Serialize, ToSchema)]
pub struct MrFilesRes {
pub path: String,
pub sha: String,
pub action: String,
}

impl From<MrDiffFile> for MrFilesRes {
fn from(value: MrDiffFile) -> Self {
match value {
MrDiffFile::New(path, sha) => Self {
path: path.to_string_lossy().to_string(),
sha: sha.to_string(),
action: String::from_str("new").unwrap(),
},
MrDiffFile::Deleted(path, sha) => Self {
path: path.to_string_lossy().to_string(),
sha: sha.to_string(),
action: String::from_str("deleted").unwrap(),
},
MrDiffFile::Modified(path, _, new) => Self {
path: path.to_string_lossy().to_string(),
sha: new.to_string(),
action: String::from_str("modified").unwrap(),
},
}
}
}
50 changes: 46 additions & 4 deletions mono/src/api/mr/mr_router.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::{collections::HashMap, path::PathBuf};

use axum::{
extract::{Path, State},
Expand All @@ -14,10 +14,12 @@ use common::{
use saturn::ActionEnum;

use crate::api::{
api_common,
api_common::model::{AssigneeUpdatePayload, LabelUpdatePayload, ListPayload},
api_common::{
self,
model::{AssigneeUpdatePayload, LabelUpdatePayload, ListPayload},
},
issue::ItemRes,
mr::{FilesChangedList, MRDetail, MuiTreeNode, SaveCommentRequest},
mr::{FilesChangedList, MRDetail, MrFilesRes, MuiTreeNode, SaveCommentRequest},
oauth::model::LoginUser,
};
use crate::api::{util, MonoApiServiceState};
Expand All @@ -33,6 +35,7 @@ pub fn routers() -> OpenApiRouter<MonoApiServiceState> {
.routes(routes!(close_mr))
.routes(routes!(reopen_mr))
.routes(routes!(mr_files_changed))
.routes(routes!(mr_files_list))
.routes(routes!(save_comment))
.routes(routes!(delete_comment))
.routes(routes!(labels))
Expand Down Expand Up @@ -247,6 +250,45 @@ async fn mr_files_changed(
Ok(Json(res))
}

/// Get Merge Request file list
#[utoipa::path(
get,
params(
("link", description = "MR link"),
),
path = "/{link}/files-list",
responses(
(status = 200, body = CommonResult<Vec<MrFilesRes>>, content_type = "application/json")
),
tag = MR_TAG
)]
async fn mr_files_list(
Path(link): Path<String>,
state: State<MonoApiServiceState>,
) -> Result<Json<CommonResult<Vec<MrFilesRes>>>, ApiError> {
let mr = state
.mr_stg()
.get_mr(&link)
.await?
.ok_or(MegaError::with_message("MR Not Found"))?;

let stg = state.monorepo();
let old_files = stg.get_commit_blobs(&mr.from_hash).await?;
let new_files = stg.get_commit_blobs(&mr.to_hash).await?;
let mr_diff_files = stg.mr_files_list(old_files, new_files.clone()).await?;

let mr_base = PathBuf::from(mr.path);
let res = mr_diff_files
.into_iter()
.map(|m| {
let mut item: MrFilesRes = m.into();
item.path = mr_base.join(item.path).to_string_lossy().to_string();
item
})
.collect::<Vec<MrFilesRes>>();
Ok(Json(CommonResult::success(Some(res))))
}

/// Add new comment on Merge Request
#[utoipa::path(
post,
Expand Down
Loading