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.
47 lines
1.5 KiB
Rust
47 lines
1.5 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(event: serde_json::Value) -> Result<(), Box<dyn std::error::Error>> {
|
|
if PullRequestEvent::is_a(&event)? {
|
|
let event = PullRequestEvent::new(&event)?;
|
|
if event.action == "opened" {
|
|
println!("PullRequestEvent action {}", event.action);
|
|
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()?;
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|