aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-12 04:34:12 +0900
committernsfisis <nsfisis@gmail.com>2026-05-12 04:38:06 +0900
commit55d44d86077e8512c15389f9b2f9c9157b4a3137 (patch)
tree2948b71fcd408a197635e6c61bd186c728cf9145 /crates/shirabe/src/util
parentfbf8b80058669f258786a7d07c3467d5d09f2a4d (diff)
downloadphp-shirabe-55d44d86077e8512c15389f9b2f9c9157b4a3137.tar.gz
php-shirabe-55d44d86077e8512c15389f9b2f9c9157b4a3137.tar.zst
php-shirabe-55d44d86077e8512c15389f9b2f9c9157b4a3137.zip
feat(port): port ForgejoRepositoryData.php
Diffstat (limited to 'crates/shirabe/src/util')
-rw-r--r--crates/shirabe/src/util/forgejo_repository_data.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/crates/shirabe/src/util/forgejo_repository_data.rs b/crates/shirabe/src/util/forgejo_repository_data.rs
index ddbe585..6303bfa 100644
--- a/crates/shirabe/src/util/forgejo_repository_data.rs
+++ b/crates/shirabe/src/util/forgejo_repository_data.rs
@@ -1 +1,60 @@
//! ref: composer/src/Composer/Util/ForgejoRepositoryData.php
+
+use indexmap::IndexMap;
+use shirabe_php_shim::PhpMixed;
+
+#[derive(Debug)]
+pub struct ForgejoRepositoryData {
+ pub html_url: String,
+ pub ssh_url: String,
+ pub http_clone_url: String,
+ pub is_private: bool,
+ pub default_branch: String,
+ pub has_issues: bool,
+ pub is_archived: bool,
+}
+
+impl ForgejoRepositoryData {
+ pub fn new(
+ html_url: String,
+ http_clone_url: String,
+ ssh_url: String,
+ is_private: bool,
+ default_branch: String,
+ has_issues: bool,
+ is_archived: bool,
+ ) -> Self {
+ Self {
+ html_url,
+ http_clone_url,
+ ssh_url,
+ is_private,
+ default_branch,
+ has_issues,
+ is_archived,
+ }
+ }
+
+ pub fn from_remote_data(data: &IndexMap<String, PhpMixed>) -> anyhow::Result<Self> {
+ let get_string = |key: &str| {
+ data.get(key)
+ .and_then(|v| v.as_string())
+ .map(|s| s.to_owned())
+ .ok_or_else(|| anyhow::anyhow!("missing or invalid string field: {key}"))
+ };
+ let get_bool = |key: &str| {
+ data.get(key)
+ .and_then(|v| v.as_bool())
+ .ok_or_else(|| anyhow::anyhow!("missing or invalid bool field: {key}"))
+ };
+ Ok(Self::new(
+ get_string("html_url")?,
+ get_string("clone_url")?,
+ get_string("ssh_url")?,
+ get_bool("private")?,
+ get_string("default_branch")?,
+ get_bool("has_issues")?,
+ get_bool("archived")?,
+ ))
+ }
+}