diff options
author | Teddy Wing | 2017-11-17 00:54:27 +0100 |
---|---|---|
committer | Teddy Wing | 2017-11-17 00:54:27 +0100 |
commit | 205fc3b71bd44067685c8517e7d126e3574827e1 (patch) | |
tree | 3deaeaa9ac1e5b23488b7f0b810ea3b88d3f04ca /src/pull_request.rs | |
parent | cef74cbc8ccfac2b371db2cc9e99dda3c1fce166 (diff) | |
download | kipper-205fc3b71bd44067685c8517e7d126e3574827e1.tar.bz2 |
CommitRef::new(): Take a `JsonValue` instead of an `&str`
We expect to have pre-parsed the JSON as this function will get called
after `pull_request_opened_or_synchronized()`. To avoid doing the same
JSON parsing work twice, take a `JsonValue` argument in both functions.
Diffstat (limited to 'src/pull_request.rs')
-rw-r--r-- | src/pull_request.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/pull_request.rs b/src/pull_request.rs index c4081f4..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(), @@ -477,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"); |