refactor(hive-forge): port CLI verbs to forgejo-api
This commit is contained in:
parent
b8a3927c43
commit
4636987469
36 changed files with 1463 additions and 1153 deletions
|
|
@ -23,7 +23,7 @@ use std::path::PathBuf;
|
|||
|
||||
use anyhow::{Result, bail};
|
||||
use clap::Args as ClapArgs;
|
||||
use serde_json::Value;
|
||||
use forgejo_api::structs::ListActionRunsQuery;
|
||||
|
||||
use crate::client::Client;
|
||||
|
||||
|
|
@ -45,28 +45,29 @@ pub struct Args {
|
|||
/// Pages over the REST runs list (newest-first) to find the run whose
|
||||
/// run-page `html_url` ends in `/runs/<run-number>`, returning its global
|
||||
/// run id — the identifier the web artifact-download route requires.
|
||||
fn resolve_run_id(client: &Client, repo: &str, run_number: u64) -> Result<u64> {
|
||||
fn resolve_run_id(client: &Client, repo: &str, run_number: u64) -> Result<i64> {
|
||||
const PER_PAGE: u32 = 50;
|
||||
const MAX_PAGES: u32 = 40;
|
||||
let (owner, name) = client.owner_repo()?;
|
||||
for page in 1..=MAX_PAGES {
|
||||
let path = format!("/repos/{repo}/actions/runs?limit={PER_PAGE}&page={page}");
|
||||
let body = client.get_json(&path)?;
|
||||
let runs = body
|
||||
.get("workflow_runs")
|
||||
.and_then(Value::as_array)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
let body = client
|
||||
.api()
|
||||
.list_action_runs(owner, name, ListActionRunsQuery::default())
|
||||
.page(page)
|
||||
.page_size(PER_PAGE)
|
||||
.send()?;
|
||||
let runs = body.workflow_runs.unwrap_or_default();
|
||||
if runs.is_empty() {
|
||||
break;
|
||||
}
|
||||
for run in &runs {
|
||||
let tail = run
|
||||
.get("html_url")
|
||||
.and_then(Value::as_str)
|
||||
.and_then(|u| u.rsplit('/').next())
|
||||
.html_url
|
||||
.as_ref()
|
||||
.and_then(|u| u.as_str().rsplit('/').next())
|
||||
.and_then(|s| s.parse::<u64>().ok());
|
||||
if tail == Some(run_number)
|
||||
&& let Some(id) = run.get("id").and_then(Value::as_u64)
|
||||
&& let Some(id) = run.id
|
||||
{
|
||||
return Ok(id);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue