This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new d21a6cb9 Handy banner method; allow for empty notice file
d21a6cb9 is described below

commit d21a6cb94194332344f3368d1ddf437a336df4ba
Author: Sebb <[email protected]>
AuthorDate: Thu Oct 3 12:14:30 2024 +0100

    Handy banner method; allow for empty notice file
---
 lib/whimsy/asf/status.rb | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/lib/whimsy/asf/status.rb b/lib/whimsy/asf/status.rb
index 379a2895..3c207062 100644
--- a/lib/whimsy/asf/status.rb
+++ b/lib/whimsy/asf/status.rb
@@ -77,12 +77,29 @@ module Status
   def self.notice
     path =  '/srv/whimsy/www/notice.txt'
     if File.exist? path
-      File.open(path) do |fh|
-        return fh.readline.chomp, '/notice.txt'
+      begin
+        File.open(path) do |fh|
+          return fh.readline.chomp, '/notice.txt'
+        end
+      rescue EOFError
       end
     end
     nil
   end
+
+  # return message and href path suitable for page banner
+  # Returns: {text: message, href: link} where
+  # message and link are derived from updates_disallowed_reason,
+  # failing that, notice.txt
+  # If neither are set, returns nil
+  def self.banner
+    link = nil
+    msg = updates_disallowed_reason
+    return {msg: msg, href: nil} if msg
+    msg, link = notice
+    return {msg: msg, href: link} if msg
+    return nil
+  end
 end
 
 # for debugging purposes

Reply via email to