Skip to content

Commit 7ede090

Browse files
committed
auth repo seeding with github app token
1 parent 153392d commit 7ede090

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

nix/modules/clawdinator.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ in
426426
systemd.services.clawdinator = {
427427
description = "CLAWDINATOR (Clawdbot gateway)";
428428
wantedBy = [ "multi-user.target" ];
429-
after = [ "network.target" ];
429+
after = [ "network.target" ] ++ lib.optional cfg.githubApp.enable "clawdinator-github-app-token.service";
430+
wants = lib.optional cfg.githubApp.enable "clawdinator-github-app-token.service";
430431

431432
environment = {
432433
CLAWDBOT_CONFIG_PATH = configPath;
@@ -502,6 +503,10 @@ in
502503

503504
systemd.services.clawdinator-github-app-token = lib.mkIf cfg.githubApp.enable {
504505
description = "CLAWDINATOR GitHub App token refresh";
506+
wantedBy = [ "multi-user.target" ];
507+
before = [ "clawdinator.service" ];
508+
after = [ "network-online.target" ];
509+
wants = [ "network-online.target" ];
505510
serviceConfig = {
506511
Type = "oneshot";
507512
User = "root";

scripts/seed-repos.sh

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ set -euo pipefail
33

44
list_file="$1"
55
base_dir="$2"
6+
auth_header=""
7+
8+
if [ -n "${GITHUB_TOKEN:-}" ]; then
9+
auth_header="Authorization: Bearer ${GITHUB_TOKEN}"
10+
fi
611

712
if [ ! -f "$list_file" ]; then
813
echo "seed-repos: missing repo list: $list_file" >&2
@@ -17,19 +22,32 @@ while IFS=$'\t' read -r name url branch; do
1722

1823
dest="$base_dir/$name"
1924
if [ ! -d "$dest/.git" ]; then
20-
if [ -n "${branch:-}" ]; then
21-
git clone --depth 1 --branch "$branch" "$url" "$dest"
25+
if [ -n "${auth_header}" ] && [[ "$url" == https://github.com/* ]]; then
26+
if [ -n "${branch:-}" ]; then
27+
git -c http.extraheader="$auth_header" clone --depth 1 --branch "$branch" "$url" "$dest"
28+
else
29+
git -c http.extraheader="$auth_header" clone --depth 1 "$url" "$dest"
30+
fi
2231
else
23-
git clone --depth 1 "$url" "$dest"
32+
if [ -n "${branch:-}" ]; then
33+
git clone --depth 1 --branch "$branch" "$url" "$dest"
34+
else
35+
git clone --depth 1 "$url" "$dest"
36+
fi
2437
fi
2538
continue
2639
fi
2740

28-
git -C "$dest" fetch --all --prune
41+
origin_url="$(git -C "$dest" config --get remote.origin.url)"
42+
if [ -n "${auth_header}" ] && [[ "$origin_url" == https://github.com/* ]]; then
43+
git -C "$dest" -c safe.directory="$dest" -c http.extraheader="$auth_header" fetch --all --prune
44+
else
45+
git -C "$dest" -c safe.directory="$dest" fetch --all --prune
46+
fi
2947
if [ -n "${branch:-}" ]; then
30-
git -C "$dest" checkout "$branch"
31-
git -C "$dest" reset --hard "origin/$branch"
48+
git -C "$dest" -c safe.directory="$dest" checkout "$branch"
49+
git -C "$dest" -c safe.directory="$dest" reset --hard "origin/$branch"
3250
else
33-
git -C "$dest" reset --hard "origin/HEAD"
51+
git -C "$dest" -c safe.directory="$dest" reset --hard "origin/HEAD"
3452
fi
3553
done < "$list_file"

0 commit comments

Comments
 (0)