diff options
author | Teddy Wing | 2017-11-08 02:43:43 +0100 |
---|---|---|
committer | Teddy Wing | 2017-11-08 02:43:43 +0100 |
commit | fed9481524036728d1a773535f887cbc974a9990 (patch) | |
tree | c7699b27452f10cb87a27cff54cf1b9dbce77a95 | |
parent | 42b3a7089ac99afe399663ab0ee1686b7c27471a (diff) | |
download | kipper-fed9481524036728d1a773535f887cbc974a9990.tar.bz2 |
jenkins.rs: Add `job_for_commit`
Fill in this function, which returns a boolean whether a given job
matches a `CommitRef`. It does this based on the display name of the
job.
Needed to make the `Job` struct public in order to use it here.
-rw-r--r-- | src/jenkins.rs | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/jenkins.rs b/src/jenkins.rs index 59f0ddd..46ccbd5 100644 --- a/src/jenkins.rs +++ b/src/jenkins.rs @@ -25,6 +25,9 @@ extern crate reqwest; use self::reqwest::header::{Authorization, Basic}; +use af83; +use pull_request::CommitRef; + #[derive(Debug, PartialEq, Eq)] pub enum JobStatus { Success, @@ -33,7 +36,7 @@ pub enum JobStatus { Unknown, } -struct Job { +pub struct Job { display_name: String, result: JobStatus, } @@ -83,8 +86,9 @@ pub fn get_jobs(repo_name: String) {//-> Vec<String> { println!("{}", res.status()); } -// Does the `commit_ref` correspond to the job in the `payload`? -pub fn job_for_commit(payload: String, commit_ref: CommitRef) -> bool { +// Does the `commit_ref` correspond to the job? +pub fn job_for_commit(job: Job, commit_ref: CommitRef) -> bool { + job.display_name == af83::job_name(commit_ref) } pub fn result_from_job(status: Option<String>) -> JobStatus { @@ -124,6 +128,38 @@ mod tests { } #[test] + fn job_for_commit_returns_true_when_commit_matches_job() { + let job = Job { + display_name: "1753-fix-everything-b4a28".to_string(), + result: JobStatus::Pending, + }; + + let commit_ref = CommitRef { + repo: "vivid-system".to_string(), + sha: "b4a286e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c".to_string(), + branch: "1753-fix-everything".to_string(), + }; + + assert_eq!(job_for_commit(job, commit_ref), true); + } + + #[test] + fn job_for_commit_returns_false_when_commit_doesnt_match_job() { + let job = Job { + display_name: "5234-eliminate-widgetmacallit-5a28c".to_string(), + result: JobStatus::Success, + }; + + let commit_ref = CommitRef { + repo: "vivid-system".to_string(), + sha: "b4a286e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c".to_string(), + branch: "1753-fix-everything".to_string(), + }; + + assert_eq!(job_for_commit(job, commit_ref), false); + } + + #[test] fn result_from_job_is_success() { assert_eq!( result_from_job(Some("SUCCESS".to_string())), |