hive-forge: add lint verb for triage queries (closes #505)
This commit is contained in:
parent
c11424dd9a
commit
703018106a
4 changed files with 478 additions and 0 deletions
|
|
@ -93,6 +93,34 @@ impl Client {
|
|||
decode_json(resp, &format!("GET {url}"))
|
||||
}
|
||||
|
||||
/// GET a paginated list endpoint and concatenate all pages.
|
||||
/// `path` should NOT include `page=` (we own it); other query
|
||||
/// params (`?limit=N&state=open&...`) are preserved. Pages drain
|
||||
/// while the response carries a `Link: rel="next"` header, up to
|
||||
/// `max_pages` (the runaway-loop safety cap). Returns the merged
|
||||
/// array. Used by `lint` for repo-wide queries (closes #505).
|
||||
pub fn get_json_all(&self, path: &str, max_pages: u32) -> Result<Vec<Value>> {
|
||||
let sep = if path.contains('?') { '&' } else { '?' };
|
||||
let mut merged = Vec::new();
|
||||
for page in 1..=max_pages {
|
||||
let url = format!("{}{}{sep}page={page}", self.api(), path);
|
||||
let resp = self.http.get(&url).send().context("GET")?;
|
||||
let has_next = resp
|
||||
.headers()
|
||||
.get(reqwest::header::LINK)
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.is_some_and(|s| s.contains("rel=\"next\""));
|
||||
let v = decode_json(resp, &format!("GET {url}"))?;
|
||||
let arr = v.as_array().cloned().unwrap_or_default();
|
||||
let empty = arr.is_empty();
|
||||
merged.extend(arr);
|
||||
if empty || !has_next {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(merged)
|
||||
}
|
||||
|
||||
/// GET `<api>/<path>` and return the raw response body as text
|
||||
/// (used by `diff` which fetches a `text/plain` blob).
|
||||
pub fn get_text(&self, path: &str, accept: &str) -> Result<String> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue