diff --git a/scripts/update-stars.sh b/scripts/update-stars.sh new file mode 100755 index 0000000..0b5df81 --- /dev/null +++ b/scripts/update-stars.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Updates the `stars` field for each project in src/lib/consts.ts using +# the GitHub CLI. Requires `gh` to be installed and authenticated +# (`gh auth login`). + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +FILE="$ROOT/src/lib/consts.ts" + +if [[ ! -f "$FILE" ]]; then + echo "error: $FILE not found" >&2 + exit 1 +fi + +if ! command -v gh >/dev/null 2>&1; then + echo "error: gh cli is required" >&2 + exit 1 +fi + +fetch_stars() { + local slug="$1" + gh api "repos/$slug" --jq '.stargazers_count' +} + +tmp="$(mktemp)" +trap 'rm -f "$tmp"' EXIT + +pending_slug="" +while IFS= read -r line || [[ -n "$line" ]]; do + if [[ "$line" =~ repo:[[:space:]]+\"https://github\.com/([^\"]+)\" ]]; then + pending_slug="${BASH_REMATCH[1]}" + printf '%s\n' "$line" + continue + fi + + if [[ -n "$pending_slug" && "$line" =~ ^([[:space:]]*)stars:[[:space:]]+[0-9]+, ]]; then + indent="${BASH_REMATCH[1]}" + if count="$(fetch_stars "$pending_slug")" && [[ "$count" =~ ^[0-9]+$ ]]; then + echo " $pending_slug -> $count" >&2 + printf '%sstars: %s,\n' "$indent" "$count" + else + echo " $pending_slug: failed, keeping existing value" >&2 + printf '%s\n' "$line" + fi + pending_slug="" + continue + fi + + printf '%s\n' "$line" +done < "$FILE" > "$tmp" + +mv "$tmp" "$FILE" +trap - EXIT +echo "done." diff --git a/src/lib/consts.ts b/src/lib/consts.ts index ec50e39..78b2b39 100644 --- a/src/lib/consts.ts +++ b/src/lib/consts.ts @@ -20,7 +20,7 @@ export const PROJECTS = [ icon: "/repos/catppuccin-nix.webp", href: null, repo: "https://github.com/catppuccin/nix", - stars: 709, + stars: 717, }, { name: "izrss", @@ -28,7 +28,7 @@ export const PROJECTS = [ icon: null, href: null, repo: "https://github.com/isabelroses/izrss", - stars: 56, + stars: 58, }, { name: "Dotfiles", @@ -36,7 +36,7 @@ export const PROJECTS = [ icon: "/repos/dotfiles.svg", href: null, repo: "https://github.com/isabelroses/dotfiles", - stars: 392, + stars: 397, }, { name: "freeze.nvim",