Parse issue list
This commit is contained in:
parent
1db4778dc4
commit
b3e0270e38
5 changed files with 56 additions and 29 deletions
|
|
@ -4,19 +4,31 @@ use anyhow::Context as _;
|
|||
|
||||
pub async fn collect_tasks(ctx: &crate::Context) -> anyhow::Result<Vec<task::Task>> {
|
||||
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::<anyhow::Result<Vec<_>>>()?;
|
||||
|
||||
Ok(tasks)
|
||||
}
|
||||
|
||||
fn task_from_issue(issue: &forgejo_api::structs::Issue) -> anyhow::Result<task::Task> {
|
||||
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<Vec<forgejo_api::structs::Issue>> {
|
||||
|
|
|
|||
|
|
@ -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", &"<redacted>")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new_from_env_or_dev_fallback() -> anyhow::Result<Self> {
|
||||
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<Self> {
|
||||
|
|
@ -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", &"<redacted>")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_env_value(key: &str) -> anyhow::Result<String> {
|
||||
std::env::var(key).with_context(|| format!("Missing ${key} environment variable"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
9
src/scheduler.rs
Normal file
9
src/scheduler.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
use crate::task;
|
||||
|
||||
pub async fn schedule_recurring_tasks(
|
||||
ctx: &crate::Context,
|
||||
tasks: &[task::Task],
|
||||
) -> anyhow::Result<()> {
|
||||
dbg!(tasks);
|
||||
todo!()
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Task {
|
||||
issue_number: u64,
|
||||
title: String,
|
||||
pub issue_number: u64,
|
||||
pub title: String,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue