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

30 lines
737 B
Rust
Raw Normal View History

2024-09-20 07:23:36 +01:00
//
use crate::model::Config;
use anyhow::Result;
use kxio::network::{NetRequest, NetUrl};
use super::Issue;
pub async fn fetch_open_issues(config: &Config) -> Result<Vec<Issue>> {
let server_url = config.server();
let repo = config.repo();
let url = format!("{server_url}/api/v1/repos/{repo}/issues?state=open");
let request_builder = NetRequest::get(NetUrl::new(url));
let request = if let Some(auth_token) = config.auth_token() {
request_builder.header("Authorization", auth_token)
} else {
request_builder
}
.build();
let issues = config
.net()
.get::<Vec<Issue>>(request)
.await?
.response_body()
.unwrap_or_default();
Ok(issues)
}