use serde::{Deserialize, Serialize}; use crate::{ error::{OperationError, RepositoryError}, object::Object, object_backend::ObjectBackend, operation::GiteratedOperation, }; use super::{IssueLabel, Repository, RepositoryIssue, RepositoryTreeEntry, RepositoryView}; /// A request to get a repository's information. /// /// # Authentication /// - Instance Authentication /// - Validate request against the `issued_for` public key /// - Validate User token against the user's instance's public key /// # Authorization /// - User Authorization /// - Potential User permissions checks #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RepositoryInfoRequest; impl GiteratedOperation for RepositoryInfoRequest { type Success = RepositoryView; type Failure = RepositoryError; } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RepositoryIssuesCountRequest; impl GiteratedOperation for RepositoryIssuesCountRequest { type Success = u64; type Failure = RepositoryError; } /// A request to get a repository's issues count. /// /// # Authentication /// - Instance Authentication /// - Validate request against the `issued_for` public key /// - Validate User token against the user's instance's public key /// # Authorization /// - User Authorization /// - Potential User permissions checks #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RepositoryIssueLabelsRequest; impl GiteratedOperation for RepositoryIssueLabelsRequest { type Success = Vec; type Failure = RepositoryError; } /// A request to get a repository's issue labels. /// /// # Authentication /// - Instance Authentication /// - Validate request against the `issued_for` public key /// - Validate User token against the user's instance's public key /// # Authorization /// - User Authorization /// - Potential User permissions checks #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RepositoryIssuesRequest; impl GiteratedOperation for RepositoryIssuesRequest { type Success = Vec; type Failure = RepositoryError; } /// A request to inspect the tree of a repository. /// /// # Authentication /// - Instance Authentication /// - Validate request against the `issued_for` public key /// - Validate User token against the user's instance's public key /// # Authorization /// - User Authorization /// - Potential User permissions checks #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RepositoryFileInspectRequest { pub path: RepositoryTreeEntry, } impl GiteratedOperation for RepositoryFileInspectRequest { type Success = Vec; type Failure = RepositoryError; } impl Object<'_, Repository, B> { pub async fn info(&mut self) -> Result> { self.request::(RepositoryInfoRequest) .await } // pub async fn issues_count(&mut self) -> Result> { // self.request::(RepositoryIssuesCountRequest) // .await // } pub async fn issue_labels( &mut self, ) -> Result, OperationError> { self.request::(RepositoryIssueLabelsRequest) .await } pub async fn issues( &mut self, ) -> Result, OperationError> { self.request::(RepositoryIssuesRequest) .await } pub async fn inspect_files( &mut self, entry: &RepositoryTreeEntry, ) -> Result, OperationError> { self.request::(RepositoryFileInspectRequest { path: entry.clone(), }) .await } }