From d3f1f6a0d9e927000d6be8e605428c2c7beb4fb5 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 5 Nov 2024 22:57:08 +0100 Subject: [PATCH] missingChangelogFinder: init --- missingChangelogFinder/run.sh | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 missingChangelogFinder/run.sh diff --git a/missingChangelogFinder/run.sh b/missingChangelogFinder/run.sh new file mode 100644 index 0000000..d0032d9 --- /dev/null +++ b/missingChangelogFinder/run.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# --- OPTIONS --- +declare -r NIXPKGS_PATH="$HOME/nixpkgs" +# See https://git.pvv.ntnu.no/oysteikt/nixpkgs-meta-dump +declare -r METADUMP="$(pwd)/result" +# --------------- + +declare -r JQ_TRANSFORMATION=' +[to_entries[] + | select (.value.changelog == null) + | { name: .key, url: .value.homepage, pos: .value.position }] +| map(select(.url != null)) +| map(select(.url|type == "string")) +| map(select(.url | test("^https?://github.com.*"))) +| .[].url |= sub("^https?://github.com/(?.+/.+/?).*"; "\(.x)") +| .[] +' + +declare -r RESULT=$(jq -c <"$METADUMP" "$JQ_TRANSFORMATION") +declare -r FZF_PREVIEW_COMMAND=" +echo {} \ +| jq -r '.url | \"repos/\\(.)\/releases\"' \ +| xargs gh api \ +| jq -r '[.[].body] | join(\"\n---------------------------------------------------------------------------\n\")' +" + +CHOSEN_ENTRY=$(fzf <<<"$RESULT" --preview "$FZF_PREVIEW_COMMAND") + +if [ "$CHOSEN_ENTRY" == "" ]; then + exit 0 +fi + +declare -r PACKAGE_URL_PIECE=$(jq -r '.url' <<<"$CHOSEN_ENTRY") +declare -r NIXPKGS_REL_POSITION=$(jq -r '.pos' <<<"$CHOSEN_ENTRY" | sed -E -s 's|/nix/store/[0-9a-z]+-source/(.+?):[[:digit:]]+|\1|') +declare -r NIXPKGS_POSITION="$NIXPKGS_PATH/$NIXPKGS_REL_POSITION" + +# Determine whether finalattrs or rec (or nothing atm) +# This could use some more work +if grep -q "finalAttrs" "$NIXPKGS_POSITION"; then + export NVIM_CLIPBOARD="changelog = \"https://github.com/${PACKAGE_URL_PIECE}/releases/tag/\${finalAttrs.src.rev}\";" +else + export NVIM_CLIPBOARD="changelog = \"https://github.com/${PACKAGE_URL_PIECE}/releases/tag/\${src.rev}\";" +fi + +nvim "$NIXPKGS_POSITION"