2024-09-20 14:36:01 +01:00
|
|
|
use std::collections::HashSet;
|
|
|
|
|
2024-09-20 07:23:36 +01:00
|
|
|
//
|
|
|
|
use crate::model::Config;
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
use kxio::network::{NetRequest, NetUrl};
|
|
|
|
|
|
|
|
use super::Issue;
|
|
|
|
|
2024-09-20 14:36:01 +01:00
|
|
|
pub async fn fetch_open_issues(config: &Config) -> 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");
|
|
|
|
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();
|
|
|
|
|
2024-09-20 14:36:01 +01:00
|
|
|
let issues: HashSet<Issue> = config
|
2024-09-20 07:23:36 +01:00
|
|
|
.net()
|
|
|
|
.get::<Vec<Issue>>(request)
|
|
|
|
.await?
|
|
|
|
.response_body()
|
2024-09-20 14:36:01 +01:00
|
|
|
.unwrap_or_default()
|
|
|
|
.into_iter()
|
|
|
|
.collect();
|
2024-09-20 07:23:36 +01:00
|
|
|
|
|
|
|
Ok(issues)
|
|
|
|
}
|