forgejo-todo-checker/src/issues/fetch.rs

29 lines
857 B
Rust
Raw Normal View History

//
use std::collections::HashSet;
2024-09-20 07:23:36 +01:00
use crate::model::Config;
2025-01-04 20:46:01 +00:00
use color_eyre::{eyre::Context, Result};
2024-09-20 07:23:36 +01:00
use super::Issue;
pub async fn fetch_open_issues<'net, 'fs>(config: &Config<'net, 'fs>) -> Result<HashSet<Issue>> {
2024-09-20 07:23:36 +01:00
let server_url = config.server();
let repo = config.repo();
let url = format!("{server_url}/api/v1/repos/{repo}/issues?state=open");
2025-01-04 20:46:01 +00:00
println!("> {url}");
let net = config.net();
let response = net
.get(url)
.with_option(config.auth_token())
.some(|request, auth_token| request.header("Authorization", auth_token))
.send()
.await?;
2025-01-04 20:46:01 +00:00
println!("< {}", response.status());
let body = response.text().await.context("reading issues body")?;
let issues: HashSet<Issue> =
serde_json::from_str(&body).with_context(|| format!("body: {body}"))?;
2024-09-20 07:23:36 +01:00
Ok(issues)
}