Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use milestones for cargo too #86

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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