aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/forgejo_url.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-17 02:53:53 +0900
committernsfisis <nsfisis@gmail.com>2026-05-17 02:53:53 +0900
commita1c7e6908a26e10f6e1f23a51721664b5e2d838d (patch)
treec575c76f1b43359ed74913da4c6a2636643f1ba0 /crates/shirabe/src/util/forgejo_url.rs
parent7f606f36fef0c0467c3c0db3d0da33af486dae8a (diff)
downloadphp-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.tar.gz
php-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.tar.zst
php-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.zip
chore(style): cargo fmt
Diffstat (limited to 'crates/shirabe/src/util/forgejo_url.rs')
-rw-r--r--crates/shirabe/src/util/forgejo_url.rs25
1 files changed, 20 insertions, 5 deletions
diff --git a/crates/shirabe/src/util/forgejo_url.rs b/crates/shirabe/src/util/forgejo_url.rs
index ef57e25..3b42f13 100644
--- a/crates/shirabe/src/util/forgejo_url.rs
+++ b/crates/shirabe/src/util/forgejo_url.rs
@@ -12,10 +12,16 @@ pub struct ForgejoUrl {
}
impl ForgejoUrl {
- pub const URL_REGEX: &'static str = r"^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$";
+ pub const URL_REGEX: &'static str =
+ r"^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$";
fn new(owner: String, repository: String, origin_url: String, api_url: String) -> Self {
- Self { owner, repository, origin_url, api_url }
+ Self {
+ owner,
+ repository,
+ origin_url,
+ api_url,
+ }
}
pub fn create(repo_url: &str) -> Result<Self> {
@@ -24,7 +30,8 @@ impl ForgejoUrl {
None => Err(InvalidArgumentException {
message: format!("This is not a valid Forgejo URL: {}", repo_url),
code: 0,
- }.into()),
+ }
+ .into()),
}
}
@@ -32,7 +39,12 @@ impl ForgejoUrl {
let repo_url = repo_url?;
let m = Preg::match_(Self::URL_REGEX, repo_url)?;
- let origin_url = if !m[1].is_empty() { m[1].clone() } else { m[2].clone() }.to_lowercase();
+ let origin_url = if !m[1].is_empty() {
+ m[1].clone()
+ } else {
+ m[2].clone()
+ }
+ .to_lowercase();
let api_base = format!("{}/api/v1", origin_url);
Some(Self::new(
@@ -44,6 +56,9 @@ impl ForgejoUrl {
}
pub fn generate_ssh_url(&self) -> String {
- format!("git@{}:{}/{}.git", self.origin_url, self.owner, self.repository)
+ format!(
+ "git@{}:{}/{}.git",
+ self.origin_url, self.owner, self.repository
+ )
}
}