refactor(git): drop /logs (subsumed by /commits), blobs/raw, tags/{name}/verify, DELETE-repo archive alias; add unarchive
ZhenYi committed
Modified lib/git/src/handler/blobs/mod.rs lib/git/src/handler/blobs/mod.rs +0 −1 View lib/git/src/handler/blobs/mod.rs
@@ -1,4 +1,3 @@
11pub mod content;
22pub mod list_lfs_pointers;
33pub mod metadata;
4pub mod raw_download;
Deleted lib/git/src/handler/blobs/raw_download.rs lib/git/src/handler/blobs/raw_download.rs +0 −43
@@ -1,43 +0,0 @@
1use axum::extract::{Path, State};
2use export::rest::AppResponseData;
3use session::Session;
4
5use crate::errors::{ApiError, GitApiError};
6use crate::handler::resolve_reader;
7use crate::service::GitService;
8use crate::service::blobs::RawDownloadDto;
9
10#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
11pub struct BlobPath {
12 pub space_name: String,
13 pub repo_name: String,
14 pub oid: String,
15}
16
17#[utoipa::path(
18 get,
19 path = "/repos/{space_name}/{repo_name}/blobs/{oid}/raw",
20 tag = "blobs",
21 params(BlobPath),
22 responses(
23 (status = 200, description = "blob raw download info", body = AppResponseData<RawDownloadDto>)
24 )
25)]
26pub async fn blob_raw_download(
27 State(service): State<GitService>,
28 session: Session,
29 Path(path): Path<BlobPath>,
30) -> Result<AppResponseData<RawDownloadDto>, ApiError> {
31 let _ = resolve_reader(
32 &service,
33 &session,
34 path.space_name.clone(),
35 path.repo_name.clone(),
36 )
37 .await?;
38 let out = service
39 .blob_raw_download(path.space_name, path.repo_name, path.oid)
40 .await
41 .map_err(GitApiError::from)?;
42 Ok(AppResponseData::ok(out))
43}
Deleted lib/git/src/handler/logs/commits_between.rs lib/git/src/handler/logs/commits_between.rs +0 −54
@@ -1,54 +0,0 @@
1use axum::extract::{Path, Query, State};
2use export::rest::AppResponseData;
3use session::Session;
4
5use crate::errors::{ApiError, GitApiError};
6use crate::handler::resolve_reader;
7use crate::service::GitService;
8use crate::service::logs::LogListDto;
9
10#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
11pub struct BetweenQuery {
12 pub after: String,
13 pub before: String,
14 #[serde(default)]
15 pub limit: Option<u64>,
16}
17
18#[utoipa::path(
19 get,
20 path = "/repos/{space_name}/{repo_name}/logs/between",
21 tag = "logs",
22 params(
23 crate::handler::RepoPath,
24 BetweenQuery,
25 ),
26 responses(
27 (status = 200, description = "commits between two revisions")
28 )
29)]
30pub async fn log_commits_between(
31 State(service): State<GitService>,
32 session: Session,
33 Path(path): Path<crate::handler::RepoPath>,
34 Query(query): Query<BetweenQuery>,
35) -> Result<AppResponseData<LogListDto>, ApiError> {
36 let _ = resolve_reader(
37 &service,
38 &session,
39 path.space_name.clone(),
40 path.repo_name.clone(),
41 )
42 .await?;
43 let out = service
44 .log_commits_between(
45 path.space_name,
46 path.repo_name,
47 query.after,
48 query.before,
49 query.limit.unwrap_or(50),
50 )
51 .await
52 .map_err(GitApiError::from)?;
53 Ok(AppResponseData::ok(out))
54}
Deleted lib/git/src/handler/logs/graph.rs lib/git/src/handler/logs/graph.rs +0 −40
@@ -1,40 +0,0 @@
1use axum::extract::{Path, Query, State};
2use export::rest::AppResponseData;
3use session::Session;
4
5use crate::errors::{ApiError, GitApiError};
6use crate::handler::resolve_reader;
7use crate::service::GitService;
8use crate::service::logs::{GraphNode, LogOptions};
9
10#[utoipa::path(
11 get,
12 path = "/repos/{space_name}/{repo_name}/logs/graph",
13 tag = "logs",
14 params(
15 crate::handler::RepoPath,
16 LogOptions,
17 ),
18 responses(
19 (status = 200, description = "commit graph")
20 )
21)]
22pub async fn log_graph(
23 State(service): State<GitService>,
24 session: Session,
25 Path(path): Path<crate::handler::RepoPath>,
26 Query(opts): Query<LogOptions>,
27) -> Result<AppResponseData<Vec<GraphNode>>, ApiError> {
28 let _ = resolve_reader(
29 &service,
30 &session,
31 path.space_name.clone(),
32 path.repo_name.clone(),
33 )
34 .await?;
35 let out = service
36 .log_graph(path.space_name, path.repo_name, opts)
37 .await
38 .map_err(GitApiError::from)?;
39 Ok(AppResponseData::ok(out))
40}
Deleted lib/git/src/handler/logs/last_commit.rs lib/git/src/handler/logs/last_commit.rs +0 −45
@@ -1,45 +0,0 @@
1use axum::extract::{Path, Query, State};
2use export::rest::AppResponseData;
3use gitbaby::commit::types::CommitInfo;
4use session::Session;
5
6use crate::errors::{ApiError, GitApiError};
7use crate::handler::resolve_reader;
8use crate::service::GitService;
9
10#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
11pub struct LastCommitQuery {
12 pub branch: String,
13}
14
15#[utoipa::path(
16 get,
17 path = "/repos/{space_name}/{repo_name}/logs/last",
18 tag = "logs",
19 params(
20 crate::handler::RepoPath,
21 LastCommitQuery,
22 ),
23 responses(
24 (status = 200, description = "last commit on branch")
25 )
26)]
27pub async fn log_last_commit(
28 State(service): State<GitService>,
29 session: Session,
30 Path(path): Path<crate::handler::RepoPath>,
31 Query(query): Query<LastCommitQuery>,
32) -> Result<AppResponseData<CommitInfo>, ApiError> {
33 let _ = resolve_reader(
34 &service,
35 &session,
36 path.space_name.clone(),
37 path.repo_name.clone(),
38 )
39 .await?;
40 let out = service
41 .log_last_commit(path.space_name, path.repo_name, query.branch)
42 .await
43 .map_err(GitApiError::from)?;
44 Ok(AppResponseData::ok(out))
45}
Deleted lib/git/src/handler/logs/list.rs lib/git/src/handler/logs/list.rs +0 −40
@@ -1,40 +0,0 @@
1use axum::extract::{Path, Query, State};
2use export::rest::AppResponseData;
3use session::Session;
4
5use crate::errors::{ApiError, GitApiError};
6use crate::handler::resolve_reader;
7use crate::service::GitService;
8use crate::service::logs::{LogListDto, LogOptions};
9
10#[utoipa::path(
11 get,
12 path = "/repos/{space_name}/{repo_name}/logs",
13 tag = "logs",
14 params(
15 crate::handler::RepoPath,
16 LogOptions,
17 ),
18 responses(
19 (status = 200, description = "list commits")
20 )
21)]
22pub async fn log_list(
23 State(service): State<GitService>,
24 session: Session,
25 Path(path): Path<crate::handler::RepoPath>,
26 Query(opts): Query<LogOptions>,
27) -> Result<AppResponseData<LogListDto>, ApiError> {
28 let _ = resolve_reader(
29 &service,
30 &session,
31 path.space_name.clone(),
32 path.repo_name.clone(),
33 )
34 .await?;
35 let out = service
36 .log_list(path.space_name, path.repo_name, opts)
37 .await
38 .map_err(GitApiError::from)?;
39 Ok(AppResponseData::ok(out))
40}
Deleted lib/git/src/handler/logs/mod.rs lib/git/src/handler/logs/mod.rs +0 −4
@@ -1,4 +0,0 @@
1pub mod commits_between;
2pub mod graph;
3pub mod last_commit;
4pub mod list;
Modified lib/git/src/handler/pipelines/get_run.rs lib/git/src/handler/pipelines/get_run.rs +0 −1 View lib/git/src/handler/pipelines/get_run.rs
@@ -4,7 +4,6 @@
44
55use crate::errors::{ApiError, GitApiError};
66use crate::handler::ensure_read_access;
7use crate::handler::RepoPath;
87use crate::service::GitService;
98use crate::service::pipelines::PipelineRunDto;
109use crate::share::errors::GitError;
Modified lib/git/src/handler/pipelines/list_runs.rs lib/git/src/handler/pipelines/list_runs.rs +2 −1 View lib/git/src/handler/pipelines/list_runs.rs
@@ -2,9 +2,10 @@
22use export::rest::AppResponseData;
33use session::Session;
44
5
56use crate::errors::{ApiError, GitApiError};
6use crate::handler::ensure_read_access;
77use crate::handler::RepoPath;
8use crate::handler::ensure_read_access;
89use crate::service::GitService;
910use crate::service::pipelines::PipelineRunDto;
1011use models::repo::pipeline_run::PipelineRunState;
Modified lib/git/src/handler/pipelines/schedule.rs lib/git/src/handler/pipelines/schedule.rs +1 −1 View lib/git/src/handler/pipelines/schedule.rs
@@ -1,6 +1,6 @@
11use axum::Json;
22use axum::extract::{Path, Query, State};
3use export::rest::{AppResponseData, NoData};
3use export::rest::AppResponseData;
44use session::Session;
55
66use crate::errors::{ApiError, GitApiError};
Modified lib/git/src/handler/repos/archive.rs lib/git/src/handler/repos/archive.rs +25 −3 View lib/git/src/handler/repos/archive.rs
@@ -8,8 +8,8 @@
88use crate::service::repos::RepoDto;
99
1010#[utoipa::path(
11 delete,
12 path = "/repos/{space_name}/{repo_name}",
11 post,
12 path = "/repos/{space_name}/{repo_name}/archive",
1313 tag = "repos",
1414 params(RepoPath),
1515 responses(
@@ -23,7 +23,29 @@
2323) -> Result<AppResponseData<RepoDto>, ApiError> {
2424 let caller = ensure_caller(&session)?;
2525 let out = service
26 .archive_repo(path.space_name, path.repo_name, caller)
26 .set_repo_archived(path.space_name, path.repo_name, caller, true)
27 .await
28 .map_err(GitApiError::from)?;
29 Ok(AppResponseData::ok(out))
30}
31
32#[utoipa::path(
33 post,
34 path = "/repos/{space_name}/{repo_name}/unarchive",
35 tag = "repos",
36 params(RepoPath),
37 responses(
38 (status = 200, description = "unarchive repo", body = AppResponseData<RepoDto>)
39 )
40)]
41pub async fn unarchive_repo(
42 State(service): State<GitService>,
43 session: Session,
44 Path(path): Path<RepoPath>,
45) -> Result<AppResponseData<RepoDto>, ApiError> {
46 let caller = ensure_caller(&session)?;
47 let out = service
48 .set_repo_archived(path.space_name, path.repo_name, caller, false)
2749 .await
2850 .map_err(GitApiError::from)?;
2951 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/tags/mod.rs lib/git/src/handler/tags/mod.rs +0 −1 View lib/git/src/handler/tags/mod.rs
@@ -2,4 +2,3 @@
22pub mod delete;
33pub mod get;
44pub mod list;
5pub mod verify;
Deleted lib/git/src/handler/tags/verify.rs lib/git/src/handler/tags/verify.rs +0 −56
@@ -1,56 +0,0 @@
1use axum::extract::{Path, State};
2use export::rest::AppResponseData;
3use serde::Serialize;
4use session::Session;
5
6use crate::errors::{ApiError, GitApiError};
7use crate::handler::resolve_reader;
8use crate::service::GitService;
9
10#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
11pub struct TagPath {
12 pub space_name: String,
13 pub repo_name: String,
14 pub name: String,
15}
16
17#[derive(Debug, Clone, Serialize, utoipa::ToSchema)]
18pub struct TagVerifyDto {
19 pub valid: bool,
20 pub signer: Option<String>,
21 pub fingerprint: Option<String>,
22 pub error_message: Option<String>,
23}
24
25#[utoipa::path(
26 get,
27 path = "/repos/{space_name}/{repo_name}/tags/{name}/verify",
28 tag = "tags",
29 params(TagPath),
30 responses(
31 (status = 200, description = "verify tag", body = AppResponseData<TagVerifyDto>)
32 )
33)]
34pub async fn verify_tag(
35 State(service): State<GitService>,
36 session: Session,
37 Path(path): Path<TagPath>,
38) -> Result<AppResponseData<TagVerifyDto>, ApiError> {
39 let _ = resolve_reader(
40 &service,
41 &session,
42 path.space_name.clone(),
43 path.repo_name.clone(),
44 )
45 .await?;
46 let out = service
47 .verify_tag(path.space_name, path.repo_name, path.name)
48 .await
49 .map_err(GitApiError::from)?;
50 Ok(AppResponseData::ok(TagVerifyDto {
51 valid: out.valid,
52 signer: out.signer,
53 fingerprint: out.fingerprint,
54 error_message: out.error_message,
55 }))
56}
Modified lib/git/src/handler/mod.rs lib/git/src/handler/mod.rs +0 −1 View lib/git/src/handler/mod.rs
@@ -12,7 +12,6 @@
1212pub mod html;
1313pub mod lfs;
1414pub mod licenses;
15pub mod logs;
1615pub mod maintenance;
1716pub mod packs;
1817pub mod patches;
Modified lib/git/src/service/commits.rs lib/git/src/service/commits.rs +8 −1 View lib/git/src/service/commits.rs
@@ -184,7 +184,14 @@
184184 let baby = self.baby(&ctx);
185185 let limit = cmd.max_count.unwrap_or(50);
186186 let skip = cmd.skip.unwrap_or(0);
187 let rev_oid = baby.rev_parse(&cmd.revision).await.map_err(map_baby)?;
187 let rev_key = if let Some((after, before)) = cmd.revision.split_once("..") {
188 let a = baby.rev_parse(after).await.map_err(map_baby)?;
189 let b = baby.rev_parse(before).await.map_err(map_baby)?;
190 format!("{a}..{b}")
191 } else {
192 baby.rev_parse(&cmd.revision).await.map_err(map_baby)?.to_string()
193 };
194 let rev_oid = rev_key.clone();
188195 let path_str = cmd
189196 .path
190197 .as_ref()
Modified lib/git/src/service/logs.rs lib/git/src/service/logs.rs +0 −20 View lib/git/src/service/logs.rs
@@ -134,24 +134,4 @@
134134 })
135135 .await
136136 }
137
138 /// Commit graph; `lanes` are placeholders (matching the reference impl).
139 pub async fn log_graph(
140 &self,
141 space_name: String,
142 repo_name: String,
143 opts: LogOptions,
144 ) -> Result<Vec<GraphNode>, GitError> {
145 let page = self
146 .log_list(space_name, repo_name, opts)
147 .await?
148 .commits
149 .into_iter()
150 .map(|commit| GraphNode {
151 commit,
152 lanes: Vec::new(),
153 })
154 .collect();
155 Ok(page)
156 }
157137}
Modified lib/git/src/service/pipelines.rs lib/git/src/service/pipelines.rs +1 −1 View lib/git/src/service/pipelines.rs
@@ -1,5 +1,5 @@
11use models::repo::pipeline_run::{self, PipelineRunState};
2use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, PaginatorTrait, QueryFilter, QueryOrder, QuerySelect, Set};
2use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, QueryOrder, QuerySelect, Set};
33use serde::{Deserialize, Serialize};
44use time::OffsetDateTime;
55use uuid::Uuid;
Modified lib/git/src/service/repos.rs lib/git/src/service/repos.rs +10 −5 View lib/git/src/service/repos.rs
@@ -478,25 +478,30 @@
478478 Ok(RepoDto::from(saved))
479479 }
480480
481 pub async fn archive_repo(
481 pub async fn set_repo_archived(
482482 &self,
483483 space_name: String,
484484 repo_name: String,
485485 caller: Uuid,
486 archived: bool,
486487 ) -> Result<RepoDto, GitError> {
487488 let ctx = self.context(space_name, repo_name).await?;
488489 let space = self.repo_space(&ctx).await?;
489490 if space.owner_id != caller {
490491 return Err(GitError::Forbidden);
491492 }
492 if ctx.model.is_archived {
493 return Err(GitError::Conflict("repo is already archived".to_string()));
493 if ctx.model.is_archived == archived {
494 return Err(GitError::Conflict(if archived {
495 "repo is already archived".to_string()
496 } else {
497 "repo is not archived".to_string()
498 }));
494499 }
495500 let now = OffsetDateTime::now_utc();
496501 let am = repos::ActiveModel {
497502 id: Unchanged(ctx.model.id),
498 is_archived: Set(true),
499 archived_at: Set(Some(now)),
503 is_archived: Set(archived),
504 archived_at: Set(archived.then_some(now)),
500505 updated_at: Set(now),
501506 ..Default::default()
502507 };
Modified lib/git/src/openapi.rs lib/git/src/openapi.rs +1 −7 View lib/git/src/openapi.rs
@@ -19,7 +19,6 @@
1919 handler::blobs::content::blob_content,
2020 handler::blobs::list_lfs_pointers::list_lfs_pointers,
2121 handler::blobs::metadata::blob_metadata,
22 handler::blobs::raw_download::blob_raw_download,
2322 handler::branches::create::create_branch,
2423 handler::branches::delete::delete_branch,
2524 handler::branches::get::get_branch,
@@ -54,10 +53,6 @@
5453 handler::lfs::unlock::unlock,
5554 handler::lfs::unlock_by_id::unlock_by_id,
5655 handler::lfs::verify_locks::verify_locks,
57 handler::logs::commits_between::log_commits_between,
58 handler::logs::graph::log_graph,
59 handler::logs::last_commit::log_last_commit,
60 handler::logs::list::log_list,
6156 handler::patches::generate::patch_generate,
6257 handler::patches::parse::patch_parse,
6358 handler::path_log::path_log,
@@ -71,6 +66,7 @@
7166 handler::remotes::push::push,
7267 handler::remotes::remove::remove,
7368 handler::repos::archive::archive_repo,
69 handler::repos::archive::unarchive_repo,
7470 handler::repos::create::create_repo,
7571 handler::repos::get::get_repo,
7672 handler::repos::list::list_repos,
@@ -87,7 +83,6 @@
8783 handler::tags::delete::delete_tag,
8884 handler::tags::get::get_tag,
8985 handler::tags::list::list_tags,
90 handler::tags::verify::verify_tag,
9186 handler::topics::add_topic_to_repo,
9287 handler::topics::create_topic,
9388 handler::topics::get_topic,
@@ -214,7 +209,6 @@
214209 crate::handler::remotes::fetch::RemoteFetchBody,
215210 crate::handler::remotes::push::RemotePushBody,
216211 crate::handler::stars::StarStatusResp,
217 crate::handler::tags::verify::TagVerifyDto,
218212 ))
219213)]
220214pub struct GitApiDoc;
Modified lib/git/src/routes.rs lib/git/src/routes.rs +3 −20 View lib/git/src/routes.rs
@@ -9,7 +9,6 @@
99use crate::handler::blobs::content::blob_content;
1010use crate::handler::blobs::list_lfs_pointers::list_lfs_pointers;
1111use crate::handler::blobs::metadata::blob_metadata;
12use crate::handler::blobs::raw_download::blob_raw_download as blob_raw;
1312use crate::handler::branches::create::create_branch as branch_create;
1413use crate::handler::branches::delete::delete_branch as branch_delete;
1514use crate::handler::branches::get::get_branch as branch_get;
@@ -50,10 +49,6 @@
5049use crate::handler::lfs::unlock_by_id::unlock_by_id;
5150use crate::handler::lfs::verify_locks::verify_locks;
5251use crate::handler::licenses::{get_license, list_licenses, upsert_license};
53use crate::handler::logs::commits_between::log_commits_between;
54use crate::handler::logs::graph::log_graph;
55use crate::handler::logs::last_commit::log_last_commit as log_last;
56use crate::handler::logs::list::log_list as log_list_handler;
5752use crate::handler::maintenance::fsck::fsck;
5853use crate::handler::maintenance::prune::prune;
5954use crate::handler::packs::ingest::ingest as pack_ingest;
@@ -83,7 +78,7 @@
8378use crate::handler::remotes::fetch::fetch as remote_fetch;
8479use crate::handler::remotes::push::push as remote_push;
8580use crate::handler::remotes::remove::remove as remote_remove;
86use crate::handler::repos::archive::archive_repo as repo_archive;
81use crate::handler::repos::archive::{archive_repo as repo_archive, unarchive_repo};
8782use crate::handler::repos::create::create_repo as repo_create;
8883use crate::handler::repos::get::get_repo as repo_get;
8984use crate::handler::repos::list::list_repos as repo_list;
@@ -97,7 +92,6 @@
9792use crate::handler::tags::delete::delete_tag as tag_delete;
9893use crate::handler::tags::get::get_tag as tag_get;
9994use crate::handler::tags::list::list_tags as tag_list;
100use crate::handler::tags::verify::verify_tag as tag_verify;
10195use crate::handler::topics::{
10296 add_topic_to_repo, create_topic, get_topic, list_repo_topics, list_repos_by_topic, list_topics,
10397 remove_topic_from_repo,
@@ -139,9 +133,10 @@
139133 .route("/{space_name}", post(repo_create).get(repo_list))
140134 .route(
141135 "/{space_name}/{repo_name}",
142 get(repo_get).patch(repo_update).delete(repo_archive),
136 get(repo_get).patch(repo_update),
143137 )
144138 .route("/{space_name}/{repo_name}/archive", post(repo_archive))
139 .route("/{space_name}/{repo_name}/unarchive", post(unarchive_repo))
145140 .route(
146141 "/{space_name}/{repo_name}/branches",
147142 get(branch_list).post(branch_create),
@@ -162,10 +157,6 @@
162157 "/{space_name}/{repo_name}/tags/{name}",
163158 get(tag_get).delete(tag_delete),
164159 )
165 .route(
166 "/{space_name}/{repo_name}/tags/{name}/verify",
167 get(tag_verify),
168 )
169160 .route("/{space_name}/{repo_name}/commits", get(list_commits))
170161 .route(
171162 "/{space_name}/{repo_name}/commits/{revision}",
@@ -189,13 +180,6 @@
189180 "/{space_name}/{repo_name}/commit-statuses/{sha}",
190181 get(list_commit_statuses),
191182 )
192 .route("/{space_name}/{repo_name}/logs", get(log_list_handler))
193 .route(
194 "/{space_name}/{repo_name}/logs/between",
195 get(log_commits_between),
196 )
197 .route("/{space_name}/{repo_name}/logs/last", get(log_last))
198 .route("/{space_name}/{repo_name}/logs/graph", get(log_graph))
199183 .route("/{space_name}/{repo_name}/path-log", get(path_log))
200184 .route(
201185 "/{space_name}/{repo_name}/blobs/{oid}/metadata",
@@ -205,7 +189,6 @@
205189 "/{space_name}/{repo_name}/blobs/{oid}/content",
206190 get(blob_content),
207191 )
208 .route("/{space_name}/{repo_name}/blobs/{oid}/raw", get(blob_raw))
209192 .route(
210193 "/{space_name}/{repo_name}/lfs-pointers",
211194 get(list_lfs_pointers),