diff options
author | Teddy Wing | 2017-11-17 01:14:22 +0100 |
---|---|---|
committer | Teddy Wing | 2017-11-17 01:14:22 +0100 |
commit | 5d18b165bca8dea2b0f09b61df2069a4336a4ff2 (patch) | |
tree | a2335f1778d8d99e82c233dcdbbeea21167e948d /src/pull_request.rs | |
parent | 7a4b816b6dc8c826db49bc5997709b8e7d1f6933 (diff) | |
parent | 399e04a697e42c9a684f14349f6d94208e719832 (diff) | |
download | kipper-5d18b165bca8dea2b0f09b61df2069a4336a4ff2.tar.bz2 |
Merge branch 'only-update-status-when-pull-request-is-opened-or-new-commits-are-pushed'
Diffstat (limited to 'src/pull_request.rs')
-rw-r--r-- | src/pull_request.rs | 71 |
1 files changed, 67 insertions, 4 deletions
diff --git a/src/pull_request.rs b/src/pull_request.rs index fb06544..b110ea4 100644 --- a/src/pull_request.rs +++ b/src/pull_request.rs @@ -28,9 +28,9 @@ pub struct CommitRef { } impl CommitRef { - pub fn new(json_str: &str) -> Result<CommitRef, Box<Error>> { - let mut github_push_event = json::parse(json_str)?; - + pub fn new( + mut github_push_event: json::JsonValue + ) -> Result<CommitRef, Box<Error>> { Ok( CommitRef { owner: github_push_event["pull_request"]["head"]["repo"]["owner"]["login"].take_string().unwrap_or_default(), @@ -42,6 +42,18 @@ impl CommitRef { } } +pub fn pull_request_opened_or_synchronized( + mut github_push_event: json::JsonValue +) -> bool { + let action = github_push_event["action"].take_string().unwrap_or_default(); + + if action == "opened" || action == "synchronize" { + return true + } + + false +} + #[cfg(test)] mod tests { @@ -465,7 +477,10 @@ mod tests { } }"#; - let commit_ref = CommitRef::new(payload) + let json = json::parse(payload) + .expect("Failed to parse payload."); + + let commit_ref = CommitRef::new(json) .expect("Failed to create CommitRef from payload"); assert_eq!(commit_ref.owner, "baxterthehacker"); @@ -473,4 +488,52 @@ mod tests { assert_eq!(commit_ref.sha, "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c"); assert_eq!(commit_ref.branch, "changes"); } + + #[test] + fn pull_request_opened_or_synchronized_returns_true_when_opened() { + let payload = r#"{ + "action": "opened" + }"#; + + let json = json::parse(payload) + .expect("Failed to parse payload."); + + assert_eq!( + pull_request_opened_or_synchronized(json), + true + ); + } + + #[test] + fn pull_request_opened_or_synchronized_returns_true_when_synchronized() { + let payload = r#"{ + "action": "synchronize" + }"#; + + let json = json::parse(payload) + .expect("Failed to parse payload."); + + assert_eq!( + pull_request_opened_or_synchronized(json), + true + ); + } + + #[test] + fn pull_request_opened_or_synchronized_returns_false_when_not_opened_or_synchronized() { + // "assigned", "unassigned", "review_requested", + // "review_request_removed", "labeled", "unlabeled", "opened", + // "edited", "closed", or "reopened" + let payload = r#"{ + "action": "review_requested" + }"#; + + let json = json::parse(payload) + .expect("Failed to parse payload."); + + assert_eq!( + pull_request_opened_or_synchronized(json), + false + ); + } } |