use crate::environment::Environment;
use crate::var::Key;
use crate::var::C_HIGH;
use crate::var::C_LOW;
use super::var;
use super::Hierarchy;
use super::RetrieveRes;
pub struct VarSource;
impl super::VarSource for VarSource {
fn is_usable(&self, _environment: &mut Environment) -> bool {
true
}
fn hierarchy(&self) -> Hierarchy {
Hierarchy::High
}
fn type_name(&self) -> &'static str {
std::any::type_name::<Self>()
}
fn properties(&self) -> &Vec<String> {
&super::NO_PROPS
}
#[remain::check]
fn retrieve(&self, environment: &mut Environment, key: Key) -> RetrieveRes {
Ok(
#[remain::sorted]
match key {
Key::BuildArch
| Key::BuildHostingUrl
| Key::BuildDate
| Key::BuildOs
| Key::BuildOsFamily
| Key::Licenses
| Key::License
| Key::VersionDate
| Key::NameMachineReadable
| Key::RepoCloneUrlGit
| Key::RepoCloneUrlSsh
| Key::RepoCommitPrefixUrl
| Key::RepoIssuesUrl
| Key::RepoRawVersionedPrefixUrl
| Key::RepoVersionedDirPrefixUrl
| Key::RepoVersionedFilePrefixUrl => None,
Key::BuildBranch => var(environment, "BITBUCKET_BRANCH", C_HIGH),
Key::BuildNumber => var(environment, "BITBUCKET_BUILD_NUMBER", C_HIGH),
Key::BuildTag => var(environment, "BITBUCKET_TAG", C_HIGH),
Key::Ci => {
var(environment, "CI", C_HIGH).or_else(|| Some((C_LOW, "false".to_owned())))
}
Key::Name => var(environment, "BITBUCKET_PROJECT_KEY", C_HIGH),
Key::RepoCloneUrl => var(environment, "BITBUCKET_GIT_SSH_ORIGIN", C_HIGH), Key::RepoCloneUrlHttp => var(environment, "BITBUCKET_GIT_HTTP_ORIGIN", C_HIGH),
Key::RepoWebUrl => {
var(environment, "BITBUCKET_REPO_FULL_NAME", C_HIGH).map(
|(confidence, project_slug)| {
(confidence, format!("https://bitbucket.org/{project_slug}"))
},
) }
Key::Version => self
.version_from_build_tag(environment, key)?
.or_else(|| var(environment, "BITBUCKET_COMMIT", C_HIGH)),
},
)
}
}