Skip to content

Commit

Permalink
Update ENV vars and replace Result with Option
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissivia committed Aug 30, 2019
1 parent c9bbeff commit 9d86ac3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/bin/plus9k.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
use plus9k;
use std::env;

fn main() -> std::io::Result<()> {
let path = env::var("INPUT_EVENT_PATH").expect("INPUT_EVENT_PATH is required");
fn main() {
let path = env::var("GITHUB_EVENT_PATH").expect("GITHUB_EVENT_PATH is required");
let token = env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN is required");
// optional, fine to have none
let maybe_message = env::var("INPUT_MESSAGE").ok();
let maybe_message = env::var("MESSAGE").ok();

plus9k::run(token, path, maybe_message)
plus9k::run(token, path, maybe_message);
}
13 changes: 7 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,22 @@ fn reply(
Ok(String::from("Success"))
}

pub fn run(token: String, path: String, maybe_message: Option<String>) -> std::io::Result<()> {
pub fn run(token: String, path: String, maybe_message: Option<String>) -> Option<String> {
let message = get_message(maybe_message);
println!("message: {:?}", message);
let contents = read_payload(path)?;
let contents = read_payload(path).ok()?;
// println!("{:?}",contents);
let payload: Payload = serde_json::from_str(&contents)?;
let payload: Payload = serde_json::from_str(&contents).ok()?;
println!("payload: {:?}", payload);
if should_reply(&payload) {
reply(
let response = reply(
token,
&payload.issue.id,
&payload.repository.full_name,
message,
);
response.ok()
} else {
Some(String::from("Comment seems legit."))
}

Ok(())
}

0 comments on commit 9d86ac3

Please sign in to comment.