diff --git a/src/repository.rs b/src/repository.rs index c56f350..b35e797 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -197,6 +197,22 @@ impl Forgejo { 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)] @@ -515,3 +531,43 @@ fn opt_bool_s(b: Option) -> &'static str { None => "", } } + +#[derive(serde::Deserialize, Debug, PartialEq)] +pub struct Tag { + pub commit: CommitMeta, + pub id: String, + pub message: String, + pub name: String, + pub tarball_url: Url, + pub zipball_url: Url, +} + +#[derive(serde::Serialize, Debug, PartialEq, Default)] +pub struct CreateTagOption { + pub message: Option, + pub tag_name: String, + pub target: Option, +} + +#[derive(Default, Debug)] +pub struct TagQuery { + pub page: Option, + pub limit: Option, +} + +impl TagQuery { + fn to_string(&self, owner: &str, repo: &str) -> String { + format!("repos/{owner}/{repo}/tags?page={}&limit={}", + self.page.map(|page| page.to_string()).unwrap_or_default(), + self.limit.map(|page| page.to_string()).unwrap_or_default(), + ) + } +} + +#[derive(serde::Deserialize, Debug, PartialEq)] +pub struct CommitMeta { + #[serde(with = "time::serde::rfc3339")] + pub created: time::OffsetDateTime, + pub url: Url, + pub sha: String, +}