summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2023-12-12 03:40:23 +0100
committerCyborus <cyborus@cyborus.xyz>2023-12-12 03:40:23 +0100
commit051f18eddcd4333584b1ec9f68f215e534006f47 (patch)
tree847a378ef7fbd537b50e7bcc1ca89e4ca474406e
parentMerge pull request 'test repository methods' (#24) from repo-tests into main (diff)
downloadforgejo-api-051f18eddcd4333584b1ec9f68f215e534006f47.tar.xz
forgejo-api-051f18eddcd4333584b1ec9f68f215e534006f47.zip
praise rustfmt
-rw-r--r--src/lib.rs79
-rw-r--r--src/misc.rs10
-rw-r--r--src/notification.rs80
-rw-r--r--src/organization.rs2
-rw-r--r--src/package.rs94
-rw-r--r--src/repository.rs52
-rw-r--r--tests/ci_test.rs124
7 files changed, 322 insertions, 119 deletions
diff --git a/src/lib.rs b/src/lib.rs
index bb0bd74..d9e8179 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -8,19 +8,19 @@ pub struct Forgejo {
client: Client,
}
+mod issue;
mod misc;
mod notification;
mod organization;
mod package;
-mod issue;
mod repository;
mod user;
+pub use issue::*;
pub use misc::*;
pub use notification::*;
pub use organization::*;
pub use package::*;
-pub use issue::*;
pub use repository::*;
pub use user::*;
@@ -124,21 +124,13 @@ impl Forgejo {
self.execute_str(request).await
}
- async fn post_unit<T: Serialize>(
- &self,
- path: &str,
- body: &T,
- ) -> Result<(), ForgejoError> {
+ async fn post_unit<T: Serialize>(&self, path: &str, body: &T) -> Result<(), ForgejoError> {
let url = self.url.join("api/v1/").unwrap().join(path).unwrap();
let request = self.client.post(url).json(body).build()?;
self.execute_unit(request).await
}
- async fn post_raw(
- &self,
- path: &str,
- body: String,
- ) -> Result<String, ForgejoError> {
+ async fn post_raw(&self, path: &str, body: String) -> Result<String, ForgejoError> {
let url = self.url.join("api/v1/").unwrap().join(path).unwrap();
let request = self.client.post(url).body(body).build()?;
self.execute_str(request).await
@@ -171,12 +163,17 @@ impl Forgejo {
match response.status() {
status if status.is_success() => {
let body = response.text().await?;
- let out = serde_json::from_str(&body).map_err(|e| ForgejoError::BadStructure(e, body))?;
+ let out =
+ serde_json::from_str(&body).map_err(|e| ForgejoError::BadStructure(e, body))?;
Ok(out)
- },
+ }
status if status.is_client_error() => Err(ForgejoError::ApiError(
status,
- response.json::<ErrorMessage>().await?.message.unwrap_or_else(|| String::from("[no message]")),
+ response
+ .json::<ErrorMessage>()
+ .await?
+ .message
+ .unwrap_or_else(|| String::from("[no message]")),
)),
status => Err(ForgejoError::UnexpectedStatusCode(status)),
}
@@ -189,7 +186,11 @@ impl Forgejo {
status if status.is_success() => Ok(response.text().await?),
status if status.is_client_error() => Err(ForgejoError::ApiError(
status,
- response.json::<ErrorMessage>().await?.message.unwrap_or_else(|| String::from("[no message]")),
+ response
+ .json::<ErrorMessage>()
+ .await?
+ .message
+ .unwrap_or_else(|| String::from("[no message]")),
)),
status => Err(ForgejoError::UnexpectedStatusCode(status)),
}
@@ -202,7 +203,11 @@ impl Forgejo {
status if status.is_success() => Ok(()),
status if status.is_client_error() => Err(ForgejoError::ApiError(
status,
- response.json::<ErrorMessage>().await?.message.unwrap_or_else(|| String::from("[no message]")),
+ response
+ .json::<ErrorMessage>()
+ .await?
+ .message
+ .unwrap_or_else(|| String::from("[no message]")),
)),
status => Err(ForgejoError::UnexpectedStatusCode(status)),
}
@@ -217,30 +222,36 @@ impl Forgejo {
match response.status() {
status if status.is_success() => {
let body = response.text().await?;
- let out = serde_json::from_str(&body).map_err(|e| ForgejoError::BadStructure(e, body))?;
+ let out =
+ serde_json::from_str(&body).map_err(|e| ForgejoError::BadStructure(e, body))?;
Ok(out)
- },
+ }
StatusCode::NOT_FOUND => Ok(None),
status if status.is_client_error() => Err(ForgejoError::ApiError(
status,
- response.json::<ErrorMessage>().await?.message.unwrap_or_else(|| String::from("[no message]")),
+ response
+ .json::<ErrorMessage>()
+ .await?
+ .message
+ .unwrap_or_else(|| String::from("[no message]")),
)),
status => Err(ForgejoError::UnexpectedStatusCode(status)),
}
}
/// Like `execute`, but returns `false` on 404.
- async fn execute_exists(
- &self,
- request: Request,
- ) -> Result<bool, ForgejoError> {
+ async fn execute_exists(&self, request: Request) -> Result<bool, ForgejoError> {
let response = self.client.execute(request).await?;
match response.status() {
status if status.is_success() => Ok(true),
StatusCode::NOT_FOUND => Ok(false),
status if status.is_client_error() => Err(ForgejoError::ApiError(
status,
- response.json::<ErrorMessage>().await?.message.unwrap_or_else(|| String::from("[no message]")),
+ response
+ .json::<ErrorMessage>()
+ .await?
+ .message
+ .unwrap_or_else(|| String::from("[no message]")),
)),
status => Err(ForgejoError::UnexpectedStatusCode(status)),
}
@@ -256,14 +267,15 @@ struct ErrorMessage {
// Forgejo can return blank strings for URLs. This handles that by deserializing
// that as `None`
-fn none_if_blank_url<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<Option<Url>, D::Error> {
+fn none_if_blank_url<'de, D: serde::Deserializer<'de>>(
+ deserializer: D,
+) -> Result<Option<Url>, D::Error> {
use serde::de::{Error, Unexpected, Visitor};
use std::fmt;
struct EmptyUrlVisitor;
- impl<'de> Visitor<'de> for EmptyUrlVisitor
- {
+ impl<'de> Visitor<'de> for EmptyUrlVisitor {
type Value = Option<Url>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
@@ -294,13 +306,14 @@ fn none_if_blank_url<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Resul
if s.is_empty() {
return Ok(None);
}
- Url::parse(s).map_err(|err| {
- let err_s = format!("{}", err);
- Error::invalid_value(Unexpected::Str(s), &err_s.as_str())
- }).map(Some)
+ Url::parse(s)
+ .map_err(|err| {
+ let err_s = format!("{}", err);
+ Error::invalid_value(Unexpected::Str(s), &err_s.as_str())
+ })
+ .map(Some)
}
}
deserializer.deserialize_str(EmptyUrlVisitor)
}
-
diff --git a/src/misc.rs b/src/misc.rs
index e2aeb5a..76fc3b8 100644
--- a/src/misc.rs
+++ b/src/misc.rs
@@ -5,7 +5,10 @@ impl Forgejo {
self.get("gitignore/templates").await
}
- pub async fn get_gitignore_template(&self, name: &str) -> Result<Option<GitignoreTemplateInfo>, ForgejoError> {
+ pub async fn get_gitignore_template(
+ &self,
+ name: &str,
+ ) -> Result<Option<GitignoreTemplateInfo>, ForgejoError> {
self.get_opt(&format!("gitignore/templates/{name}")).await
}
@@ -21,7 +24,10 @@ impl Forgejo {
self.get("licenses").await
}
- pub async fn get_license(&self, name: &str) -> Result<Option<GitignoreTemplateInfo>, ForgejoError> {
+ pub async fn get_license(
+ &self,
+ name: &str,
+ ) -> Result<Option<GitignoreTemplateInfo>, ForgejoError> {
self.get_opt(&format!("license/{name}")).await
}
diff --git a/src/notification.rs b/src/notification.rs
index 9dbff21..348363a 100644
--- a/src/notification.rs
+++ b/src/notification.rs
@@ -1,32 +1,72 @@
use super::*;
impl Forgejo {
- pub async fn notifications(&self, query: NotificationQuery) -> Result<Vec<NotificationThread>, ForgejoError> {
- self.get(&format!("notifications?{}", query.query_string())).await
+ pub async fn notifications(
+ &self,
+ query: NotificationQuery,
+ ) -> Result<Vec<NotificationThread>, ForgejoError> {
+ self.get(&format!("notifications?{}", query.query_string()))
+ .await
}
- pub async fn set_notifications_state(&self, query: NotificationPutQuery) -> Result<Vec<NotificationThread>, ForgejoError> {
- self.put(&format!("notifications?{}", query.query_string())).await
+ pub async fn set_notifications_state(
+ &self,
+ query: NotificationPutQuery,
+ ) -> Result<Vec<NotificationThread>, ForgejoError> {
+ self.put(&format!("notifications?{}", query.query_string()))
+ .await
}
pub async fn notification_count(&self) -> Result<Vec<NotificationCount>, ForgejoError> {
self.get("notifications/new").await
}
- pub async fn get_notification(&self, id: u64) -> Result<Option<NotificationThread>, ForgejoError> {
+ pub async fn get_notification(
+ &self,
+ id: u64,
+ ) -> Result<Option<NotificationThread>, ForgejoError> {
self.get_opt(&format!("notifications/threads/{id}")).await
}
- pub async fn set_notification_state(&self, id: u64, to_status: ToStatus) -> Result<Option<NotificationThread>, ForgejoError> {
- self.patch(&format!("notifications/threads/{id}?to-status={}", to_status.as_str()), &()).await
+ pub async fn set_notification_state(
+ &self,
+ id: u64,
+ to_status: ToStatus,
+ ) -> Result<Option<NotificationThread>, ForgejoError> {
+ self.patch(
+ &format!(
+ "notifications/threads/{id}?to-status={}",
+ to_status.as_str()
+ ),
+ &(),
+ )
+ .await
}
- pub async fn get_repo_notifications(&self, owner: &str, name: &str, query: NotificationQuery) -> Result<Vec<NotificationThread>, ForgejoError> {
- self.get(&format!("repos/{owner}/{name}/notifications?{}", query.query_string())).await
+ pub async fn get_repo_notifications(
+ &self,
+ owner: &str,
+ name: &str,
+ query: NotificationQuery,
+ ) -> Result<Vec<NotificationThread>, ForgejoError> {
+ self.get(&format!(
+ "repos/{owner}/{name}/notifications?{}",
+ query.query_string()
+ ))
+ .await
}
- pub async fn set_repo_notifications_state(&self, owner: &str, name: &str, query: NotificationPutQuery) -> Result<Vec<NotificationThread>, ForgejoError> {
- self.put(&format!("repos/{owner}/{name}/notifications?{}", query.query_string())).await
+ pub async fn set_repo_notifications_state(
+ &self,
+ owner: &str,
+ name: &str,
+ query: NotificationPutQuery,
+ ) -> Result<Vec<NotificationThread>, ForgejoError> {
+ self.put(&format!(
+ "repos/{owner}/{name}/notifications?{}",
+ query.query_string()
+ ))
+ .await
}
}
@@ -82,12 +122,20 @@ impl NotificationQuery {
}
if let Some(since) = &self.since {
s.push_str("since=");
- s.push_str(&since.format(&time::format_description::well_known::Rfc3339).unwrap());
+ s.push_str(
+ &since
+ .format(&time::format_description::well_known::Rfc3339)
+ .unwrap(),
+ );
s.push('&');
}
if let Some(before) = &self.before {
s.push_str("before=");
- s.push_str(&before.format(&time::format_description::well_known::Rfc3339).unwrap());
+ s.push_str(
+ &before
+ .format(&time::format_description::well_known::Rfc3339)
+ .unwrap(),
+ );
s.push('&');
}
if let Some(page) = self.page {
@@ -176,7 +224,11 @@ impl NotificationPutQuery {
let mut s = String::new();
if let Some(last_read_at) = &self.last_read_at {
s.push_str("since=");
- s.push_str(&last_read_at.format(&time::format_description::well_known::Rfc3339).unwrap());
+ s.push_str(
+ &last_read_at
+ .format(&time::format_description::well_known::Rfc3339)
+ .unwrap(),
+ );
s.push('&');
}
if self.all {
diff --git a/src/organization.rs b/src/organization.rs
index 55cbd45..6a54f10 100644
--- a/src/organization.rs
+++ b/src/organization.rs
@@ -1,5 +1,5 @@
-use std::collections::BTreeMap;
use crate::*;
+use std::collections::BTreeMap;
#[derive(serde::Deserialize, Debug, PartialEq)]
pub struct Organization {
diff --git a/src/package.rs b/src/package.rs
index 5788704..4c49d5b 100644
--- a/src/package.rs
+++ b/src/package.rs
@@ -3,20 +3,54 @@ use std::fmt::Write;
use super::*;
impl Forgejo {
- pub async fn get_user_packages(&self, owner: &str, query: PackagesQuery) -> Result<Vec<Package>, ForgejoError> {
+ pub async fn get_user_packages(
+ &self,
+ owner: &str,
+ query: PackagesQuery,
+ ) -> Result<Vec<Package>, ForgejoError> {
self.get(&query.path(owner)).await
}
-
- pub async fn get_package(&self, owner: &str, _type: PackageType, name: &str, version: &str) -> Result<Option<Package>, ForgejoError> {
- self.get_opt(&format!("packages/{owner}/{}/{name}/{version}", _type.as_str())).await
+
+ pub async fn get_package(
+ &self,
+ owner: &str,
+ _type: PackageType,
+ name: &str,
+ version: &str,
+ ) -> Result<Option<Package>, ForgejoError> {
+ self.get_opt(&format!(
+ "packages/{owner}/{}/{name}/{version}",
+ _type.as_str()
+ ))
+ .await
}
-
- pub async fn delete_package(&self, owner: &str, _type: PackageType, name: &str, version: &str) -> Result<(), ForgejoError> {
- self.delete(&format!("packages/{owner}/{}/{name}/{version}", _type.as_str())).await
+
+ pub async fn delete_package(
+ &self,
+ owner: &str,
+ _type: PackageType,
+ name: &str,
+ version: &str,
+ ) -> Result<(), ForgejoError> {
+ self.delete(&format!(
+ "packages/{owner}/{}/{name}/{version}",
+ _type.as_str()
+ ))
+ .await
}
- pub async fn get_package_files(&self, owner: &str, _type: PackageType, name: &str, version: &str) -> Result<Vec<PackageFile>, ForgejoError> {
- self.get(&format!("packages/{owner}/{}/{name}/{version}", _type.as_str())).await
+ pub async fn get_package_files(
+ &self,
+ owner: &str,
+ _type: PackageType,
+ name: &str,
+ version: &str,
+ ) -> Result<Vec<PackageFile>, ForgejoError> {
+ self.get(&format!(
+ "packages/{owner}/{}/{name}/{version}",
+ _type.as_str()
+ ))
+ .await
}
}
@@ -35,12 +69,14 @@ impl PackagesQuery {
s.push('?');
if let Some(page) = self.page {
s.push_str("page=");
- s.write_fmt(format_args!("{page}")).expect("writing to string can't fail");
+ s.write_fmt(format_args!("{page}"))
+ .expect("writing to string can't fail");
s.push('&');
}
if let Some(limit) = self.limit {
s.push_str("limit=");
- s.write_fmt(format_args!("{limit}")).expect("writing to string can't fail");
+ s.write_fmt(format_args!("{limit}"))
+ .expect("writing to string can't fail");
s.push('&');
}
if let Some(kind) = self.kind {
@@ -63,24 +99,24 @@ impl PackagesQuery {
pub enum PackageType {
Alpine,
Cargo,
- Chef,
- Composer,
- Conan,
- Conda,
- Container,
- Cran,
- Debian,
- Generic,
- Go,
- Helm,
- Maven,
- Npm,
- Nuget,
- Pub,
- Pypi,
- Rpm,
- RubyGems,
- Swift,
+ Chef,
+ Composer,
+ Conan,
+ Conda,
+ Container,
+ Cran,
+ Debian,
+ Generic,
+ Go,
+ Helm,
+ Maven,
+ Npm,
+ Nuget,
+ Pub,
+ Pypi,
+ Rpm,
+ RubyGems,
+ Swift,
Vagrant,
}
diff --git a/src/repository.rs b/src/repository.rs
index 8b063a0..966b5e3 100644
--- a/src/repository.rs
+++ b/src/repository.rs
@@ -3,7 +3,11 @@ use super::*;
/// Repository operations.
impl Forgejo {
/// Gets info about the specified repository.
- pub async fn get_repo(&self, user: &str, repo: &str) -> Result<Option<Repository>, ForgejoError> {
+ pub async fn get_repo(
+ &self,
+ user: &str,
+ repo: &str,
+ ) -> Result<Option<Repository>, ForgejoError> {
self.get_opt(&format!("repos/{user}/{repo}/")).await
}
@@ -32,7 +36,8 @@ impl Forgejo {
}
pub async fn is_merged(&self, owner: &str, repo: &str, pr: u64) -> Result<bool, ForgejoError> {
- self.get_exists(&format!("repos/{owner}/{repo}/pulls/{pr}/merge")).await
+ self.get_exists(&format!("repos/{owner}/{repo}/pulls/{pr}/merge"))
+ .await
}
pub async fn merge_pr(
@@ -144,8 +149,13 @@ impl Forgejo {
) -> Result<Attachment, ForgejoError> {
self.post_multipart(
&format!("repos/{owner}/{repo}/releases/{id}/assets?name={name}"),
- reqwest::multipart::Form::new()
- .part("attachment", reqwest::multipart::Part::bytes(file).file_name("file").mime_str("*/*").unwrap()),
+ reqwest::multipart::Form::new().part(
+ "attachment",
+ reqwest::multipart::Part::bytes(file)
+ .file_name("file")
+ .mime_str("*/*")
+ .unwrap(),
+ ),
)
.await
}
@@ -197,20 +207,38 @@ impl Forgejo {
.await
}
- pub async fn get_tags(&self, owner: &str, repo: &str, query: TagQuery) -> Result<Vec<Tag>, ForgejoError> {
+ pub async fn get_tags(
+ &self,
+ owner: &str,
+ repo: &str,
+ query: TagQuery,
+ ) -> Result<Vec<Tag>, ForgejoError> {
self.get(&query.to_string(owner, repo)).await
}
- pub async fn create_tag(&self, owner: &str, repo: &str, opts: CreateTagOption) -> Result<Tag, ForgejoError> {
- self.post(&format!("repos/{owner}/{repo}/tags"), &opts).await
+ pub async fn create_tag(
+ &self,
+ owner: &str,
+ repo: &str,
+ opts: CreateTagOption,
+ ) -> Result<Tag, ForgejoError> {
+ self.post(&format!("repos/{owner}/{repo}/tags"), &opts)
+ .await
}
- pub async fn get_tag(&self, owner: &str, repo: &str, tag: &str) -> Result<Option<Tag>, ForgejoError> {
- self.get_opt(&format!("repos/{owner}/{repo}/tags/{tag}")).await
+ pub async fn get_tag(
+ &self,
+ owner: &str,
+ repo: &str,
+ tag: &str,
+ ) -> Result<Option<Tag>, 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
+ self.delete(&format!("repos/{owner}/{repo}/tags/{tag}"))
+ .await
}
}
@@ -608,7 +636,8 @@ pub struct TagQuery {
impl TagQuery {
fn to_string(&self, owner: &str, repo: &str) -> String {
- format!("repos/{owner}/{repo}/tags?page={}&limit={}",
+ 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(),
)
@@ -661,4 +690,3 @@ pub struct RepoTransfer {
pub recipient: User,
pub teams: Vec<Team>,
}
-
diff --git a/tests/ci_test.rs b/tests/ci_test.rs
index 52e5efe..b949b7f 100644
--- a/tests/ci_test.rs
+++ b/tests/ci_test.rs
@@ -1,5 +1,5 @@
+use eyre::{ensure, eyre, WrapErr};
use forgejo_api::Forgejo;
-use eyre::{eyre, ensure, WrapErr};
#[tokio::test]
async fn ci() -> eyre::Result<()> {
@@ -34,13 +34,19 @@ async fn ci() -> eyre::Result<()> {
async fn user(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
let myself = api.myself().await?;
ensure!(myself.is_admin, "user should be admin");
- ensure!(myself.login == "TestingAdmin", "user should be named \"TestingAdmin\"");
+ ensure!(
+ myself.login == "TestingAdmin",
+ "user should be named \"TestingAdmin\""
+ );
let myself_indirect = api
.get_user("TestingAdmin")
.await?
.ok_or_else(|| eyre!("\"TestingAdmin\" not found, but should have been."))?;
- ensure!(myself == myself_indirect, "result of `myself` does not match result of `get_user`");
+ ensure!(
+ myself == myself_indirect,
+ "result of `myself` does not match result of `get_user`"
+ );
let following = api.get_following("TestingAdmin").await?;
ensure!(following == Some(Vec::new()), "following list not empty");
@@ -57,15 +63,20 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
cmd.current_dir("/test_repo");
cmd
};
- let _ = git().args(["config", "--global", "init.defaultBranch", "main"]).status()?;
+ let _ = git()
+ .args(["config", "--global", "init.defaultBranch", "main"])
+ .status()?;
let _ = git().args(["init"]).status()?;
- let _ = git().args(["config", "user.name", "TestingAdmin"]).status()?;
- let _ = git().args(["config", "user.email", "admin@noreply.example.org"]).status()?;
+ let _ = git()
+ .args(["config", "user.name", "TestingAdmin"])
+ .status()?;
+ let _ = git()
+ .args(["config", "user.email", "admin@noreply.example.org"])
+ .status()?;
tokio::fs::write("/test_repo/README.md", "# Test\nThis is a test repo").await?;
let _ = git().args(["add", "."]).status()?;
let _ = git().args(["commit", "-m", "initial commit"]).status()?;
-
let repo_opt = forgejo_api::CreateRepoOption {
auto_init: false,
default_branch: "main".into(),
@@ -80,19 +91,31 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
trust_model: forgejo_api::TrustModel::Default,
};
let remote_repo = api.create_repo(repo_opt).await?;
- ensure!(remote_repo.has_pull_requests, "repo does not accept pull requests");
- ensure!(remote_repo.owner.login == "TestingAdmin", "repo owner is not \"TestingAdmin\"");
+ ensure!(
+ remote_repo.has_pull_requests,
+ "repo does not accept pull requests"
+ );
+ ensure!(
+ remote_repo.owner.login == "TestingAdmin",
+ "repo owner is not \"TestingAdmin\""
+ );
ensure!(remote_repo.name == "test", "repo owner is not \"test\"");
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
let mut remote_url = remote_repo.clone_url.clone();
remote_url.set_username("TestingAdmin").unwrap();
remote_url.set_password(Some("password")).unwrap();
- let _ = git().args(["remote", "add", "origin", remote_url.as_str()]).status()?;
+ let _ = git()
+ .args(["remote", "add", "origin", remote_url.as_str()])
+ .status()?;
let _ = git().args(["push", "-u", "origin", "main"]).status()?;
let _ = git().args(["switch", "-c", "test"]).status()?;
- tokio::fs::write("/test_repo/example.rs", "fn add_one(x: u32) -> u32 { x + 1 }").await?;
+ tokio::fs::write(
+ "/test_repo/example.rs",
+ "fn add_one(x: u32) -> u32 { x + 1 }",
+ )
+ .await?;
let _ = git().args(["add", "."]).status()?;
let _ = git().args(["commit", "-m", "egg"]).status()?;
let _ = git().args(["push", "-u", "origin", "test"]).status()?;
@@ -108,9 +131,15 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
milestone: None,
title: "test pr".into(),
};
- let pr = api.create_pr("TestingAdmin", "test", pr_opt).await.wrap_err("couldn't create pr")?;
+ let pr = api
+ .create_pr("TestingAdmin", "test", pr_opt)
+ .await
+ .wrap_err("couldn't create pr")?;
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
- let is_merged = api.is_merged("TestingAdmin", "test", pr.number).await.wrap_err_with(|| eyre!("couldn't find unmerged pr {}", pr.number))?;
+ let is_merged = api
+ .is_merged("TestingAdmin", "test", pr.number)
+ .await
+ .wrap_err_with(|| eyre!("couldn't find unmerged pr {}", pr.number))?;
ensure!(!is_merged, "pr should not yet be merged");
let merge_opt = forgejo_api::MergePullRequestOption {
act: forgejo_api::MergePrAction::Merge,
@@ -122,20 +151,33 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
head_commit_id: None,
merge_when_checks_succeed: None,
};
- api.merge_pr("TestingAdmin", "test", pr.number, merge_opt).await.wrap_err_with(|| eyre!("couldn't merge pr {}", pr.number))?;
- let is_merged = api.is_merged("TestingAdmin", "test", pr.number).await.wrap_err_with(|| eyre!("couldn't find merged pr {}", pr.number))?;
+ api.merge_pr("TestingAdmin", "test", pr.number, merge_opt)
+ .await
+ .wrap_err_with(|| eyre!("couldn't merge pr {}", pr.number))?;
+ let is_merged = api
+ .is_merged("TestingAdmin", "test", pr.number)
+ .await
+ .wrap_err_with(|| eyre!("couldn't find merged pr {}", pr.number))?;
ensure!(is_merged, "pr should be merged");
let _ = git().args(["fetch"]).status()?;
let _ = git().args(["pull"]).status()?;
- ensure!(api.get_releases("TestingAdmin", "test", forgejo_api::ReleaseQuery::default()).await.wrap_err("releases list not found")?.is_empty(), "there should be no releases yet");
+ ensure!(
+ api.get_releases("TestingAdmin", "test", forgejo_api::ReleaseQuery::default())
+ .await
+ .wrap_err("releases list not found")?
+ .is_empty(),
+ "there should be no releases yet"
+ );
let tag_opt = forgejo_api::CreateTagOption {
message: Some("This is a tag!".into()),
tag_name: "v1.0".into(),
target: None,
};
- api.create_tag("TestingAdmin", "test", tag_opt).await.wrap_err("failed to create tag")?;
+ api.create_tag("TestingAdmin", "test", tag_opt)
+ .await
+ .wrap_err("failed to create tag")?;
let release_opt = forgejo_api::CreateReleaseOption {
body: "This is a release!".into(),
@@ -145,23 +187,49 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
tag_name: "v1.0".into(),
target_commitish: None,
};
- let release = api.create_release("TestingAdmin", "test", release_opt).await.wrap_err("failed to create release")?;
+ let release = api
+ .create_release("TestingAdmin", "test", release_opt)
+ .await
+ .wrap_err("failed to create release")?;
let edit_release = forgejo_api::EditReleaseOption {
draft: Some(false),
..Default::default()
};
- api.edit_release("TestingAdmin", "test", release.id, edit_release).await.wrap_err("failed to edit release")?;
-
- let release_by_tag = api.get_release_by_tag("TestingAdmin", "test", "v1.0").await.wrap_err("failed to find release")?;
- let release_latest = api.latest_release("TestingAdmin", "test").await.wrap_err("failed to find latest release")?;
+ api.edit_release("TestingAdmin", "test", release.id, edit_release)
+ .await
+ .wrap_err("failed to edit release")?;
+
+ let release_by_tag = api
+ .get_release_by_tag("TestingAdmin", "test", "v1.0")
+ .await
+ .wrap_err("failed to find release")?;
+ let release_latest = api
+ .latest_release("TestingAdmin", "test")
+ .await
+ .wrap_err("failed to find latest release")?;
ensure!(release_by_tag == release_latest, "releases not equal");
- let attachment = api.create_release_attachment("TestingAdmin", "test", release.id, "test.txt", b"This is a file!".to_vec()).await.wrap_err("failed to create release attachment")?;
- api.delete_release_attachment("TestingAdmin", "test", release.id, attachment.id).await.wrap_err("failed to deleted attachment")?;
-
- api.delete_release("TestingAdmin", "test", release.id).await.wrap_err("failed to delete release")?;
-
- api.delete_tag("TestingAdmin", "test", "v1.0").await.wrap_err("failed to delete release")?;
+ let attachment = api
+ .create_release_attachment(
+ "TestingAdmin",
+ "test",
+ release.id,
+ "test.txt",
+ b"This is a file!".to_vec(),
+ )
+ .await
+ .wrap_err("failed to create release attachment")?;
+ api.delete_release_attachment("TestingAdmin", "test", release.id, attachment.id)
+ .await
+ .wrap_err("failed to deleted attachment")?;
+
+ api.delete_release("TestingAdmin", "test", release.id)
+ .await
+ .wrap_err("failed to delete release")?;
+
+ api.delete_tag("TestingAdmin", "test", "v1.0")
+ .await
+ .wrap_err("failed to delete release")?;
Ok(())
}