aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2017-11-17 00:47:26 +0100
committerTeddy Wing2017-11-17 00:47:26 +0100
commitcef74cbc8ccfac2b371db2cc9e99dda3c1fce166 (patch)
tree942797cb042329579a2a6aa1e1de58d488e02963 /src
parent7a4b816b6dc8c826db49bc5997709b8e7d1f6933 (diff)
downloadkipper-cef74cbc8ccfac2b371db2cc9e99dda3c1fce166.tar.bz2
pull_request.rs: Add `pull_request_opened_or_synchronized()`
A new function that, given the parsed JSON from a pull request webhook, tells us whether the pull request was "opened" or "synchronize"d with a boolean. This will enable us to only update commit statuses when actions on the pull request result in new commits being available. Otherwise, we don't want to set a commit status that we've already set before.
Diffstat (limited to 'src')
-rw-r--r--src/pull_request.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/pull_request.rs b/src/pull_request.rs
index fb06544..c4081f4 100644
--- a/src/pull_request.rs
+++ b/src/pull_request.rs
@@ -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 {
@@ -473,4 +485,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
+ );
+ }
}