use super::*; /// Repository operations. impl Forgejo { /// Gets info about the specified repository. pub async fn get_repo(&self, user: &str, repo: &str) -> Result, ForgejoError> { self.get_opt(&format!("repos/{user}/{repo}/")).await } /// Creates a repository. pub async fn create_repo(&self, repo: CreateRepoOption) -> Result { self.post("user/repos", &repo).await } pub async fn get_pulls( &self, owner: &str, repo: &str, query: PullQuery, ) -> Result, ForgejoError> { self.get(&query.to_string(owner, repo)).await } pub async fn create_pr( &self, owner: &str, repo: &str, opts: CreatePullRequestOption, ) -> Result { self.post(&format!("repos/{owner}/{repo}/pulls"), &opts) .await } pub async fn is_merged(&self, owner: &str, repo: &str, pr: u64) -> Result { self.get_opt::<()>(&format!("repos/{owner}/{repo}/pulls/{pr}/merge")) .await .map(|o| o.is_some()) } pub async fn merge_pr( &self, owner: &str, repo: &str, pr: u64, opts: MergePullRequestOption, ) -> Result<(), ForgejoError> { self.post(&format!("repos/{owner}/{repo}/pulls/{pr}/merge"), &opts) .await } pub async fn cancel_merge(&self, owner: &str, repo: &str, pr: u64) -> Result<(), ForgejoError> { self.delete(&format!("repos/{owner}/{repo}/pulls/{pr}/merge")) .await } pub async fn get_releases( &self, owner: &str, repo: &str, query: ReleaseQuery, ) -> Result, ForgejoError> { self.get(&query.to_string(owner, repo)).await } pub async fn get_release( &self, owner: &str, repo: &str, id: u64, ) -> Result, ForgejoError> { self.get_opt(&format!("repos/{owner}/{repo}/releases/{id}")) .await } pub async fn get_release_by_tag( &self, owner: &str, repo: &str, tag: &str, ) -> Result, ForgejoError> { self.get_opt(&format!("repos/{owner}/{repo}/releases/tags/{tag}")) .await } pub async fn delete_release( &self, owner: &str, repo: &str, id: u64, ) -> Result<(), ForgejoError> { self.delete(&format!("repos/{owner}/{repo}/releases/{id}")) .await } pub async fn delete_release_by_tag( &self, owner: &str, repo: &str, tag: &str, ) -> Result<(), ForgejoError> { self.delete(&format!("repos/{owner}/{repo}/releases/tags/{tag}")) .await } pub async fn edit_release( &self, owner: &str, repo: &str, id: u64, opts: EditReleaseOption, ) -> Result { self.patch(&format!("repos/{owner}/{repo}/releases/{id}"), &opts) .await } pub async fn get_release_attachments( &self, owner: &str, repo: &str, id: u64, ) -> Result, ForgejoError> { self.get(&format!("repos/{owner}/{repo}/releases/{id}/assets")) .await } pub async fn get_release_attachment( &self, owner: &str, repo: &str, release_id: u64, attachment_id: u64, ) -> Result { self.get(&format!( "repos/{owner}/{repo}/releases/{release_id}/assets/{attachment_id}" )) .await } pub async fn create_release_attachment( &self, owner: &str, repo: &str, id: u64, name: &str, file: &[u8], ) -> Result { self.post_form( &format!("repos/{owner}/{repo}/releases/{id}/assets?name={name}"), &file, ) .await } pub async fn delete_release_attachment( &self, owner: &str, repo: &str, release_id: u64, attachment_id: u64, ) -> Result<(), ForgejoError> { self.delete(&format!( "repos/{owner}/{repo}/releases/{release_id}/assets/{attachment_id}" )) .await } pub async fn edit_release_attachment( &self, owner: &str, repo: &str, release_id: u64, attachment_id: u64, opts: EditAttachmentOption, ) -> Result { self.patch( &format!("repos/{owner}/{repo}/releases/{release_id}/assets/{attachment_id}"), &opts, ) .await } pub async fn create_release( &self, owner: &str, repo: &str, opts: CreateReleaseOption, ) -> Result { self.post(&format!("repos/{owner}/{repo}/releases"), &opts) .await } pub async fn latest_release( &self, owner: &str, repo: &str, ) -> Result, ForgejoError> { self.get_opt(&format!("repos/{owner}/{repo}/releases/latest")) .await } pub async fn get_tags(&self, owner: &str, repo: &str, query: TagQuery) -> Result, ForgejoError> { self.get(&query.to_string(owner, repo)).await } pub async fn create_tag(&self, owner: &str, repo: &str, opts: CreateTagOption) -> Result { self.post(&format!("repos/{owner}/{repo}/tags"), &opts).await } pub async fn get_tag(&self, owner: &str, repo: &str, tag: &str) -> Result, ForgejoError> { self.get_opt(&format!("repos/{owner}/{repo}/tags/{tag}")).await } pub async fn delete_tag(&self, owner: &str, repo: &str, tag: &str) -> Result<(), ForgejoError> { self.delete(&format!("repos/{owner}/{repo}/tags/{tag}")).await } } #[derive(serde::Deserialize, Debug, PartialEq)] pub struct Repository { pub allow_merge_commits: bool, pub allow_rebase: bool, pub allow_rebase_explicit: bool, pub allow_rebase_update: bool, pub allow_squash_merge: bool, pub archived: bool, #[serde(with = "time::serde::rfc3339::option")] pub archived_at: Option, #[serde(deserialize_with = "crate::none_if_blank_url")] pub avatar_url: Option, pub clone_url: Url, #[serde(with = "time::serde::rfc3339")] pub created_at: time::OffsetDateTime, pub default_allow_maintainer_edit: bool, pub default_branch: String, pub default_delete_branch_after_merge: bool, pub default_merge_style: String, pub description: String, pub empty: bool, pub external_tracker: Option, pub external_wiki: Option, pub fork: bool, pub forks_count: u64, pub full_name: String, pub has_actions: bool, pub has_issues: bool, pub has_packages: bool, pub has_projects: bool, pub has_pull_request: bool, pub has_releases: bool, pub has_wiki: bool, pub html_url: Url, pub id: u64, pub ignore_whitespace_conflicts: bool, pub internal: bool, pub internal_tracker: Option, pub language: String, pub languages_url: Url, pub link: String, pub mirror: bool, pub mirror_interval: Option, #[serde(with = "time::serde::rfc3339::option")] pub mirror_updated: Option, pub name: String, pub open_issue_count: u64, pub open_pr_counter: u64, #[serde(deserialize_with = "crate::none_if_blank_url")] pub original_url: Option, pub owner: User, pub permissions: Permission, pub private: bool, pub release_counter: u64, pub repo_transfer: Option, pub size: u64, pub ssh_url: String, pub starts_count: u64, pub template: bool, #[serde(with = "time::serde::rfc3339")] pub updated_at: time::OffsetDateTime, pub url: Url, pub watchers_count: u64, pub website: Option, } #[derive(serde::Deserialize, Debug, PartialEq)] pub struct RepositoryMeta { pub full_name: String, pub id: u64, pub name: String, pub owner: String, } #[derive(serde::Serialize, Debug, PartialEq)] pub struct CreateRepoOption { pub auto_init: bool, pub default_branch: String, pub description: Option, pub gitignores: String, pub issue_labels: String, pub license: String, pub name: String, pub private: bool, pub readme: String, pub template: bool, pub trust_model: TrustModel, } #[derive(serde::Serialize, Debug, PartialEq)] pub enum TrustModel { Default, Collaborator, Committer, #[serde(rename = "collaboratorcommiter")] CollaboratorCommitter, } #[derive(serde::Deserialize, Debug, PartialEq)] pub struct Milestone { #[serde(with = "time::serde::rfc3339::option")] pub closed_at: Option, pub closed_issues: u64, #[serde(with = "time::serde::rfc3339")] pub created_at: time::OffsetDateTime, pub description: String, #[serde(with = "time::serde::rfc3339::option")] pub due_on: Option, pub id: u64, pub open_issues: u64, pub state: State, pub title: String, #[serde(with = "time::serde::rfc3339")] pub updated_at: time::OffsetDateTime, } #[derive(serde::Deserialize, Debug, PartialEq)] pub struct PullRequest { pub allow_maintainer_edit: bool, pub assignee: User, pub assignees: Vec, pub base: PrBranchInfo, pub body: String, #[serde(with = "time::serde::rfc3339::option")] pub closed_at: Option, pub comments: u64, #[serde(with = "time::serde::rfc3339")] pub created_at: time::OffsetDateTime, pub diff_url: Url, #[serde(with = "time::serde::rfc3339::option")] pub due_date: Option, pub head: PrBranchInfo, pub html_url: Url, pub id: u64, pub is_locked: bool, pub labels: Vec