~ knotless Search/
↑↓ move↵ open⇧↵ all results

johnandersen777.bsky.social/knotless

git that lives in your Atmosphere account

Forked from chadtmiller.com/knotless

0
0
51 lines · 2.3 KB Raw History
#!/bin/sh
# Whether a pull that changes the client says so in a change file, as
# AGENTS.md (Versioning) asks: one that changes what `knotless`,
# `git-remote-knotless` or `knotless-mcp` do, under crates/knotless/src or
# crates/knotless-mcp/src, adds a file under .changeset/, as `knope
# document-change` writes one, or says on a line of its body
#
#   Changeset: none
#
# for a change no one using knotless sees. Run by check.yml in a pull's
# run, at its head merged with its base; elsewhere it passes, since a
# batch and a push to main carry pulls checked already.

set -eu

[ -n "${KNOTLESS_RUN_PULL:-}" ] || { echo "not a pull: nothing to check"; exit 0; }
base="$KNOTLESS_RUN_BASE"
git config --global --add safe.directory '*'

client=$(git diff --name-only "$base" HEAD -- crates/knotless/src crates/knotless-mcp/src)
if [ -z "$client" ]; then
  echo "the client is not changed: no change file needed"
  exit 0
fi
added=$(git diff --name-only --diff-filter=A "$base" HEAD -- '.changeset/*.md')
if [ -n "$added" ]; then
  echo "the client is changed, and said so in: $added"
  exit 0
fi

# The pull's record, from its author's PDS.
did=$(printf "%s\n" "$KNOTLESS_RUN_PULL" | cut -d/ -f3)
collection=$(printf "%s\n" "$KNOTLESS_RUN_PULL" | cut -d/ -f4)
rkey=$(printf "%s\n" "$KNOTLESS_RUN_PULL" | cut -d/ -f5)
case "$did" in
  did:web:*) doc=$(curl -fsSL "https://$(echo "${did#did:web:}" | sed 's/%3A/:/g')/.well-known/did.json") ;;
  *) doc=$(curl -fsSL "${KNOTLESS_PLC_URL:-https://plc.directory}/$did") ;;
esac
pds=$(printf "%s\n" "$doc" | tr -d ' \n' | grep -o '"serviceEndpoint":"[^"]*"' | head -1 | cut -d'"' -f4)
record=$(curl -fsSL "$pds/xrpc/com.atproto.repo.getRecord?repo=$did&collection=$collection&rkey=$rkey") \
  || { echo "could not read the body of $KNOTLESS_RUN_PULL"; exit 1; }
# The body is a JSON string, its lines joined by \n.
if printf "%s\n" "$record" | grep -Eq '(^|\\n|")Changeset: none(\\n|")'; then
  echo "the client is changed, and the pull's body says no change file is needed"
  exit 0
fi

echo "the client is changed, in:"
printf "%s\n" "$client" | sed 's/^/  /'
echo "but no change file was added under .changeset/. Add one, as \`knope document-change\` writes one (AGENTS.md, Versioning), or, if no one using knotless sees the change, say so on a line of the pull's body, \`Changeset: none\`, and run its checks again."
exit 1