|
|
@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
use crate::json_util::get_json_string;
|
|
|
|
|
|
|
|
use std::collections::HashSet;
|
|
|
|
use tokio::sync::mpsc;
|
|
|
|
use tokio::sync::mpsc;
|
|
|
|
|
|
|
|
|
|
|
|
use super::github_endpoint_watcher::GithubEndpointWatcher;
|
|
|
|
use super::github_endpoint_watcher::GithubEndpointWatcher;
|
|
|
@ -75,9 +77,10 @@ impl<'a> GithubCtl<'a> {
|
|
|
|
let event_stream = self.event_writer.clone();
|
|
|
|
let event_stream = self.event_writer.clone();
|
|
|
|
|
|
|
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
|
|
|
let mut already_seen_event_ids = HashSet::new();
|
|
|
|
let mut endpoint_watcher = GithubEndpointWatcher::new(username, token, url)
|
|
|
|
let mut endpoint_watcher = GithubEndpointWatcher::new(username, token, url)
|
|
|
|
.expect("Failed to create endpoint watcher.");
|
|
|
|
.expect("Failed to create endpoint watcher.");
|
|
|
|
endpoint_watcher.skip_results_before_now().await.expect("Failed to fetch initial historical results.");
|
|
|
|
let mut should_notify: bool = false; // Skip the first page of results because theses events already occurred in the past
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
let api_result = match endpoint_watcher.get_results().await {
|
|
|
|
let api_result = match endpoint_watcher.get_results().await {
|
|
|
|
Ok(result) => result,
|
|
|
|
Ok(result) => result,
|
|
|
@ -88,9 +91,17 @@ impl<'a> GithubCtl<'a> {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if let Some(serde_json::Value::Array(events)) = api_result {
|
|
|
|
if let Some(serde_json::Value::Array(events)) = api_result {
|
|
|
|
for event in events {
|
|
|
|
for event in events {
|
|
|
|
if let Err(_) = event_stream.send(event).await {
|
|
|
|
let event_id = event
|
|
|
|
error!("Receiver dropped.");
|
|
|
|
.get("id")
|
|
|
|
return;
|
|
|
|
.map(get_json_string)
|
|
|
|
|
|
|
|
.expect("Ran into an event without a id.")
|
|
|
|
|
|
|
|
.to_owned();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if should_notify && already_seen_event_ids.insert(event_id) {
|
|
|
|
|
|
|
|
if let Err(_) = event_stream.send(event).await {
|
|
|
|
|
|
|
|
error!("Receiver dropped.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if let None = api_result {
|
|
|
|
} else if let None = api_result {
|
|
|
@ -98,6 +109,7 @@ impl<'a> GithubCtl<'a> {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
error!("Unsupported JSON type.");
|
|
|
|
error!("Unsupported JSON type.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
should_notify = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|