commit a69f0eb820f9682651f9902ae4a79e51cfd22169
parent a7709b79b557cadeadfb9f9b3ba629c4e1e7e134
Author: Juan F. Meleiro <juan@juanmeleiro.mat.br>
Date: Wed, 1 Nov 2023 11:08:59 -0300
script: Generate automated changelog in monthly
Diffstat:
5 files changed, 55 insertions(+), 5 deletions(-)
diff --git a/lib/report.lua b/lib/report.lua
@@ -4,9 +4,24 @@ local _M = {}
local fns = {
tmp = ".tmp",
- history = ".hist"
+ history = ".hist",
+ changes = ".changes"
}
+function sincelast(log, what)
+ local all = table.filter(log, function (e) return e.what == what end)
+ table.sort(all, function (e0, e1) return e0.when >= e1.when end)
+ local last = all[1].when
+ local since = table.filter(log, function (e) return e.when >= last end)
+ return since
+end
+
+function format_events(f, es)
+ for _,e in ipairs(es) do
+ f:write(format_event(e))
+ end
+end
+
function _M.weekly(args, players, log)
defs = {
YEAR = os.date("%Y"),
@@ -36,15 +51,17 @@ function _M.weekly(args, players, log)
end
function _M.monthly(args, players, log)
- local hist = io.open(fns.history, "w")
defs = {
YEAR = os.date("%Y"),
MONTH = os.date("%m"),
DAY = os.date("%d"),
MAILDATE = os.date("%a, %d %b %Y %T %z"),
- PLAYERS = string.format("include(%s)", fns.history)
+ PLAYERS = string.format("include(%s)", fns.history),
+ CHANGES = string.format("include(%s)", fns.changes)
}
+
+ local hist = io.open(fns.history, "w")
for n,h in pairs(players) do
hist:write("===============\n"..n.."\n")
for _,e in ipairs(h) do
@@ -62,6 +79,10 @@ function _M.monthly(args, players, log)
end
hist:close()
+ local changes = io.open(fns.changes, "w")
+ format_events(changes, sincelast(log, "monthly"))
+ changes:close()
+
os.execute(string.format("m4 %s templates/monthly/monthly.m4 > %s", m4flags(defs), fns.tmp))
if args.p then
@@ -81,6 +102,7 @@ function _M.monthly(args, players, log)
end
end
os.remove(fns.history)
+ os.remove(fns.changes)
end
return _M
diff --git a/lib/utils.lua b/lib/utils.lua
@@ -81,3 +81,31 @@ function table.query(t, q)
end
return nil
end
+
+function table.filter(t, q)
+ local res = {}
+ for _,i in ipairs(t) do
+ if q(i) then
+ table.insert(res, i)
+ end
+ end
+ return res
+end
+
+function format_event(e)
+ local formats = {
+ deactivation = "Deactivated {who}",
+ deregister = "Deregistered {who}",
+ monthly = "Monthly report",
+ readdress = "Changed {who}'s address",
+ register = "Registered {who}",
+ rename = "Changed {whither}'s name from '{who}'",
+ weekly = "Weekly report",
+ activation = "Activated {who}"
+ }
+ die(not formats[e.what], string.format("No format for '%s'", e.what))
+ return string.format("* %s %s\n",
+ os.date("%Y-%m-%d %H:%M", e.when),
+ format(formats[e.what], e)
+ )
+end
diff --git a/templates/monthly/events.m4 b/templates/monthly/events.m4
@@ -0,0 +1 @@
+CHANGES
diff --git a/templates/monthly/monthly.m4 b/templates/monthly/monthly.m4
@@ -11,7 +11,7 @@ dhl
`Registrar: juan Arrivals and Departures 'YEAR-MONTH-DAY
dhl
-module(NEWS, templates/monthly/news.m4)
+module(EVENTS, templates/monthly/events.m4)
module(EDITORIAL, templates/monthly/editorial.m4)
module(WRITS OF FAGE, templates/monthly/writs.m4)
module(HISTORY, templates/monthly/history.m4)
diff --git a/templates/monthly/news.m4 b/templates/monthly/news.m4
@@ -1 +0,0 @@
-# The news.