diff --git a/libs/service/project/repo.rs b/libs/service/project/repo.rs index 52549c6..eca7e8c 100644 --- a/libs/service/project/repo.rs +++ b/libs/service/project/repo.rs @@ -1,7 +1,7 @@ -use crate::AppService; use crate::error::AppError; +use crate::AppService; use chrono::{DateTime, Utc}; -use models::projects::{Project, project_members}; +use models::projects::{project_members, Project}; use models::repos::repo::{ ActiveModel as RepoActiveModel, Column as RepoColumn, Entity as RepoEntity, }; @@ -34,6 +34,8 @@ pub struct ProjectRepositoryItem { pub star_count: i64, pub watch_count: i64, pub last_commit_at: Option>, + pub ssh_clone_url: String, + pub https_clone_url: String, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)] @@ -200,21 +202,31 @@ impl AppService { map }; + let ssh_domain = self + .config + .ssh_domain() + .unwrap_or_else(|_| "code".to_string()); + let items: Vec = repo_list .into_iter() - .map(|r| ProjectRepositoryItem { - uid: r.id, - repo_name: r.repo_name, - description: r.description, - default_branch: r.default_branch, - project_name: project.name.clone(), - is_private: r.is_private, - commit_count: *commit_counts.get(&r.id).unwrap_or(&0), - branch_count: *branch_counts.get(&r.id).unwrap_or(&0), - tag_count: *tag_counts.get(&r.id).unwrap_or(&0), - star_count: *star_counts.get(&r.id).unwrap_or(&0), - watch_count: *watch_counts.get(&r.id).unwrap_or(&0), - last_commit_at: last_commit_times.get(&r.id).and_then(|t| *t), + .map(|r| { + let path = format!("{}/{}", project.name, r.repo_name); + ProjectRepositoryItem { + uid: r.id, + repo_name: r.repo_name, + description: r.description, + default_branch: r.default_branch, + project_name: project.name.clone(), + is_private: r.is_private, + commit_count: *commit_counts.get(&r.id).unwrap_or(&0), + branch_count: *branch_counts.get(&r.id).unwrap_or(&0), + tag_count: *tag_counts.get(&r.id).unwrap_or(&0), + star_count: *star_counts.get(&r.id).unwrap_or(&0), + watch_count: *watch_counts.get(&r.id).unwrap_or(&0), + last_commit_at: last_commit_times.get(&r.id).and_then(|t| *t), + ssh_clone_url: format!("git@{}:{}", ssh_domain, path), + https_clone_url: format!("https://{}/{}", ssh_domain, path), + } }) .collect(); diff --git a/src/components/repository/header.tsx b/src/components/repository/header.tsx index 4354e30..eae2004 100644 --- a/src/components/repository/header.tsx +++ b/src/components/repository/header.tsx @@ -61,8 +61,8 @@ export const RepoHeader = () => { }, }); - const cloneUrl = `git@code:${namespace}/${repo_name}.git`; - const httpUrl = `${window.location.origin}/${namespace}/${repo_name}`; + const cloneUrl = repo.ssh_clone_url; + const httpUrl = repo.https_clone_url; const copyUrl = (url: string, label: string) => { navigator.clipboard.writeText(url); diff --git a/src/contexts/repository-context.tsx b/src/contexts/repository-context.tsx index 57a2348..a1873c3 100644 --- a/src/contexts/repository-context.tsx +++ b/src/contexts/repository-context.tsx @@ -25,6 +25,10 @@ export interface RepoInfo { is_star: boolean; /** Whether the current user is watching this repo */ is_watch: boolean; + /** SSH clone URL */ + ssh_clone_url: string; + /** HTTPS clone URL */ + https_clone_url: string; } export const RepositoryContext = React.createContext(null); @@ -95,6 +99,8 @@ export const RepositoryContextProvider = ({ last_commit_at: repoItem.last_commit_at, is_star: Boolean(starCountResp), is_watch: Boolean(watchCountResp), + ssh_clone_url: repoItem.ssh_clone_url, + https_clone_url: repoItem.https_clone_url, }; }, [repoItem, namespace, starCountResp, watchCountResp]);