ci_detective/
codeship.rs

1use env;
2
3/// Codeship CI
4///
5/// # References
6///
7/// - <https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables/#default-environment-variables>
8/// - <https://github.com/codecov/codecov-bash/blob/8b76995ad4a95a61cecd4b049a448a402d91d197/codecov#L501-L510>
9#[derive(Clone, Debug)]
10#[cfg_attr(feature = "nightly", non_exhaustive)]
11#[allow(missing_docs)]
12pub struct Codeship {
13    pub branch: String,
14    pub build_number: String,
15    pub build_url: String,
16    pub committer_email: String,
17    pub committer_name: String,
18    pub committer_username: String,
19    pub commit_id: String,
20    pub message: String,
21    pub repo_name: String,
22    non_exhaustive: (),
23}
24
25impl Codeship {
26    /// Construct this provider's information from the environment.
27    pub fn from_env() -> Option<Self> {
28        if !(env("CI")? == "true" && env("CI_NAME")? == "codeship") {
29            return None;
30        }
31
32        Some(Codeship {
33            branch: env("CI_BRANCH")?,
34            build_number: env("CI_BUILD_NUMBER")?,
35            build_url: env("CI_BUILD_URL")?,
36            committer_email: env("CI_COMMITTER_EMAIL")?,
37            committer_name: env("CI_COMMITTER_NAME")?,
38            committer_username: env("CI_COMMITTER_USERNAME")?,
39            commit_id: env("CI_COMMIT_ID")?,
40            message: env("CI_MESSAGE")?,
41            repo_name: env("CI_REPO_NAME")?,
42            non_exhaustive: (),
43        })
44    }
45}