Skip to content

Commit

Permalink
v0.0.17: fix !cancel dates
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai committed Dec 19, 2024
1 parent f4731d4 commit 029d310
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "moo"
version = "0.0.16"
version = "0.0.17"
edition = "2021"
authors = ["hinto-janai"]
repository = "https://github.com/Cuprate/moo"
Expand Down
12 changes: 6 additions & 6 deletions src/command/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,14 @@ impl Command {
let mut msg = "Canceled meeting(s):\n\n".to_string();
let mut next_meeting = String::new();

for _ in 0..count.get() {
match crate::github::cancel_cuprate_meeting(reason.as_deref()).await {
Ok((canceled_url, next)) => {
msg.push_str(&format!("- {canceled_url}\n"));
next_meeting = next;
match crate::github::cancel_cuprate_meeting(count, reason.as_deref()).await {
Ok((canceled_urls, next)) => {
for url in canceled_urls {
msg.push_str(&format!("- {url}\n"));
}
Err(e) => return RoomMessageEventContent::text_plain(e.to_string()),
next_meeting = next;
}
Err(e) => return RoomMessageEventContent::text_plain(e.to_string()),
}

msg.push_str(&format!("\nNext meeting: {next_meeting}"));
Expand Down
48 changes: 36 additions & 12 deletions src/github.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! TODO
use std::num::NonZero;

//---------------------------------------------------------------------------------------------------- Use
use anyhow::anyhow;
use reqwest::{Client, RequestBuilder};
Expand Down Expand Up @@ -121,8 +123,8 @@ pub async fn finish_cuprate_meeting(
let client = build_client();

let (issue, title) = find_cuprate_meeting_issue(&client, false).await?;
let logs = post_comment_in_issue(&client, issue, meeting_logs).await?;
let next_meeting = post_cuprate_meeting_issue(&client, title, issue).await?;
let logs = post_comment_in_issue(&client, issue, &meeting_logs).await?;
let next_meeting = post_cuprate_meeting_issue(&client, title, issue, None).await?;
close_issue(&client, issue).await?;

Ok((logs, next_meeting))
Expand All @@ -135,20 +137,36 @@ pub async fn finish_cuprate_meeting(
#[instrument]
#[inline]
pub async fn cancel_cuprate_meeting(
count: NonZero<u8>,
reason: Option<&str>,
) -> Result<(String, String), anyhow::Error> {
) -> Result<(Vec<String>, String), anyhow::Error> {
let client = build_client();

let reason = reason.unwrap_or("Unknown");

let comment = format!("This meeting was canceled, reason: `{reason}`");

let (issue, title) = find_cuprate_meeting_issue(&client, false).await?;
post_comment_in_issue(&client, issue, comment).await?;
let next_meeting = post_cuprate_meeting_issue(&client, title, issue).await?;
close_issue(&client, issue).await?;
let mut canceled_meetings = vec![];
let mut next_meeting = String::new();

for week_multiplier in 1..=count.get() {
let (issue, title) = find_cuprate_meeting_issue(&client, false).await?;

post_comment_in_issue(&client, issue, &comment).await?;

Ok((format!("{MONERO_META_GITHUB_ISSUE}/{issue}"), next_meeting))
let next = post_cuprate_meeting_issue(
&client,
title,
issue,
NonZero::new(u64::from(week_multiplier)),
)
.await?;

close_issue(&client, issue).await?;

canceled_meetings.push(format!("{MONERO_META_GITHUB_ISSUE}/{issue}"));
next_meeting = next;
}

Ok((canceled_meetings, next_meeting))
}

/// TODO
Expand Down Expand Up @@ -223,6 +241,7 @@ pub async fn post_cuprate_meeting_issue(
client: &Client,
previous_meeting_title: String,
last_issue: u64,
week_multiplier: Option<NonZero<u64>>,
) -> Result<String, anyhow::Error> {
trace!("Posting Cuprate meeting issue on: {MONERO_META_GITHUB_ISSUE_API}");

Expand All @@ -234,7 +253,12 @@ pub async fn post_cuprate_meeting_issue(
today = today - Days::new(1);
}

let next = today + Days::new(7);
let next = if let Some(multiplier) = week_multiplier {
today + Days::new(7 * multiplier.get())
} else {
today + Days::new(7)
};

next.format("%Y-%m-%d").to_string()
};

Expand Down Expand Up @@ -316,7 +340,7 @@ pub async fn post_cuprate_meeting_issue(
pub async fn post_comment_in_issue(
client: &Client,
issue: u64,
comment: String,
comment: &str,
) -> Result<String, anyhow::Error> {
let url = format!("{MONERO_META_GITHUB_ISSUE_API}/{issue}/comments");

Expand Down

0 comments on commit 029d310

Please sign in to comment.