From 577c3d50a768167bbec8ed6fd1460e47d577fc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Casta=C3=B1o=20S=C3=A1nchez?= <47361803+darth-cassan@users.noreply.github.com> Date: Thu, 21 Nov 2024 08:56:13 +0100 Subject: [PATCH] Add min wait support to close on passing (#555) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Castaño Sánchez --- docs/config/.gitvote.yml | 17 +++++++++++++++++ src/cfg.rs | 2 ++ src/db.rs | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/docs/config/.gitvote.yml b/docs/config/.gitvote.yml index bdcb652..ffe40a1 100644 --- a/docs/config/.gitvote.yml +++ b/docs/config/.gitvote.yml @@ -136,6 +136,23 @@ profiles: # close_on_passing: false + # Close on passing minimum wait + #  + # When the close on passing feature is activated, voting will conclude once + # the pass threshold is met. However, there may be instances where it is + # preferable to implement a minimum wait time, even if the vote would + # already pass. This allows participants sufficient opportunity to engage + # and reflect before the vote is automatically finalized. + # + # Units supported: + # + # - day / days + # - week / weeks  + # + # close_on_passing_min_wait: "1 week" + # + close_on_passing_min_wait: null + # Announcements # # GitVote can announce the results of a vote when it is closed on GitHub diff --git a/src/cfg.rs b/src/cfg.rs index 0db3266..ba7d720 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -84,6 +84,8 @@ pub(crate) struct CfgProfile { pub periodic_status_check: Option, #[serde(skip_serializing_if = "Option::is_none")] pub close_on_passing: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub close_on_passing_min_wait: Option, } impl CfgProfile { diff --git a/src/db.rs b/src/db.rs index 22d5160..ad0fb2f 100644 --- a/src/db.rs +++ b/src/db.rs @@ -190,6 +190,12 @@ impl DB for PgDB { where closed = false and cfg ? 'close_on_passing' and (cfg->>'close_on_passing')::boolean = true + and + case + when cfg ? 'close_on_passing_min_wait' and string_to_interval(cfg->>'close_on_passing_min_wait') is not null then + current_timestamp > created_at + (cfg->>'close_on_passing_min_wait')::interval + else true + end ", &[], )