diff --git a/Cargo.lock b/Cargo.lock index f855651..db3e428 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -629,7 +629,7 @@ dependencies = [ [[package]] name = "giterated-daemon" -version = "0.0.4" +version = "0.0.5" dependencies = [ "aes-gcm", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 5ff963a..0024ba0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "giterated-daemon" -version = "0.0.4" +version = "0.0.5" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/backend/git.rs b/src/backend/git.rs index 8c4212d..06a7559 100644 --- a/src/backend/git.rs +++ b/src/backend/git.rs @@ -10,7 +10,8 @@ use crate::messages::ValidatedUserAuthenticated; use crate::model::instance::Instance; use crate::model::repository::{ - Commit, Repository, RepositoryObjectType, RepositoryTreeEntry, RepositoryVisibility, + Commit, Repository, RepositoryObjectType, RepositorySummary, RepositoryTreeEntry, + RepositoryVisibility, }; use crate::model::user::User; use crate::{ @@ -452,7 +453,10 @@ impl RepositoryBackend for GitBackend { todo!() } - async fn repositories_for_user(&mut self, user: &User) -> Result, Error> { + async fn repositories_for_user( + &mut self, + user: &User, + ) -> Result, Error> { let mut repositories = sqlx::query_as!( GitRepository, 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 { let mut result = vec![]; while let Some(Ok(Either::Right(repository))) = repositories.next().await { - result.push(Repository { - owner: repository.owner_user, - name: repository.name, - instance: self.instance.clone(), + result.push(RepositorySummary { + repository: Repository { + owner: repository.owner_user.clone(), + name: repository.name, + instance: self.instance.clone(), + }, + owner: repository.owner_user.clone(), + visibility: repository.visibility, + description: repository.description, + // TODO + last_commit: None, }); } diff --git a/src/backend/mod.rs b/src/backend/mod.rs index cdf7676..8624fdf 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -26,7 +26,7 @@ use crate::{ ValidatedUserAuthenticated, }, model::{ - repository::{Repository, RepositoryView}, + repository::{Repository, RepositorySummary, RepositoryView}, user::User, }, }; @@ -45,7 +45,8 @@ pub trait RepositoryBackend: IssuesBackend { &mut self, request: &ValidatedUserAuthenticated, ) -> Result; - async fn repositories_for_user(&mut self, user: &User) -> Result, Error>; + async fn repositories_for_user(&mut self, user: &User) + -> Result, Error>; } pub trait IssuesBackend { diff --git a/src/lib.rs b/src/lib.rs index d8442f6..de968ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,7 @@ pub fn version() -> Version { } pub fn validate_version(other: &Version) -> bool { - let version_req = VersionReq::from_str("=0.0.4").unwrap(); + let version_req = VersionReq::from_str("=0.0.5").unwrap(); version_req.matches(other) } diff --git a/src/messages/user.rs b/src/messages/user.rs index bf34fd8..77cc030 100644 --- a/src/messages/user.rs +++ b/src/messages/user.rs @@ -1,6 +1,10 @@ use serde::{Deserialize, Serialize}; -use crate::model::{instance::Instance, repository::Repository, user::User}; +use crate::model::{ + instance::Instance, + repository::{Repository, RepositorySummary}, + user::User, +}; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct UserMessage { @@ -67,5 +71,5 @@ pub struct UserRepositoriesRequest { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct UserRepositoriesResponse { - pub repositories: Vec, + pub repositories: Vec, } diff --git a/src/model/repository.rs b/src/model/repository.rs index a68dea3..d7e4b1f 100644 --- a/src/model/repository.rs +++ b/src/model/repository.rs @@ -61,7 +61,7 @@ impl FromStr for Repository { } /// Visibility of the repository to the general eye -#[derive(Debug, Hash, Serialize, Deserialize, Clone, sqlx::Type)] +#[derive(PartialEq, Eq, Debug, Hash, Serialize, Deserialize, Clone, sqlx::Type)] #[sqlx(type_name = "visibility", rename_all = "lowercase")] pub enum RepositoryVisibility { Public, @@ -133,7 +133,7 @@ pub struct RepositoryTreeEntryWithCommit { } /// Info about a git commit -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] pub struct Commit { /// Unique commit ID pub oid: String, @@ -161,7 +161,7 @@ impl From> for Commit { } /// Git commit signature -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] pub struct CommitSignature { pub name: Option, pub email: Option, @@ -178,3 +178,12 @@ impl From> for CommitSignature { } } } + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct RepositorySummary { + pub repository: Repository, + pub owner: User, + pub visibility: RepositoryVisibility, + pub description: Option, + pub last_commit: Option, +}