diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-06 22:40:30 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-06 22:54:44 +0900 |
| commit | c028a9d5c737de5d2b259638a0a76b999364a262 (patch) | |
| tree | 36c7678a335d284e6d2139346660c77f1e124ddc /crates/shirabe/src/repository/vcs/github_driver.rs | |
| parent | 33550b03c1724fbc8c1c8630c3b03fca1f0c0dc7 (diff) | |
| download | php-shirabe-c028a9d5c737de5d2b259638a0a76b999364a262.tar.gz php-shirabe-c028a9d5c737de5d2b259638a0a76b999364a262.tar.zst php-shirabe-c028a9d5c737de5d2b259638a0a76b999364a262.zip | |
feat(vcs): implement VcsDriverInterface for all VCS drivers
Reconcile the VcsDriverInterface trait with the concrete drivers so every
driver implements it as in PHP, where each driver extends VcsDriver.
- Make cache-mutating getters take &mut self in the trait, matching the
inherent methods' lazy-cache semantics; update vcs_repository consumers.
- Change supports() to take Rc<RefCell<Config>> and return Result<bool>,
completing GitDriver::supports deep ls-remote and its config wiring.
- Add base get_composer_information to Git/Hg/Fossil/Perforce and an
impl VcsDriverInterface block to every driver, delegating to inherent
methods and absorbing type differences in the impl.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository/vcs/github_driver.rs')
| -rw-r--r-- | crates/shirabe/src/repository/vcs/github_driver.rs | 92 |
1 files changed, 85 insertions, 7 deletions
diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index 093cd03..b3d5e05 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -939,10 +939,10 @@ impl GitHubDriver { pub fn supports( io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, - config: &Config, + config: std::rc::Rc<std::cell::RefCell<Config>>, url: &str, _deep: bool, - ) -> bool { + ) -> anyhow::Result<bool> { let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if !Preg::is_match_strict_groups3( r"#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#", @@ -951,7 +951,7 @@ impl GitHubDriver { ) .unwrap_or(false) { - return false; + return Ok(false); } let origin_url = matches @@ -968,10 +968,10 @@ impl GitHubDriver { PhpMixed::String(strtolower( &Preg::replace(r"{^www\.}i", "", &origin_url).unwrap_or_default(), )), - &config.get("github-domains"), + &config.borrow().get("github-domains"), false, ) { - return false; + return Ok(false); } if !extension_loaded("openssl") { @@ -984,10 +984,10 @@ impl GitHubDriver { io_interface::VERBOSE, ); - return false; + return Ok(false); } - true + Ok(true) } /// Gives back the loaded <github-api>/repos/<owner>/<repo> result @@ -1324,3 +1324,81 @@ impl GitHubDriver { None } } + +impl crate::repository::vcs::VcsDriverInterface for GitHubDriver { + fn initialize(&mut self) -> anyhow::Result<()> { + GitHubDriver::initialize(self) + } + + fn get_composer_information( + &mut self, + identifier: &str, + ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> { + GitHubDriver::get_composer_information(self, identifier) + } + + fn get_file_content(&mut self, file: &str, identifier: &str) -> anyhow::Result<Option<String>> { + GitHubDriver::get_file_content(self, file, identifier) + } + + fn get_change_date(&mut self, identifier: &str) -> anyhow::Result<Option<DateTime<Utc>>> { + GitHubDriver::get_change_date(self, identifier) + } + + fn get_root_identifier(&mut self) -> anyhow::Result<String> { + GitHubDriver::get_root_identifier(self) + } + + fn get_branches(&mut self) -> anyhow::Result<IndexMap<String, String>> { + GitHubDriver::get_branches(self) + } + + fn get_tags(&mut self) -> anyhow::Result<IndexMap<String, String>> { + GitHubDriver::get_tags(self) + } + + fn get_dist(&self, identifier: &str) -> anyhow::Result<Option<IndexMap<String, String>>> { + Ok(GitHubDriver::get_dist(self, identifier).map(|m| { + m.into_iter() + .map(|(k, v)| (k, v.as_string().unwrap_or("").to_string())) + .collect() + })) + } + + fn get_source(&self, identifier: &str) -> anyhow::Result<IndexMap<String, String>> { + Ok(GitHubDriver::get_source(self, identifier) + .into_iter() + .map(|(k, v)| (k, v.as_string().unwrap_or("").to_string())) + .collect()) + } + + fn get_url(&self) -> String { + GitHubDriver::get_url(self) + } + + fn has_composer_file(&mut self, identifier: &str) -> anyhow::Result<bool> { + match self.get_composer_information(identifier) { + Ok(info) => Ok(info.is_some()), + Err(e) => { + if e.downcast_ref::<TransportException>().is_some() { + Ok(false) + } else { + Err(e) + } + } + } + } + + fn cleanup(&mut self) -> anyhow::Result<()> { + Ok(()) + } + + fn supports( + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + config: std::rc::Rc<std::cell::RefCell<Config>>, + url: &str, + deep: bool, + ) -> anyhow::Result<bool> { + GitHubDriver::supports(io, config, url, deep) + } +} |
