2024-04-21 09:46:33 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-07-06 15:05:10 +00:00
|
|
|
set -eo pipefail
|
2024-04-21 09:46:33 +00:00
|
|
|
|
2024-07-06 11:09:47 +00:00
|
|
|
# Args:
|
|
|
|
# $1 text
|
|
|
|
# $2 tooltip
|
|
|
|
# $3 error-code
|
|
|
|
print_output() {
|
|
|
|
local text="$1"
|
|
|
|
local tooltip="$2"
|
|
|
|
local error_code="$3"
|
|
|
|
|
|
|
|
if [ -z "$error_code" ]; then
|
|
|
|
output=$(jq -n \
|
|
|
|
--arg text "$text" \
|
|
|
|
--arg tooltip "$tooltip" \
|
|
|
|
--unbuffered \
|
|
|
|
--compact-output \
|
|
|
|
'{text: $text, tooltip: $tooltip}')
|
|
|
|
else
|
|
|
|
output=$(jq -n \
|
|
|
|
--arg text "$text" \
|
|
|
|
--arg tooltip "$tooltip" \
|
|
|
|
--unbuffered \
|
|
|
|
--compact-output \
|
|
|
|
'{text: $text, tooltip: $tooltip}')
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$output"
|
|
|
|
}
|
|
|
|
|
2024-04-21 09:46:33 +00:00
|
|
|
FLAKE_DIR="/home/torjus/nixos"
|
|
|
|
NIXPKGS_DIR="/home/torjus/git/nixpkgs"
|
|
|
|
|
|
|
|
flake_metadata=$(nix flake metadata --json "$FLAKE_DIR" 2>/dev/null)
|
|
|
|
|
2024-05-28 17:47:42 +00:00
|
|
|
unstable_input=$(echo "$flake_metadata" | jq '.locks.nodes.root.inputs.nixpkgs')
|
2024-04-21 09:46:33 +00:00
|
|
|
unstable_rev=$(echo "$flake_metadata" | jq -r ".locks.nodes.$unstable_input.locked.rev")
|
|
|
|
unstable_branch=$(echo "$flake_metadata" | jq -r ".locks.nodes.$unstable_input.original.ref")
|
|
|
|
|
2024-07-06 11:09:47 +00:00
|
|
|
cd "$NIXPKGS_DIR" || print_output "?" "Could not find git repo dir" 1
|
2024-07-06 15:05:10 +00:00
|
|
|
if ! git fetch -q --all; then
|
|
|
|
print_output "?" "Unable to fetch commits" 1
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-07-06 11:09:47 +00:00
|
|
|
if ! unstable_commit_count=$(git rev-list --count "$unstable_rev..origin/$unstable_branch"); then
|
|
|
|
print_output "?" "Unable to list commits" 1
|
2024-07-06 15:05:10 +00:00
|
|
|
exit 1
|
2024-07-06 11:09:47 +00:00
|
|
|
fi
|
2024-04-21 09:46:33 +00:00
|
|
|
|
2024-05-28 17:47:42 +00:00
|
|
|
text="$unstable_commit_count"
|
|
|
|
tooltip="${unstable_branch}: ${unstable_commit_count}"
|
2024-04-29 09:51:25 +00:00
|
|
|
|
2024-07-06 11:09:47 +00:00
|
|
|
print_output "$text" "$tooltip" 0
|