summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoraviac <aviac@mailbox.org>2024-05-10 09:00:27 +0200
committeraviac <aviac@mailbox.org>2024-05-10 09:00:27 +0200
commit9b2864bd70e7bff52f4f0bbdfbe0e2164d286063 (patch)
tree176585b682dc16197db7cf90dde276aca205ed1e /src
parentMerge pull request 'bump version to 0.2.0' (#52) from bump-0.2.0 into main (diff)
downloadforgejo-api-9b2864bd70e7bff52f4f0bbdfbe0e2164d286063.tar.xz
forgejo-api-9b2864bd70e7bff52f4f0bbdfbe0e2164d286063.zip
feat: naive implementation of ssh_url deserialization
Diffstat (limited to 'src')
-rw-r--r--src/generated/structs.rs3
-rw-r--r--src/lib.rs26
2 files changed, 28 insertions, 1 deletions
diff --git a/src/generated/structs.rs b/src/generated/structs.rs
index 1445c47..e727b5d 100644
--- a/src/generated/structs.rs
+++ b/src/generated/structs.rs
@@ -2278,7 +2278,8 @@ pub struct Repository {
pub release_counter: Option<u64>,
pub repo_transfer: Option<RepoTransfer>,
pub size: Option<u64>,
- pub ssh_url: Option<String>,
+ #[serde(deserialize_with = "crate::deserialize_optional_ssh_url")]
+ pub ssh_url: Option<url::Url>,
pub stars_count: Option<u64>,
pub template: Option<bool>,
#[serde(with = "time::serde::rfc3339::option")]
diff --git a/src/lib.rs b/src/lib.rs
index 90d1137..c86ef64 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,5 @@
use reqwest::{Client, Request, StatusCode};
+use serde::{Deserialize, Deserializer};
use soft_assert::*;
use url::Url;
use zeroize::Zeroize;
@@ -254,6 +255,31 @@ fn none_if_blank_url<'de, D: serde::Deserializer<'de>>(
deserializer.deserialize_str(EmptyUrlVisitor)
}
+#[allow(dead_code)] // not used yet, but it might appear in the future
+fn deserialize_ssh_url<'de, D, DE>(deserializer: D) -> Result<Url, DE>
+where
+ D: Deserializer<'de>,
+ DE: serde::de::Error,
+{
+ let raw_url: String = String::deserialize(deserializer).map_err(DE::custom)?;
+ let url = format!("ssh://{url}", url = raw_url.replace(":", "/"));
+ Url::parse(url.as_str()).map_err(DE::custom)
+}
+
+fn deserialize_optional_ssh_url<'de, D, DE>(deserializer: D) -> Result<Option<Url>, DE>
+where
+ D: Deserializer<'de>,
+ DE: serde::de::Error,
+{
+ let raw_url: Option<String> = Option::deserialize(deserializer).map_err(DE::custom)?;
+ raw_url
+ .map(|raw_url| {
+ let url = format!("ssh://{url}", url = raw_url.replace(":", "/"));
+ Url::parse(url.as_str()).map_err(DE::custom).map(Some)
+ })
+ .unwrap_or(Ok(None))
+}
+
impl From<structs::DefaultMergeStyle> for structs::MergePullRequestOptionDo {
fn from(value: structs::DefaultMergeStyle) -> Self {
match value {