1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::str::FromStr;
use reqwest::{header::USER_AGENT, Client};
use serde_json::Value;
use crate::{authors::AuthorQuery, Authors, CommitAuthor, GithubError, Result};
pub mod by_network_events;
pub mod by_repo_events;
pub mod by_user_events;
fn read_payload(event: &Value, count: &mut Authors) -> Option<()> {
let payload = event.as_object()?.get("payload")?.as_object()?;
let commits = payload.get("commits")?.as_array()?;
for commit in commits {
match read_commit(commit) {
Some(s) => count.insert(s),
None => continue,
}
}
Some(())
}
fn read_commit(commit: &Value) -> Option<CommitAuthor> {
let author = commit.as_object()?.get("author")?.as_object()?;
let name = author.get("name")?.as_str()?.to_string();
let email = author.get("email")?.as_str()?.to_string();
Some(CommitAuthor { name, email, count: 1 })
}
pub fn parse_queries(urls: &str) -> Vec<AuthorQuery> {
let mut out = vec![];
for x in urls.lines() {
let query = AuthorQuery::from(x);
if query.is_some() {
out.push(query)
}
}
out
}