JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Add RepositorySummary and return in user repositories

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨8512ab4

Showing ⁨⁨7⁩ changed files⁩ with ⁨⁨41⁩ insertions⁩ and ⁨⁨16⁩ deletions⁩

Cargo.lock

View file
@@ -629,7 +629,7 @@ dependencies = [
629 629
630 630 [[package]]
631 631 name = "giterated-daemon"
632 version = "0.0.4"
632 version = "0.0.5"
633 633 dependencies = [
634 634 "aes-gcm",
635 635 "anyhow",

Cargo.toml

View file
@@ -1,6 +1,6 @@
1 1 [package]
2 2 name = "giterated-daemon"
3 version = "0.0.4"
3 version = "0.0.5"
4 4 edition = "2021"
5 5
6 6 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/backend/git.rs

View file
@@ -10,7 +10,8 @@ use crate::messages::ValidatedUserAuthenticated;
10 10
11 11 use crate::model::instance::Instance;
12 12 use crate::model::repository::{
13 Commit, Repository, RepositoryObjectType, RepositoryTreeEntry, RepositoryVisibility,
13 Commit, Repository, RepositoryObjectType, RepositorySummary, RepositoryTreeEntry,
14 RepositoryVisibility,
14 15 };
15 16 use crate::model::user::User;
16 17 use crate::{
@@ -452,7 +453,10 @@ impl RepositoryBackend for GitBackend {
452 453 todo!()
453 454 }
454 455
455 async fn repositories_for_user(&mut self, user: &User) -> Result<Vec<Repository>, Error> {
456 async fn repositories_for_user(
457 &mut self,
458 user: &User,
459 ) -> Result<Vec<RepositorySummary>, Error> {
456 460 let mut repositories = sqlx::query_as!(
457 461 GitRepository,
458 462 r#"SELECT visibility as "visibility: _", owner_user, name, description, default_branch FROM repositories WHERE owner_user = $1"#,
@@ -463,10 +467,17 @@ impl RepositoryBackend for GitBackend {
463 467 let mut result = vec![];
464 468
465 469 while let Some(Ok(Either::Right(repository))) = repositories.next().await {
466 result.push(Repository {
467 owner: repository.owner_user,
468 name: repository.name,
469 instance: self.instance.clone(),
470 result.push(RepositorySummary {
471 repository: Repository {
472 owner: repository.owner_user.clone(),
473 name: repository.name,
474 instance: self.instance.clone(),
475 },
476 owner: repository.owner_user.clone(),
477 visibility: repository.visibility,
478 description: repository.description,
479 // TODO
480 last_commit: None,
470 481 });
471 482 }
472 483

src/backend/mod.rs

View file
@@ -26,7 +26,7 @@ use crate::{
26 26 ValidatedUserAuthenticated,
27 27 },
28 28 model::{
29 repository::{Repository, RepositoryView},
29 repository::{Repository, RepositorySummary, RepositoryView},
30 30 user::User,
31 31 },
32 32 };
@@ -45,7 +45,8 @@ pub trait RepositoryBackend: IssuesBackend {
45 45 &mut self,
46 46 request: &ValidatedUserAuthenticated<RepositoryFileInspectRequest>,
47 47 ) -> Result<RepositoryFileInspectionResponse, Error>;
48 async fn repositories_for_user(&mut self, user: &User) -> Result<Vec<Repository>, Error>;
48 async fn repositories_for_user(&mut self, user: &User)
49 -> Result<Vec<RepositorySummary>, Error>;
49 50 }
50 51
51 52 pub trait IssuesBackend {

src/lib.rs

View file
@@ -18,7 +18,7 @@ pub fn version() -> Version {
18 18 }
19 19
20 20 pub fn validate_version(other: &Version) -> bool {
21 let version_req = VersionReq::from_str("=0.0.4").unwrap();
21 let version_req = VersionReq::from_str("=0.0.5").unwrap();
22 22
23 23 version_req.matches(other)
24 24 }

src/messages/user.rs

View file
@@ -1,6 +1,10 @@
1 1 use serde::{Deserialize, Serialize};
2 2
3 use crate::model::{instance::Instance, repository::Repository, user::User};
3 use crate::model::{
4 instance::Instance,
5 repository::{Repository, RepositorySummary},
6 user::User,
7 };
4 8
5 9 #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
6 10 pub struct UserMessage {
@@ -67,5 +71,5 @@ pub struct UserRepositoriesRequest {
67 71
68 72 #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
69 73 pub struct UserRepositoriesResponse {
70 pub repositories: Vec<Repository>,
74 pub repositories: Vec<RepositorySummary>,
71 75 }

src/model/repository.rs

View file
@@ -61,7 +61,7 @@ impl FromStr for Repository {
61 61 }
62 62
63 63 /// Visibility of the repository to the general eye
64 #[derive(Debug, Hash, Serialize, Deserialize, Clone, sqlx::Type)]
64 #[derive(PartialEq, Eq, Debug, Hash, Serialize, Deserialize, Clone, sqlx::Type)]
65 65 #[sqlx(type_name = "visibility", rename_all = "lowercase")]
66 66 pub enum RepositoryVisibility {
67 67 Public,
@@ -133,7 +133,7 @@ pub struct RepositoryTreeEntryWithCommit {
133 133 }
134 134
135 135 /// Info about a git commit
136 #[derive(Debug, Clone, Serialize, Deserialize)]
136 #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
137 137 pub struct Commit {
138 138 /// Unique commit ID
139 139 pub oid: String,
@@ -161,7 +161,7 @@ impl From<git2::Commit<'_>> for Commit {
161 161 }
162 162
163 163 /// Git commit signature
164 #[derive(Debug, Clone, Serialize, Deserialize)]
164 #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
165 165 pub struct CommitSignature {
166 166 pub name: Option<String>,
167 167 pub email: Option<String>,
@@ -178,3 +178,12 @@ impl From<git2::Signature<'_>> for CommitSignature {
178 178 }
179 179 }
180 180 }
181
182 #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
183 pub struct RepositorySummary {
184 pub repository: Repository,
185 pub owner: User,
186 pub visibility: RepositoryVisibility,
187 pub description: Option<String>,
188 pub last_commit: Option<Commit>,
189 }