feat(repo): return ssh/https clone URLs from backend
Add ssh_clone_url and https_clone_url to ProjectRepositoryItem, constructed from config.ssh_domain() and config.git_http_domain(). Update frontend RepoInfo interface and header.tsx to use the server-provided URLs instead of hardcoded values.
This commit is contained in:
parent
b1e93a7cfc
commit
8b433c9169
@ -1,7 +1,7 @@
|
|||||||
use crate::AppService;
|
|
||||||
use crate::error::AppError;
|
use crate::error::AppError;
|
||||||
|
use crate::AppService;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use models::projects::{Project, project_members};
|
use models::projects::{project_members, Project};
|
||||||
use models::repos::repo::{
|
use models::repos::repo::{
|
||||||
ActiveModel as RepoActiveModel, Column as RepoColumn, Entity as RepoEntity,
|
ActiveModel as RepoActiveModel, Column as RepoColumn, Entity as RepoEntity,
|
||||||
};
|
};
|
||||||
@ -34,6 +34,8 @@ pub struct ProjectRepositoryItem {
|
|||||||
pub star_count: i64,
|
pub star_count: i64,
|
||||||
pub watch_count: i64,
|
pub watch_count: i64,
|
||||||
pub last_commit_at: Option<DateTime<Utc>>,
|
pub last_commit_at: Option<DateTime<Utc>>,
|
||||||
|
pub ssh_clone_url: String,
|
||||||
|
pub https_clone_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
|
||||||
@ -200,21 +202,31 @@ impl AppService {
|
|||||||
map
|
map
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let ssh_domain = self
|
||||||
|
.config
|
||||||
|
.ssh_domain()
|
||||||
|
.unwrap_or_else(|_| "code".to_string());
|
||||||
|
|
||||||
let items: Vec<ProjectRepositoryItem> = repo_list
|
let items: Vec<ProjectRepositoryItem> = repo_list
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|r| ProjectRepositoryItem {
|
.map(|r| {
|
||||||
uid: r.id,
|
let path = format!("{}/{}", project.name, r.repo_name);
|
||||||
repo_name: r.repo_name,
|
ProjectRepositoryItem {
|
||||||
description: r.description,
|
uid: r.id,
|
||||||
default_branch: r.default_branch,
|
repo_name: r.repo_name,
|
||||||
project_name: project.name.clone(),
|
description: r.description,
|
||||||
is_private: r.is_private,
|
default_branch: r.default_branch,
|
||||||
commit_count: *commit_counts.get(&r.id).unwrap_or(&0),
|
project_name: project.name.clone(),
|
||||||
branch_count: *branch_counts.get(&r.id).unwrap_or(&0),
|
is_private: r.is_private,
|
||||||
tag_count: *tag_counts.get(&r.id).unwrap_or(&0),
|
commit_count: *commit_counts.get(&r.id).unwrap_or(&0),
|
||||||
star_count: *star_counts.get(&r.id).unwrap_or(&0),
|
branch_count: *branch_counts.get(&r.id).unwrap_or(&0),
|
||||||
watch_count: *watch_counts.get(&r.id).unwrap_or(&0),
|
tag_count: *tag_counts.get(&r.id).unwrap_or(&0),
|
||||||
last_commit_at: last_commit_times.get(&r.id).and_then(|t| *t),
|
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();
|
.collect();
|
||||||
|
|
||||||
|
|||||||
@ -61,8 +61,8 @@ export const RepoHeader = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const cloneUrl = `git@code:${namespace}/${repo_name}.git`;
|
const cloneUrl = repo.ssh_clone_url;
|
||||||
const httpUrl = `${window.location.origin}/${namespace}/${repo_name}`;
|
const httpUrl = repo.https_clone_url;
|
||||||
|
|
||||||
const copyUrl = (url: string, label: string) => {
|
const copyUrl = (url: string, label: string) => {
|
||||||
navigator.clipboard.writeText(url);
|
navigator.clipboard.writeText(url);
|
||||||
|
|||||||
@ -25,6 +25,10 @@ export interface RepoInfo {
|
|||||||
is_star: boolean;
|
is_star: boolean;
|
||||||
/** Whether the current user is watching this repo */
|
/** Whether the current user is watching this repo */
|
||||||
is_watch: boolean;
|
is_watch: boolean;
|
||||||
|
/** SSH clone URL */
|
||||||
|
ssh_clone_url: string;
|
||||||
|
/** HTTPS clone URL */
|
||||||
|
https_clone_url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const RepositoryContext = React.createContext<RepoInfo | null>(null);
|
export const RepositoryContext = React.createContext<RepoInfo | null>(null);
|
||||||
@ -95,6 +99,8 @@ export const RepositoryContextProvider = ({
|
|||||||
last_commit_at: repoItem.last_commit_at,
|
last_commit_at: repoItem.last_commit_at,
|
||||||
is_star: Boolean(starCountResp),
|
is_star: Boolean(starCountResp),
|
||||||
is_watch: Boolean(watchCountResp),
|
is_watch: Boolean(watchCountResp),
|
||||||
|
ssh_clone_url: repoItem.ssh_clone_url,
|
||||||
|
https_clone_url: repoItem.https_clone_url,
|
||||||
};
|
};
|
||||||
}, [repoItem, namespace, starCountResp, watchCountResp]);
|
}, [repoItem, namespace, starCountResp, watchCountResp]);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user