You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.0 KiB
Rust
55 lines
2.0 KiB
Rust
#[macro_use]
|
|
extern crate log;
|
|
|
|
mod githubctl;
|
|
mod json_util;
|
|
|
|
use githubctl::PullRequestEvent;
|
|
use notify_rust::{Hint, Notification};
|
|
use serde_json;
|
|
|
|
const USERNAME: &'static str = include_str!("../.username");
|
|
const TOKEN: &'static str = include_str!("../.pat");
|
|
const ORG: &'static str = include_str!("../.org");
|
|
const REPO: &'static str = include_str!("../.repo");
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
pretty_env_logger::init();
|
|
let mut github = githubctl::GithubCtl::new(USERNAME, TOKEN)?;
|
|
github.watch_repo(ORG, REPO).await?;
|
|
loop {
|
|
let event = github.get_event().await?;
|
|
// println!("{}", serde_json::to_string(&event)?);
|
|
handle_event(event)?;
|
|
}
|
|
}
|
|
|
|
fn handle_event(json_event: serde_json::Value) -> Result<(), Box<dyn std::error::Error>> {
|
|
if PullRequestEvent::is_a(&json_event)? {
|
|
let event = PullRequestEvent::new(&json_event)?;
|
|
if event.action == "opened" {
|
|
// println!("PullRequestEvent action {}", event.action);
|
|
println!("{}", serde_json::to_string(&json_event)?);
|
|
let notification_body = format!("Pull Request opened: {}", event.title);
|
|
Notification::new()
|
|
.summary("Pull request opened.")
|
|
.body(notification_body.as_str())
|
|
// .icon("can be a full path to an image file")
|
|
.appname("github_watcher")
|
|
.hint(Hint::Category("im.received".to_owned()))
|
|
.hint(Hint::Resident(true))
|
|
.timeout(0)
|
|
.show()?
|
|
.wait_for_action(|action| match action {
|
|
"default" => info!("you clicked \"default\""),
|
|
"clicked" => info!("that was correct"),
|
|
// here "__closed" is a hard coded keyword
|
|
"__closed" => info!("the notification was closed"),
|
|
_ => info!("Unrecognized action {}", action),
|
|
});
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|