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>> {
|
pub async fn collect_tasks(ctx: &crate::Context) -> anyhow::Result<Vec<task::Task>> {
|
||||||
let issues = list_all_issues(ctx).await?;
|
let issues = list_all_issues(ctx).await?;
|
||||||
let issues: Vec<_> = issues
|
|
||||||
.iter()
|
let tasks = issues
|
||||||
.map(|i| {
|
.into_iter()
|
||||||
|
.map(|issue| {
|
||||||
|
task_from_issue(&issue).with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
"#{} — {}",
|
"Error while converting issue #{} to task",
|
||||||
i.number.unwrap_or(-1),
|
issue.number.unwrap_or(-1)
|
||||||
i.title.as_deref().unwrap_or("")
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
})
|
||||||
dbg!(issues);
|
.collect::<anyhow::Result<Vec<_>>>()?;
|
||||||
|
|
||||||
todo!()
|
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>> {
|
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,
|
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 {
|
impl Context {
|
||||||
pub fn new_from_env_or_dev_fallback() -> anyhow::Result<Self> {
|
pub fn new_from_env_or_dev_fallback() -> anyhow::Result<Self> {
|
||||||
if std::env::var("CI").is_ok() {
|
if std::env::var("CI").is_ok() {
|
||||||
|
|
@ -51,7 +40,11 @@ impl Context {
|
||||||
let config: DevEnvironment =
|
let config: DevEnvironment =
|
||||||
serde_json::de::from_reader(f).context("Failed to parse dev environment")?;
|
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> {
|
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> {
|
fn get_env_value(key: &str) -> anyhow::Result<String> {
|
||||||
std::env::var(key).with_context(|| format!("Missing ${key} environment variable"))
|
std::env::var(key).with_context(|| format!("Missing ${key} environment variable"))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,18 @@ mod task;
|
||||||
mod collect;
|
mod collect;
|
||||||
mod ci_meta;
|
mod ci_meta;
|
||||||
mod context;
|
mod context;
|
||||||
|
mod scheduler;
|
||||||
|
|
||||||
use context::Context;
|
use context::Context;
|
||||||
|
|
||||||
async fn run() -> anyhow::Result<()> {
|
async fn run() -> anyhow::Result<()> {
|
||||||
let ctx = Context::new_from_env_or_dev_fallback()?;
|
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]
|
#[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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
issue_number: u64,
|
pub issue_number: u64,
|
||||||
title: String,
|
pub title: String,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue