1mod circleci;
2mod codefresh;
3mod github;
4mod gitlab;
5
6pub use circleci::CircleCI;
7pub use codefresh::Codefresh;
8pub use github::GitHub;
9pub use gitlab::GitLab;
10use qlty_types::tests::v1::CoverageMetadata;
11
12pub trait CI {
13 fn detect(&self) -> bool;
14
15 fn ci_name(&self) -> String;
17 fn ci_url(&self) -> String;
18
19 fn repository_name(&self) -> String;
21 fn repository_url(&self) -> String;
22
23 fn branch(&self) -> String;
25 fn pull_number(&self) -> String;
26 fn pull_url(&self) -> String;
27 fn commit_sha(&self) -> String;
28
29 fn workflow(&self) -> String;
37 fn job(&self) -> String;
38
39 fn build_id(&self) -> String;
41 fn build_url(&self) -> String;
42
43 fn metadata(&self) -> CoverageMetadata {
44 CoverageMetadata {
45 ci: self.ci_name(),
46 build_id: self.build_id(),
47 commit_sha: self.commit_sha(),
48 branch: self.branch(),
49 pull_request_number: self.pull_number(),
50
51 ..Default::default()
52 }
53 }
54}
55
56pub fn current() -> Option<Box<dyn CI>> {
57 all().into_iter().find(|ci| ci.detect())
58}
59
60pub fn all() -> Vec<Box<dyn CI>> {
61 vec![
62 Box::<GitHub>::default(),
63 Box::<GitLab>::default(),
64 Box::<CircleCI>::default(),
65 Box::<Codefresh>::default(),
66 ]
67}