about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-05-28 18:33:28 -0700
committerFranck Cuny <franck@fcuny.net>2022-05-28 18:39:00 -0700
commite7a86828d98eaa7fdf43138d0a9e3f9c9e8cc0a5 (patch)
treefdf43352418a67db60312ae307cd9ddcad2e9b92
parentfeat(gerrit): link to cgit (diff)
downloadworld-e7a86828d98eaa7fdf43138d0a9e3f9c9e8cc0a5.tar.gz
fix(cgit): generate a proper list of repositories
The logic was previously incorrect. If a repository becomes hidden in
gerrit, it will not be removed from the list. Instead, we create a
temporary file which we use to dump the new list and then move it over
the current list.

Change-Id: I990588ac98ad4024ba144c4c76ad7e4ae27202bc
Reviewed-on: https://cl.fcuny.net/c/world/+/121
Reviewed-by: Franck Cuny <franck@fcuny.net>
Diffstat (limited to '')
-rw-r--r--modules/services/cgit/default.nix4
1 files changed, 3 insertions, 1 deletions
diff --git a/modules/services/cgit/default.nix b/modules/services/cgit/default.nix
index 87cc72c..0ac6a58 100644
--- a/modules/services/cgit/default.nix
+++ b/modules/services/cgit/default.nix
@@ -55,11 +55,13 @@ in {
         serviceConfig.Type = "oneshot";
         script = ''
           mkdir -p /var/lib/cgit/cache
+          tmplist=$(mktemp)
           # as per https://gerrit-review.googlesource.com/Documentation/rest-api.html#output we need to remove `)]}' from the response
           repos=$(${pkgs.curl}/bin/curl -s -H "Content-Type: application/json" "https://cl.fcuny.net/projects/?state=ACTIVE"|sed "s/^)]}'//"|${pkgs.jq}/bin/jq -r 'to_entries | .[] | .value | .id')
           for repo in ''${repos}; do
-            grep "/var/lib/gerrit/git/''${repo}.git" /var/lib/cgit/cache/projects.list || echo "/var/lib/gerrit/git/''${repo}.git" >> /var/lib/cgit/cache/projects.list
+            echo "/var/lib/gerrit/git/''${repo}.git" >> $tmplist
           done
+          mv $tmplist /var/lib/cgit/cache/projects.list
         '';
       };
     };