Compare commits

..

2 commits

Author SHA1 Message Date
427bbf3193 Fix clippy issues 2026-03-05 22:01:58 +01:00
0d59568c9e Fix potential timezone inaccuracy
For non whole-hour timezones, the previous logic would not produce
correct timestamps.
2026-03-05 22:00:02 +01:00
4 changed files with 21 additions and 27 deletions

View file

@ -217,7 +217,7 @@ async fn list_all_issues(ctx: &crate::Context) -> anyhow::Result<Vec<Issue>> {
) )
.all() .all()
.await .await
.with_context(|| format!("Failed fetching issue list"))?; .context("Failed fetching issue list")?;
Ok(issues) Ok(issues)
} }
@ -231,11 +231,11 @@ trait IssueExt {
impl IssueExt for Issue { impl IssueExt for Issue {
fn get_number(&self) -> anyhow::Result<u32> { fn get_number(&self) -> anyhow::Result<u32> {
Ok(self self
.number .number
.context("Missing issue number")? .context("Missing issue number")?
.try_into() .try_into()
.context("Failed converting issue number to u32")?) .context("Failed converting issue number to u32")
} }
fn get_title(&self) -> anyhow::Result<String> { fn get_title(&self) -> anyhow::Result<String> {
@ -243,13 +243,13 @@ impl IssueExt for Issue {
} }
fn get_state(&self) -> anyhow::Result<forgejo_api::structs::StateType> { fn get_state(&self) -> anyhow::Result<forgejo_api::structs::StateType> {
Ok(self.state.context("Issue has no state")?) self.state.context("Issue has no state")
} }
fn get_label_names(&self) -> anyhow::Result<Vec<std::string::String>> { fn get_label_names(&self) -> anyhow::Result<Vec<std::string::String>> {
let labels = self.labels.as_ref().context("Issue without labels list")?; let labels = self.labels.as_ref().context("Issue without labels list")?;
let label_names = labels let label_names = labels
.into_iter() .iter()
.map(|label| label.name.as_ref().context("Label without name").cloned()) .map(|label| label.name.as_ref().context("Label without name").cloned())
.collect::<anyhow::Result<Vec<_>>>()?; .collect::<anyhow::Result<Vec<_>>>()?;
Ok(label_names) Ok(label_names)

View file

@ -56,10 +56,10 @@ impl Context {
format!("Could not split repo slug {repo_with_owner:?} into owner and repo") format!("Could not split repo slug {repo_with_owner:?} into owner and repo")
})?; })?;
let server_url = url::Url::parse(&server_url).context("Failed parsing server URL")?; let server_url = url::Url::parse(server_url).context("Failed parsing server URL")?;
let repo_url = server_url let repo_url = server_url
.join(&repo_with_owner) .join(repo_with_owner)
.context("Failed to build server + repo URL")?; .context("Failed to build server + repo URL")?;
let repo_auth_url = { let repo_auth_url = {
let mut repo_auth_url = repo_url.clone(); let mut repo_auth_url = repo_url.clone();

View file

@ -66,8 +66,8 @@ pub async fn remind_all_tasks(ctx: &crate::Context, tasks: &[task::Task]) -> any
Ok(()) Ok(())
} }
pub const SIGNATURE_BASIC: &'static str = "<small>\\[TaskBot Comment\\]</small>"; pub const SIGNATURE_BASIC: &str = "<small>\\[TaskBot Comment\\]</small>";
pub const SIGNATURE_URGENT: &'static str = "<small>\\[TaskBot Comment (Urgent)\\]</small>"; pub const SIGNATURE_URGENT: &str = "<small>\\[TaskBot Comment (Urgent)\\]</small>";
async fn remind_task( async fn remind_task(
ctx: &crate::Context, ctx: &crate::Context,
@ -76,22 +76,14 @@ async fn remind_task(
batching_interval: BatchingInterval, batching_interval: BatchingInterval,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let body = match (reminder_type, batching_interval) { let body = match (reminder_type, batching_interval) {
(ReminderType::Basic, BatchingInterval::Monthly) => format!( (ReminderType::Basic, BatchingInterval::Monthly) => "\
"\ Beep boop. This task is due this month, go take care of it!".to_string(),
Beep boop. This task is due this month, go take care of it!" (ReminderType::Basic, BatchingInterval::Weekly) => "\
), Beep boop. This task is due this week, go take care of it!".to_string(),
(ReminderType::Basic, BatchingInterval::Weekly) => format!( (ReminderType::Basic, BatchingInterval::OnTheDay) => "\
"\ Beep boop. This task is due today, go take care of it!".to_string(),
Beep boop. This task is due this week, go take care of it!" (ReminderType::Urgent, _) => "\
), Hello again. This task is overdue, please take care of it ASAP!".to_string(),
(ReminderType::Basic, BatchingInterval::OnTheDay) => format!(
"\
Beep boop. This task is due today, go take care of it!"
),
(ReminderType::Urgent, _) => format!(
"\
Hello again. This task is overdue, please take care of it ASAP!"
),
}; };
let signature = match reminder_type { let signature = match reminder_type {
@ -107,7 +99,7 @@ Hello again. This task is overdue, please take care of it ASAP!"
&ctx.repo, &ctx.repo,
task.issue_number.into(), task.issue_number.into(),
forgejo_api::structs::CreateIssueCommentOption { forgejo_api::structs::CreateIssueCommentOption {
body: body, body,
updated_at: None, updated_at: None,
}, },
) )

View file

@ -1,5 +1,7 @@
pub fn time_to_jiff(t: time::OffsetDateTime) -> jiff::Zoned { pub fn time_to_jiff(t: time::OffsetDateTime) -> jiff::Zoned {
let tz = jiff::tz::TimeZone::fixed(jiff::tz::offset(t.offset().whole_hours())); let tz = jiff::tz::TimeZone::fixed(
jiff::tz::Offset::from_seconds(t.offset().whole_seconds()).unwrap(),
);
jiff::Timestamp::new(t.unix_timestamp(), 0) jiff::Timestamp::new(t.unix_timestamp(), 0)
.unwrap() .unwrap()