diff options
Diffstat (limited to 'crates/shirabe/src/repository/vcs/gitlab_driver.rs')
| -rw-r--r-- | crates/shirabe/src/repository/vcs/gitlab_driver.rs | 165 |
1 files changed, 106 insertions, 59 deletions
diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index dea1bf6..e00bbf8 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -4,7 +4,7 @@ use crate::io::io_interface; use anyhow::Result; use chrono::{DateTime, Utc}; use indexmap::IndexMap; -use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::composer::pcre::preg::{CaptureKey, Preg}; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_search_mixed, array_shift, ctype_alnum, empty, explode, extension_loaded, implode, in_array, is_array, @@ -18,6 +18,7 @@ use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; use crate::repository::vcs::vcs_driver::VcsDriverBase; +use crate::repository::vcs::vcs_driver_interface::VcsDriverInterface; use crate::util::gitlab::GitLab; use crate::util::http::response::Response; use crate::util::http_downloader::HttpDownloader; @@ -57,30 +58,43 @@ impl GitLabDriver { /// /// SSH urls use https by default. Set "secure-http": false on the repository config to use http instead. pub fn initialize(&mut self) -> Result<()> { - let match_ = match Preg::is_match_strict_groups(Self::URL_REGEX, &self.inner.url) { - Some(m) => m, - None => { - return Err(InvalidArgumentException { - message: sprintf( - "The GitLab repository URL %s is invalid. It must be the HTTP URL of a GitLab project.", - &[PhpMixed::String(self.inner.url.clone())], - ), - code: 0, - } - .into()); + let mut match_: IndexMap<CaptureKey, String> = IndexMap::new(); + if !Preg::is_match_strict_groups3(Self::URL_REGEX, &self.inner.url, Some(&mut match_)) + .unwrap_or(false) + { + return Err(InvalidArgumentException { + message: sprintf( + "The GitLab repository URL %s is invalid. It must be the HTTP URL of a GitLab project.", + &[PhpMixed::String(self.inner.url.clone())], + ), + code: 0, } - }; + .into()); + } let guessed_domain = match_ - .get("domain") + .get(&CaptureKey::ByName("domain".to_string())) .cloned() .filter(|s| !s.is_empty()) - .unwrap_or_else(|| match_.get("domain2").cloned().unwrap_or_default()); - let configured_domains = self.inner.config.get("gitlab-domains"); - let mut url_parts: Vec<String> = - explode("/", &match_.get("parts").cloned().unwrap_or_default()); + .unwrap_or_else(|| { + match_ + .get(&CaptureKey::ByName("domain2".to_string())) + .cloned() + .unwrap_or_default() + }); + let configured_domains = self.inner.config.borrow_mut().get("gitlab-domains"); + let mut url_parts: Vec<String> = explode( + "/", + &match_ + .get(&CaptureKey::ByName("parts".to_string())) + .cloned() + .unwrap_or_default(), + ); - let scheme_match = match_.get("scheme").cloned().unwrap_or_default(); + let scheme_match = match_ + .get(&CaptureKey::ByName("scheme".to_string())) + .cloned() + .unwrap_or_default(); self.scheme = if in_array( PhpMixed::String(scheme_match.clone()), &PhpMixed::List(vec