1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
pub mod forgejo_driver;
pub mod fossil_driver;
pub mod git_bitbucket_driver;
pub mod git_driver;
pub mod github_driver;
pub mod gitlab_driver;
pub mod hg_driver;
pub mod perforce_driver;
pub mod svn_driver;
pub mod vcs_driver;
pub mod vcs_driver_interface;
pub use forgejo_driver::*;
pub use fossil_driver::*;
pub use git_bitbucket_driver::*;
pub use git_driver::*;
pub use github_driver::*;
pub use gitlab_driver::*;
pub use hg_driver::*;
pub use perforce_driver::*;
pub use svn_driver::*;
pub use vcs_driver::*;
pub use vcs_driver_interface::*;
use crate::config::Config;
use crate::io::IOInterface;
use crate::util::{HttpDownloader, ProcessExecutor};
use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VcsDriverKind {
GitHub,
GitLab,
GitBitbucket,
Forgejo,
Git,
Hg,
Perforce,
Fossil,
Svn,
}
impl VcsDriverKind {
pub fn instantiate(
self,
repo_config: IndexMap<String, PhpMixed>,
io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
config: std::rc::Rc<std::cell::RefCell<Config>>,
http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>,
process: std::rc::Rc<std::cell::RefCell<ProcessExecutor>>,
) -> Box<dyn VcsDriverInterface> {
match self {
VcsDriverKind::GitHub => Box::new(GitHubDriver::new(
repo_config,
io,
config,
http_downloader,
process,
)),
VcsDriverKind::GitLab => Box::new(GitLabDriver::new(
repo_config,
io,
config,
http_downloader,
process,
)),
VcsDriverKind::GitBitbucket => Box::new(GitBitbucketDriver::new(
repo_config,
io,
config,
http_downloader,
process,
)),
VcsDriverKind::Forgejo => Box::new(ForgejoDriver::new(
repo_config,
io,
config,
http_downloader,
process,
)),
VcsDriverKind::Git => Box::new(GitDriver::new(
repo_config,
io,
config,
http_downloader,
process,
)),
VcsDriverKind::Hg => Box::new(HgDriver::new(
repo_config,
io,
config,
http_downloader,
process,
)),
VcsDriverKind::Perforce => Box::new(PerforceDriver::new(
repo_config,
io,
config,
http_downloader,
process,
)),
VcsDriverKind::Fossil => Box::new(FossilDriver::new(
repo_config,
io,
config,
http_downloader,
process,
)),
VcsDriverKind::Svn => Box::new(SvnDriver::new(
repo_config,
io,
config,
http_downloader,
process,
)),
}
}
pub fn supports(
self,
io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
config: std::rc::Rc<std::cell::RefCell<Config>>,
url: &str,
deep: bool,
) -> anyhow::Result<bool> {
match self {
VcsDriverKind::GitHub => GitHubDriver::supports(io, config, url, deep),
VcsDriverKind::GitLab => GitLabDriver::supports(io, config, url, deep),
VcsDriverKind::GitBitbucket => GitBitbucketDriver::supports(io, config, url, deep),
VcsDriverKind::Forgejo => ForgejoDriver::supports(io, config, url, deep),
VcsDriverKind::Git => GitDriver::supports(io, config, url, deep),
VcsDriverKind::Hg => HgDriver::supports(io, config, url, deep),
VcsDriverKind::Perforce => PerforceDriver::supports(io, config, url, deep),
VcsDriverKind::Fossil => FossilDriver::supports(io, config, url, deep),
VcsDriverKind::Svn => SvnDriver::supports(io, config, url, deep),
}
}
/// PHP fully-qualified `class-string`, used as the fallback driver name in `getRepoName()`.
pub fn php_class_name(self) -> &'static str {
match self {
VcsDriverKind::GitHub => "Composer\\Repository\\Vcs\\GitHubDriver",
VcsDriverKind::GitLab => "Composer\\Repository\\Vcs\\GitLabDriver",
VcsDriverKind::GitBitbucket => "Composer\\Repository\\Vcs\\GitBitbucketDriver",
VcsDriverKind::Forgejo => "Composer\\Repository\\Vcs\\ForgejoDriver",
VcsDriverKind::Git => "Composer\\Repository\\Vcs\\GitDriver",
VcsDriverKind::Hg => "Composer\\Repository\\Vcs\\HgDriver",
VcsDriverKind::Perforce => "Composer\\Repository\\Vcs\\PerforceDriver",
VcsDriverKind::Fossil => "Composer\\Repository\\Vcs\\FossilDriver",
VcsDriverKind::Svn => "Composer\\Repository\\Vcs\\SvnDriver",
}
}
}
|