use serde::{Deserialize, Serialize}; use crate::{ error::{OperationError, RepositoryError}, object::Object, object_backend::ObjectBackend, operation::GiteratedOperation, }; use super::{ Commit, IssueLabel, Repository, RepositoryBranch, RepositoryBranchFilter, RepositoryDiff, RepositoryFile, RepositoryIssue, RepositoryStatistics, 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 a file from a repository using the given relative path. /// Also returns the commit id of the rev. /// /// # 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 RepositoryFileFromPathRequest { pub rev: Option, pub path: String, } impl GiteratedOperation for RepositoryFileFromPathRequest { type Success = (RepositoryFile, String); type Failure = RepositoryError; } /// A request to get the last commit made to a file, using a starting point and the path. /// /// # 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 RepositoryLastCommitOfFileRequest { /// ID of commit to start at pub start_commit: String, // Path of the file pub path: String, } impl GiteratedOperation for RepositoryLastCommitOfFileRequest { type Success = Commit; type Failure = RepositoryError; } /// A request to get the commit by the specified 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 RepositoryCommitFromIdRequest(pub String); impl GiteratedOperation for RepositoryCommitFromIdRequest { type Success = Commit; 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 difference between two repository trees as a unified git patch. /// /// # 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 RepositoryDiffPatchRequest { pub old_id: String, pub new_id: String, } impl GiteratedOperation for RepositoryDiffPatchRequest { type Success = String; 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; } /// A request to get the statistics of 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 RepositoryStatisticsRequest { /// Revision of the repository to get (branch, commit id). pub rev: Option, } impl GiteratedOperation for RepositoryStatisticsRequest { type Success = RepositoryStatistics; type Failure = RepositoryError; } /// A request to get a list of branches in the repository. /// Also returns the total amount of branches after the filter is applied. /// /// Optional search parameter that'll search through the filtered branches /// /// Skips over references with invalid UTF-8 names. /// /// # 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 RepositoryBranchesRequest { pub filter: RepositoryBranchFilter, pub range: (usize, usize), // pub sort: Option pub search: Option, } impl GiteratedOperation for RepositoryBranchesRequest { type Success = (Vec, usize); 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 file_from_path( &mut self, rev: Option, path: String, operation_state: &S, ) -> Result<(RepositoryFile, String), OperationError> { self.request::( RepositoryFileFromPathRequest { rev, path }, operation_state, ) .await } pub async fn last_commit_of_file( &mut self, start_commit: String, path: String, operation_state: &S, ) -> Result> { self.request::( RepositoryLastCommitOfFileRequest { start_commit, path }, operation_state, ) .await } pub async fn commit_by_id( &mut self, id: String, operation_state: &S, ) -> Result> { self.request::( RepositoryCommitFromIdRequest(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 diff_patch( &mut self, old_id: String, new_id: String, operation_state: &S, ) -> Result> { self.request::( RepositoryDiffPatchRequest { 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 statistics( &mut self, rev: Option, operation_state: &S, ) -> Result> { self.request::( RepositoryStatisticsRequest { rev }, operation_state, ) .await } pub async fn branches( &mut self, filter: RepositoryBranchFilter, range_start: usize, range_end: usize, search: Option, operation_state: &S, ) -> Result<(Vec, usize), OperationError> { self.request::( RepositoryBranchesRequest { filter, range: (range_start, range_end), search, }, 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 } }