From b3e0270e38741f44ebda990a9707b32eaaa9a4e3 Mon Sep 17 00:00:00 2001 From: Rahix Date: Sun, 1 Mar 2026 15:47:42 +0100 Subject: [PATCH] Parse issue list --- src/collect.rs | 36 ++++++++++++++++++++++++------------ src/context.rs | 28 ++++++++++++++++------------ src/main.rs | 8 +++++--- src/scheduler.rs | 9 +++++++++ src/task.rs | 4 ++-- 5 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 src/scheduler.rs diff --git a/src/collect.rs b/src/collect.rs index d55320a..48014c8 100644 --- a/src/collect.rs +++ b/src/collect.rs @@ -4,19 +4,31 @@ use anyhow::Context as _; pub async fn collect_tasks(ctx: &crate::Context) -> anyhow::Result> { let issues = list_all_issues(ctx).await?; - let issues: Vec<_> = issues - .iter() - .map(|i| { - format!( - "#{} — {}", - i.number.unwrap_or(-1), - i.title.as_deref().unwrap_or("") - ) - }) - .collect(); - dbg!(issues); - todo!() + let tasks = issues + .into_iter() + .map(|issue| { + task_from_issue(&issue).with_context(|| { + format!( + "Error while converting issue #{} to task", + issue.number.unwrap_or(-1) + ) + }) + }) + .collect::>>()?; + + Ok(tasks) +} + +fn task_from_issue(issue: &forgejo_api::structs::Issue) -> anyhow::Result { + Ok(task::Task { + issue_number: issue + .number + .context("Missing issue number")? + .try_into() + .context("Failed converting issue number")?, + title: issue.title.as_ref().context("Missing issue title")?.clone(), + }) } async fn list_all_issues(ctx: &crate::Context) -> anyhow::Result> { diff --git a/src/context.rs b/src/context.rs index b30fc86..e5f2b89 100644 --- a/src/context.rs +++ b/src/context.rs @@ -15,17 +15,6 @@ pub struct Context { pub repo_auth_url: url::Url, } -impl std::fmt::Debug for Context { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Context") - .field("owner", &self.owner) - .field("repo", &self.repo) - .field("repo_url", &self.repo_url.to_string()) - .field("repo_auth_url", &"") - .finish() - } -} - impl Context { pub fn new_from_env_or_dev_fallback() -> anyhow::Result { if std::env::var("CI").is_ok() { @@ -51,7 +40,11 @@ impl Context { let config: DevEnvironment = serde_json::de::from_reader(f).context("Failed to parse dev environment")?; - Self::new(&config.dev_token, &config.server_url, &config.repo_with_owner) + Self::new( + &config.dev_token, + &config.server_url, + &config.repo_with_owner, + ) } fn new(token: &str, server_url: &str, repo_with_owner: &str) -> anyhow::Result { @@ -84,6 +77,17 @@ impl Context { } } +impl std::fmt::Debug for Context { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Context") + .field("owner", &self.owner) + .field("repo", &self.repo) + .field("repo_url", &self.repo_url.to_string()) + .field("repo_auth_url", &"") + .finish() + } +} + fn get_env_value(key: &str) -> anyhow::Result { std::env::var(key).with_context(|| format!("Missing ${key} environment variable")) } diff --git a/src/main.rs b/src/main.rs index 37991fb..990ee8e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,16 +4,18 @@ mod task; mod collect; mod ci_meta; mod context; +mod scheduler; use context::Context; async fn run() -> anyhow::Result<()> { let ctx = Context::new_from_env_or_dev_fallback()?; - log::info!("Context: \n{ctx:#?}"); - collect::collect_tasks(&ctx).await?; + let tasks = collect::collect_tasks(&ctx).await?; - todo!() + scheduler::schedule_recurring_tasks(&ctx, &tasks).await?; + + Ok(()) } #[tokio::main] diff --git a/src/scheduler.rs b/src/scheduler.rs new file mode 100644 index 0000000..a6a2352 --- /dev/null +++ b/src/scheduler.rs @@ -0,0 +1,9 @@ +use crate::task; + +pub async fn schedule_recurring_tasks( + ctx: &crate::Context, + tasks: &[task::Task], +) -> anyhow::Result<()> { + dbg!(tasks); + todo!() +} diff --git a/src/task.rs b/src/task.rs index fd6f25b..d522cae 100644 --- a/src/task.rs +++ b/src/task.rs @@ -1,5 +1,5 @@ #[derive(Debug, Clone, PartialEq, Eq)] pub struct Task { - issue_number: u64, - title: String, + pub issue_number: u64, + pub title: String, }