Only nag to read news when there's news to read (#3699)

This commit is contained in:
Dustin J. Mitchell 2024-11-25 17:48:06 -05:00 committed by GitHub
parent 5664182f5e
commit a99b6084e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 4 deletions

View file

@ -28,6 +28,7 @@
// cmake.h include header must come first
#include <CmdCustom.h>
#include <CmdNews.h>
#include <Context.h>
#include <Filter.h>
#include <Lexer.h>
@ -222,11 +223,9 @@ 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();
auto should_nag = news_version != current_version && Context::getContext().verbose("news");
if (should_nag) {
if (CmdNews::should_nag()) {
std::ostringstream notice;
Version current_version = Version::Current();
notice << "Recently upgraded to " << current_version
<< ". "
"Please run 'task news' to read highlights about the new release.";

View file

@ -615,3 +615,28 @@ int CmdNews::execute(std::string& output) {
return 0;
}
bool CmdNews::should_nag() {
if (!Context::getContext().verbose("news")) {
return false;
}
Version news_version(Context::getContext().config.get("news.version"));
if (!news_version.is_valid()) news_version = Version("2.6.0");
Version current_version = Version::Current();
if (news_version == current_version) {
return true;
}
// Check if there are actually any interesting news items to show.
std::vector<NewsItem> items = NewsItem::all();
for (auto& item : items) {
if (item._version > news_version) {
return true;
}
}
return false;
}

View file

@ -63,6 +63,8 @@ class CmdNews : public Command {
public:
CmdNews();
int execute(std::string&);
static bool should_nag();
};
#endif