feat(web/todolist): Implement a "todo-list" page generator

This invokes ripgrep & jq to construct a list of TODOs from known
users across depot sources, and dumps it into a static page that we
can serve.

The structure is relatively simple, but it might be useful. See here
for an example of what this looks like:

https: //tazj.in/blobs/todos.png
Change-Id: I1edef56606273584ab886b9e762c8ed4d210919d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1296
Tested-by: BuildkiteCI
Reviewed-by: Alyssa Ross <hi@alyssa.is>
This commit is contained in:
Vincent Ambo 2020-07-20 00:34:14 +01:00 committed by tazjin
parent 15afa8472e
commit 259750277a
3 changed files with 139 additions and 0 deletions

View file

@ -74,6 +74,7 @@ in lib.fix (self: {
tools.cheddar
tools.nsfv-setup
web.cgit-taz
web.todolist
web.tvl
(drvify "getBins-tests" nix.getBins.tests)
]

113
web/todolist/default.nix Normal file
View file

@ -0,0 +1,113 @@
# Generates a simple web view of open TODOs in the depot.
#
# Only TODOs that match the form 'TODO($username)' are considered, and
# only for users that are known to us.
{ depot, lib, ... }:
with depot.nix.yants;
let
inherit (depot.third_party)
jq
ripgrep
runCommandNoCC
writeText
;
inherit (builtins)
elem
filter
fromJSON
head
readFile
;
inherit (lib) concatStringsSep;
# We should extract this from TVL slapd, but that data is not easily
# accessible right now.
knownUsers = [
"tazjin"
"riking"
"Profpatsch"
"grfn"
"lukegb"
];
todo = struct {
file = string;
line = int;
todo = string;
user = string;
};
allTodos = fromJSON (readFile (runCommandNoCC "depot-todos.json" {} ''
${ripgrep}/bin/rg --json 'TODO\(\w+\):.*$' ${depot.depotPath} | \
${jq}/bin/jq -s -f ${./extract-todos.jq} > $out
''));
knownUserTodos = filter (todos: elem (head todos).user knownUsers) allTodos;
fileLink = defun [ todo string ] (t:
''<a style="color: inherit;"
href="https://cs.tvl.fyi/depot/-/blob/${t.file}#L${toString t.line}">
//${t.file}:${toString t.line}</a>'');
todoElement = defun [ todo string ] (t: ''
<p>At ${fileLink t}:</p>
<blockquote>${t.todo}</blockquote>
'');
userParagraph = todos:
let user = (head todos).user;
in ''
<p>
<h3>${user}</h3>
${concatStringsSep "\n" (map todoElement todos)}
</p>
<hr>
'';
todoPage = writeText "index.html" ''
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="TVL's todo-list">
<link rel="stylesheet" type="text/css" href="static/tazjin.css" media="all">
<link rel="icon" type="image/webp" href="static/favicon.webp">
<title>TVL's todo-list</title>
<style>
svg {
max-width: inherit;
height: auto;
}
</style>
</head>
<body class="dark">
<header>
<h1><a class="blog-title" href="/">The Virus Lounge's todo-list</a> </h1>
<hr>
</header>
<main>
${concatStringsSep "\n" (map userParagraph knownUserTodos)}
</main>
<footer>
<p class="footer">
<a class="uncoloured-link" href="https://tvl.fyi">homepage</a>
|
<a class="uncoloured-link" href="https://cs.tvl.fyi/depot/-/blob/README.md">code</a>
|
<a class="uncoloured-link" href="https://cl.tvl.fyi">reviews</a>
</p>
<p class="lod">_</p>
</footer>
</body>
'';
in runCommandNoCC "tvl-todos" {} ''
mkdir $out
cp ${todoPage} $out/index.html
ln -s ${depot.web.tvl}/static $out/static
''

View file

@ -0,0 +1,25 @@
# Simple jq script to extract all TODO comments in the code base from
# ripgrep's JSON output.
#
# This assumes that the filter used is something like 'TODO\(\w+\):'
# Construct a structure with only the fields we need to populate the
# page.
def simplify_match:
.data.submatches[0].match.text as $todo
| {
file: (.data.path.text | sub("/nix/store/.+-depot/"; "")),
line: .data.line_number,
todo: $todo,
user: ($todo | capture("TODO\\((?<user>\\w+)\\)") | .user),
};
# Group all matches first by the user and return them in sorted order
# by the file in which they appear. This matches the presentation
# order on the website.
def group_by_user: .
| group_by(.user)
| map(sort_by(.file));
# main:
map(select(.type == "match") | simplify_match) | group_by_user