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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 84 additions and 20 deletions

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);