aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/composer_mirror.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-19 00:10:22 +0900
committernsfisis <nsfisis@gmail.com>2026-05-19 00:11:03 +0900
commitc839244d8d09f3036ebfee8eef7eb6b147e593ab (patch)
treefe48c94f2c2e62468beef5ff1a8f3cff6adeef4f /crates/shirabe/src/util/composer_mirror.rs
parent48839250146b217e2756ed3c0e624fd341b54d6c (diff)
downloadphp-shirabe-c839244d8d09f3036ebfee8eef7eb6b147e593ab.tar.gz
php-shirabe-c839244d8d09f3036ebfee8eef7eb6b147e593ab.tar.zst
php-shirabe-c839244d8d09f3036ebfee8eef7eb6b147e593ab.zip
fix(compile): fix various compile errors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/composer_mirror.rs')
-rw-r--r--crates/shirabe/src/util/composer_mirror.rs47
1 files changed, 38 insertions, 9 deletions
diff --git a/crates/shirabe/src/util/composer_mirror.rs b/crates/shirabe/src/util/composer_mirror.rs
index 0743e9f..d70af94 100644
--- a/crates/shirabe/src/util/composer_mirror.rs
+++ b/crates/shirabe/src/util/composer_mirror.rs
@@ -1,6 +1,6 @@
//! ref: composer/src/Composer/Util/ComposerMirror.php
-use shirabe_external_packages::composer::pcre::preg::Preg;
+use shirabe_external_packages::composer::pcre::preg::{CaptureKey, Preg};
use shirabe_php_shim::hash;
pub struct ComposerMirror;
@@ -15,7 +15,7 @@ impl ComposerMirror {
pretty_version: Option<&str>,
) -> String {
let reference = reference.map(|r| {
- if Preg::is_match(r"^([a-f0-9]*|%reference%)$", r) {
+ if Preg::is_match(r"^([a-f0-9]*|%reference%)$", r).unwrap_or(false) {
r.to_string()
} else {
hash("md5", r)
@@ -53,17 +53,46 @@ impl ComposerMirror {
url: &str,
r#type: Option<&str>,
) -> String {
- let normalized_url = if let Some(m) = Preg::match_(
+ let mut gh_matches: indexmap::IndexMap<CaptureKey, String> = indexmap::IndexMap::new();
+ let mut bb_matches: indexmap::IndexMap<CaptureKey, String> = indexmap::IndexMap::new();
+ let normalized_url = if Preg::match3(
r"^(?:(?:https?|git)://github\.com/|git@github\.com:)([^/]+)/(.+?)(?:\.git)?$",
url,
- ) {
- format!("gh-{}/{}", m[1], m[2])
- } else if let Some(m) =
- Preg::match_(r"^https://bitbucket\.org/([^/]+)/(.+?)(?:\.git)?/?$", url)
+ Some(&mut gh_matches),
+ )
+ .unwrap_or(false)
{
- format!("bb-{}/{}", m[1], m[2])
+ format!(
+ "gh-{}/{}",
+ gh_matches
+ .get(&CaptureKey::ByIndex(1))
+ .cloned()
+ .unwrap_or_default(),
+ gh_matches
+ .get(&CaptureKey::ByIndex(2))
+ .cloned()
+ .unwrap_or_default(),
+ )
+ } else if Preg::match3(
+ r"^https://bitbucket\.org/([^/]+)/(.+?)(?:\.git)?/?$",
+ url,
+ Some(&mut bb_matches),
+ )
+ .unwrap_or(false)
+ {
+ format!(
+ "bb-{}/{}",
+ bb_matches
+ .get(&CaptureKey::ByIndex(1))
+ .cloned()
+ .unwrap_or_default(),
+ bb_matches
+ .get(&CaptureKey::ByIndex(2))
+ .cloned()
+ .unwrap_or_default(),
+ )
} else {
- Preg::replace(r"[^a-z0-9_.-]", "-", url.trim_matches('/'))
+ Preg::replace(r"[^a-z0-9_.-]", "-", url.trim_matches('/')).unwrap_or_default()
};
["%package%", "%normalizedUrl%", "%type%"]