use serde::{Deserialize, Serialize}; use crate::{ error::{OperationError, RepositoryError}, object::Object, object_backend::ObjectBackend, operation::GiteratedOperation, }; use super::{ Commit, IssueLabel, Repository, RepositoryDiff, RepositoryFile, 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 { pub extra_metadata: bool, pub rev: Option, pub path: Option, } impl GiteratedOperation for RepositoryInfoRequest { type Success = RepositoryView; type Failure = RepositoryError; } /// A request to get a file from a repository using the given id. /// /// # 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 RepositoryFileFromIdRequest(pub String); impl GiteratedOperation for RepositoryFileFromIdRequest { type Success = RepositoryFile; type Failure = RepositoryError; } /// A request to get the difference between two repository trees. /// /// # 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 RepositoryDiffRequest { pub old_id: String, pub new_id: String, } impl GiteratedOperation for RepositoryDiffRequest { type Success = RepositoryDiff; type Failure = RepositoryError; } /// A request to get the commit before the one with the passed id /// /// # 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 RepositoryCommitBeforeRequest(pub String); impl GiteratedOperation for RepositoryCommitBeforeRequest { type Success = Commit; 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 { /// Whether to get extra metadata for every entry (file mode, size and last commit made to it). pub extra_metadata: bool, /// Revision of the repository to get (branch, commit id). pub rev: Option, /// If not given a path, it'll default to the base. pub path: Option, } impl GiteratedOperation for RepositoryFileInspectRequest { type Success = Vec; type Failure = RepositoryError; } impl + std::fmt::Debug> Object<'_, S, Repository, B> { pub async fn info( &mut self, extra_metadata: bool, rev: Option, path: Option, operation_state: &S, ) -> Result> { self.request::( RepositoryInfoRequest { extra_metadata, rev, path, }, operation_state, ) .await } pub async fn file_from_id( &mut self, id: String, operation_state: &S, ) -> Result> { self.request::( RepositoryFileFromIdRequest(id), operation_state, ) .await } pub async fn diff( &mut self, old_id: String, new_id: String, operation_state: &S, ) -> Result> { self.request::( RepositoryDiffRequest { old_id, new_id }, operation_state, ) .await } pub async fn commit_before( &mut self, id: String, operation_state: &S, ) -> Result> { self.request::( RepositoryCommitBeforeRequest(id), operation_state, ) .await } // pub async fn issues_count(&mut self) -> Result> { // self.request::(RepositoryIssuesCountRequest) // .await // } pub async fn issue_labels( &mut self, operation_state: &S, ) -> Result, OperationError> { self.request::(RepositoryIssueLabelsRequest, operation_state) .await } pub async fn issues( &mut self, operation_state: &S, ) -> Result, OperationError> { self.request::(RepositoryIssuesRequest, operation_state) .await } pub async fn inspect_files( &mut self, extra_metadata: bool, rev: Option<&str>, path: Option<&str>, operation_state: &S, ) -> Result, OperationError> { self.request::( RepositoryFileInspectRequest { extra_metadata, rev: rev.map(|r| r.to_string()), path: path.map(|p| p.to_string()), }, operation_state, ) .await } }