1#![allow(missing_docs)]
2
3use env;
4use std::path::PathBuf;
5use std::str::FromStr;
6
7#[derive(Clone, Debug)]
14pub struct Appveyor {
15 pub api_url: String,
16 pub account_name: String,
17 pub project_id: String,
18 pub project_name: String,
19 pub project_slug: String,
20 pub build_folder: PathBuf,
21 pub build_id: String,
22 pub build_number: u32,
23 pub build_version: String,
24 pub build_worker_image: String,
25 pub pull_request_number: Option<u32>,
26 pub pull_request_title: Option<String>,
27 pub pull_request_head_repo_name: Option<String>,
28 pub pull_request_head_repo_branch: Option<String>,
29 pub pull_request_head_commit: Option<String>,
30 pub job_id: String,
31 pub job_name: String,
32 pub job_number: u32,
33 pub repo_provider: RepoProvider,
34 pub repo_scm: RepoSCM,
35 pub repo_name: String,
36 pub repo_branch: String,
37 pub repo_tag: bool,
38 pub repo_tag_name: Option<String>,
39 pub repo_commit: String,
40 pub repo_commit_author: String,
41 pub repo_commit_author_email: String,
42 pub repo_commit_timestamp: String,
43 pub repo_commit_message: String,
44 pub repo_commit_message_extended: String,
45 pub scheduled_build: bool,
46 pub forced_build: bool,
47 pub re_build: bool,
48 pub platform: String,
49 pub configuration: String,
50 non_exhaustive: (),
51}
52
53impl Appveyor {
54 pub fn from_env() -> Option<Self> {
56 if !(env("APPVEYOR")? == "True" && env("CI")? == "True") {
57 return None;
58 }
59
60 Some(Appveyor {
61 api_url: env("APPVEYOR_API_URL")?,
62 account_name: env("APPVEYOR_ACCOUNT_NAME")?,
63 project_id: env("APPVEYOR_PROJECT_ID")?,
64 project_name: env("APPVEYOR_PROJECT_NAME")?,
65 project_slug: env("APPVEYOR_PROJECT_SLUG")?,
66 build_folder: env("APPVEYOR_BUILD_FOLDER")?.into(),
67 build_id: env("APPVEYOR_BUILD_ID")?,
68 build_number: env("APPVEYOR_BUILD_NUMBER")?.parse().ok()?,
69 build_version: env("APPVEYOR_BUILD_VERSION")?,
70 build_worker_image: env("APPVEYOR_BUILD_WORKER_IMAGE")?,
71 pull_request_number: env("APPVEYOR_PULL_REQUEST_NUMBER").and_then(|it| it.parse().ok()),
72 pull_request_title: env("APPVEYOR_PULL_REQUEST_TITLE"),
73 pull_request_head_repo_name: env("APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME"),
74 pull_request_head_repo_branch: env("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH"),
75 pull_request_head_commit: env("APVEYOR_PULL_REQUEST_HEAD_COMMIT"),
76 job_id: env("APPVEYOR_JOB_ID")?,
77 job_name: env("APPVEYOR_JOB_NAME")?,
78 job_number: env("APPVEYOR_JOB_NUMBER")?.parse().ok()?,
79 repo_provider: env("APPVEYOR_REPO_PROVIDER")?.parse().ok()?,
80 repo_scm: env("APPVEYOR_REPO_SCM")?.parse().ok()?,
81 repo_name: env("APPVEYOR_REPO_NAME")?,
82 repo_branch: env("APPVEYOR_REPO_BRANCH")?,
83 repo_tag: env("APVEYOR_REPO_TAG")?.parse().ok()?,
84 repo_tag_name: env("APPVEYOR_REPO_TAG_NAME"),
85 repo_commit: env("APPVEYOR_REPO_COMMIT")?,
86 repo_commit_author: env("APPVEYOR_REPO_COMMIT_AUTHOR")?,
87 repo_commit_author_email: env("APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL")?,
88 repo_commit_timestamp: env("APPVEYOR_REPO_COMMIT_TIMESTAMP")?,
89 repo_commit_message: env("APPVEYOR_REPO_COMMIT_MESSAGE")?,
90 repo_commit_message_extended: env("APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED")?,
91 scheduled_build: env("APPVEYOR_SCHEDULED_BUILD").is_some(),
92 forced_build: env("APPVEYOR_FORCED_BUILD").is_some(),
93 re_build: env("APPVEYOR_RE_BUILD").is_some(),
94 platform: env("PLATFORM")?,
95 configuration: env("CONFIGURATION")?,
96 non_exhaustive: (),
97 })
98 }
99}
100
101#[derive(Copy, Clone, Debug)]
102pub enum RepoProvider {
103 Github,
104 BitBucket,
105 Kiln,
106 Vso,
107 Gitlab,
108 #[doc(hidden)] __NonExhaustive,
109}
110
111impl FromStr for RepoProvider {
112 type Err = ();
113
114 fn from_str(s: &str) -> Result<Self, Self::Err> {
115 Ok(match s {
116 "github" => RepoProvider::Github,
117 "bitbucket" => RepoProvider::BitBucket,
118 "kiln" => RepoProvider::Kiln,
119 "vso" => RepoProvider::Vso,
120 "gitlab" => RepoProvider::Gitlab,
121 _ => return Err(()),
122 })
123 }
124}
125
126#[derive(Copy, Clone, Debug)]
127pub enum RepoSCM {
128 Git,
129 Mercurial,
130 #[doc(hidden)] __NonExhaustive,
131}
132
133impl FromStr for RepoSCM {
134 type Err = ();
135
136 fn from_str(s: &str) -> Result<Self, Self::Err> {
137 Ok(match s {
138 "git" => RepoSCM::Git,
139 "mercurial" => RepoSCM::Mercurial,
140 _ => return Err(()),
141 })
142 }
143}