Skip to content

Commit 157c928

Browse files
Forward-paginate issues and PRs
This seems like it ought to be identical, but in 1.94.0 I'm seeing PR 151164 (and maybe others, but that's the one picked up as missing despite having a tracking issue) only existing in the forward pagination. It also seems more intuitive to scan forwards in general, so feels reasonable to switch given it fixes the bug without too much more digging. This also adds an assertion that we did fetch all the results which would have made it clearer where the problem was without as much investigation.
1 parent 923fe8f commit 157c928

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

src/main.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn get_issues_by_milestone_inner(
191191
if ty == "pullRequests" {
192192
args.insert("states", String::from("[MERGED]"));
193193
}
194-
args.insert("last", String::from("100"));
194+
args.insert("first", String::from("100"));
195195
let mut issues = Vec::new();
196196

197197
loop {
@@ -209,14 +209,15 @@ fn get_issues_by_milestone_inner(
209209
url
210210
body
211211
state
212-
labels(last: 100) {{
212+
labels(first: 100) {{
213213
nodes {{
214214
name
215215
}}
216216
}}
217217
}}
218+
totalCount
218219
pageInfo {{
219-
startCursor
220+
endCursor
220221
}}
221222
}}
222223
}}
@@ -248,6 +249,7 @@ fn get_issues_by_milestone_inner(
248249
.unwrap();
249250
let status = response.status();
250251
let json = response.json::<json::Value>().unwrap();
252+
251253
if !status.is_success() {
252254
panic!("API Error {}: {}", status, json);
253255
}
@@ -264,11 +266,16 @@ fn get_issues_by_milestone_inner(
264266
let mut pull_requests = pull_requests_data["nodes"].as_array().unwrap().clone();
265267
issues.append(&mut pull_requests);
266268

267-
match &pull_requests_data["pageInfo"]["startCursor"] {
269+
match &pull_requests_data["pageInfo"]["endCursor"] {
268270
json::Value::String(cursor) => {
269-
args.insert("before", format!("\"{}\"", cursor));
271+
args.insert("after", format!("\"{}\"", cursor));
270272
}
271273
json::Value::Null => {
274+
// Confirm we gathered all the PRs
275+
assert_eq!(
276+
pull_requests_data["totalCount"].as_u64().unwrap(),
277+
issues.len() as u64
278+
);
272279
break issues;
273280
}
274281
_ => unreachable!(),
@@ -313,6 +320,18 @@ impl TrackingIssues {
313320
let title = o["title"].as_str().unwrap();
314321
if let Some(tail) = title.strip_prefix(PREFIX) {
315322
let for_number = tail[..tail.find(':').unwrap()].parse::<u64>().unwrap();
323+
324+
if !all
325+
.iter()
326+
.any(|i| i["number"].as_u64().unwrap() == for_number)
327+
{
328+
eprintln!(
329+
"Issue #{} is supposed to have relnotes for #{for_number}, \
330+
but #{for_number} is not found in all issues collected",
331+
o["number"]
332+
);
333+
}
334+
316335
let mut sections = HashMap::new();
317336
let body = o["body"].as_str().unwrap();
318337

@@ -394,6 +413,8 @@ fn map_to_line_items<'a>(
394413
issue.raw["url"].as_str().unwrap(),
395414
));
396415
}
416+
} else {
417+
eprintln!("#{number} has unknown section {:?}", section);
397418
}
398419
}
399420

0 commit comments

Comments
 (0)