Make task news nag configurable and deterministic (#3567)

This patch fixes #3497.
This commit is contained in:
Adrian Sadłocha
2024-07-27 01:30:54 +01:00
committed by GitHub
parent 9dde68f918
commit 9c49863795
5 changed files with 84 additions and 20 deletions

View File

@@ -93,8 +93,8 @@ std::string configurationDefaults =
"\n"
"# Miscellaneous\n"
"# verbose= # Comma-separated list. May contain any subset of:\n"
"# affected,blank,context,default,edit,filter,footnote,header,label,new-id,new-uuid,override,project,recur,special,sync\n"
"verbose=affected,blank,context,edit,header,footnote,label,new-id,project,special,sync,override,recur\n"
"# affected,blank,context,default,edit,filter,footnote,header,label,new-id,new-uuid,news,override,project,recur,special,sync\n"
"verbose=affected,blank,context,edit,header,footnote,label,new-id,news,project,special,sync,override,recur\n"
"confirmation=1 # Confirmation on delete, big changes\n"
"recurrence=1 # Enable recurrence\n"
"recurrence.confirmation=prompt # Confirmation for propagating changes among recurring tasks (yes/no/prompt)\n"
@@ -1050,6 +1050,7 @@ bool Context::verbose (const std::string& token)
v != "label" && //
v != "new-id" && //
v != "new-uuid" && //
v != "news" && //
v != "override" && //
v != "project" && //
v != "recur" && //

View File

@@ -26,7 +26,6 @@
#include <cmake.h>
#include <CmdCustom.h>
#include <random>
#include <sstream>
#include <map>
#include <vector>
@@ -254,23 +253,16 @@ int CmdCustom::execute (std::string& output)
// Inform user about the new release highlights if not presented yet
Version news_version(Context::getContext ().config.get ("news.version"));
Version current_version = Version::Current();
if (news_version != current_version)
auto should_nag = news_version != current_version && Context::getContext ().verbose ("news");
if (should_nag)
{
std::random_device device;
std::mt19937 random_generator(device());
std::uniform_int_distribution<std::mt19937::result_type> twentyfive_percent(1, 4);
// 25% chance to display the message.
if (twentyfive_percent(random_generator) == 4)
{
std::ostringstream notice;
notice << "Recently upgraded to " << current_version << ". "
"Please run 'task news' to read highlights about the new release.";
if (Context::getContext ().verbose ("footnote"))
Context::getContext ().footnote (notice.str());
else if (Context::getContext ().verbose ("header"))
Context::getContext ().header (notice.str());
}
std::ostringstream notice;
notice << "Recently upgraded to " << current_version << ". "
"Please run 'task news' to read highlights about the new release.";
if (Context::getContext ().verbose ("footnote"))
Context::getContext ().footnote (notice.str());
else if (Context::getContext ().verbose ("header"))
Context::getContext ().header (notice.str());
}
std::string location = (Context::getContext ().data_dir);