Skip to content

Commit

Permalink
Merge pull request #86 from cuviper/cargo-milestones
Browse files Browse the repository at this point in the history
Use milestones for cargo too
  • Loading branch information
Mark-Simulacrum authored Mar 11, 2022
2 parents 43bb6dc + 5496658 commit b88126a
Showing 1 changed file with 1 addition and 105 deletions.
106 changes: 1 addition & 105 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ fn main() {
while today - end > six_weeks {
end = end + six_weeks;
}
let start = end - six_weeks;

let mut issues = get_issues_by_milestone(&version, "rust");
issues.sort_by_cached_key(|issue| issue["number"].as_u64().unwrap());
Expand Down Expand Up @@ -86,7 +85,7 @@ fn main() {
let (compat_unsorted, libraries_unsorted, language_unsorted, compiler_unsorted, unsorted) =
partition_prs(rest);

let mut cargo_issues = get_issues_by_date(start, end, "cargo");
let mut cargo_issues = get_issues_by_milestone(&version, "cargo");
cargo_issues.sort_by_cached_key(|issue| issue["number"].as_u64().unwrap());

let (cargo_relnotes, cargo_unsorted) = {
Expand Down Expand Up @@ -207,109 +206,6 @@ fn get_issues_by_milestone(version: &str, repo_name: &'static str) -> Vec<json::
}
}

fn get_issues_by_date(
start: Date<Utc>,
end: Date<Utc>,
repo_name: &'static str,
) -> Vec<json::Value> {
use reqwest::blocking::Client;

let headers = request_header();
let mut args = BTreeMap::new();
args.insert("states", String::from("[MERGED]"));
args.insert("last", String::from("100"));
let mut issues = Vec::new();
let mut not_found_window = true;

loop {
let query = format!(
r#"
query {{
repository(owner: "rust-lang", name: "{repo_name}") {{
pullRequests({args}) {{
nodes {{
mergedAt
number
title
url
labels(last: 100) {{
nodes {{
name
}}
}}
}}
pageInfo {{
startCursor
}}
}}
}}
}}"#,
repo_name = repo_name,
args = args
.iter()
.map(|(k, v)| format!("{}: {}", k, v))
.collect::<Vec<_>>()
.join(",")
)
.replace(" ", "")
.replace("\n", " ")
.replace('"', "\\\"");

let json_query = format!("{{\"query\": \"{}\"}}", query);

let client = Client::new();

let json = client
.post("https://api.github.com/graphql")
.headers(headers.clone())
.body(json_query)
.send()
.unwrap()
.json::<json::Value>()
.unwrap();

let pull_requests_data = json["data"]["repository"]["pullRequests"].clone();

let mut pull_requests = pull_requests_data["nodes"]
.as_array()
.unwrap()
.iter()
.filter(|o| {
let merge_date: chrono::Date<_> = o["mergedAt"]
.as_str()
.unwrap()
.parse::<DateTime<_>>()
.unwrap()
.date();

(merge_date < end) && (merge_date > start)
})
.cloned()
.collect::<Vec<_>>();

args.insert(
"before",
format!(
"\"{}\"",
pull_requests_data["pageInfo"]["startCursor"]
.clone()
.as_str()
.unwrap()
.to_owned()
),
);

if !pull_requests.is_empty() {
not_found_window = false;
issues.append(&mut pull_requests);
} else if not_found_window {
continue;
} else {
break issues;
}
}
}

fn request_header() -> HeaderMap {
use reqwest::header::*;
let token = env::var("GITHUB_TOKEN").expect("Set GITHUB_TOKEN to a valid token");
Expand Down

0 comments on commit b88126a

Please sign in to comment.