Skip to content

Instantly share code, notes, and snippets.

@epilys
Created November 7, 2023 07:48
Show Gist options
  • Save epilys/b8d390f66d6f47dbbf681df85b23af68 to your computer and use it in GitHub Desktop.
Save epilys/b8d390f66d6f47dbbf681df85b23af68 to your computer and use it in GitHub Desktop.
#!/bin/sh
check_onwers() {
CRATE_NAME="$1"
echo "INFO: querying https://crates.io/api/v1/crates/${CRATE_NAME}/owners"
OWNERS_REPLY=$(curl --silent "https://crates.io/api/v1/crates/${CRATE_NAME}/owners")
echo "INFO: API reply was ${OWNERS_REPLY}"
case "${OWNERS_REPLY}" in
*'{"errors":[{"detail":"Not Found"}]}'* ) echo "INFO: Crate ${CRATE_NAME} was not found on crates.io and is assumed unpublished." ; return 0 ;; # Crate is not published.
esac
ERROR=""
case "${OWNERS_REPLY}" in
*github:rust-vmm:gatekeepers* ) echo "OK: rust-vmm:gatekeepers is an owner." ;;
* ) echo "ERROR: rust-vmm:gatekeepers team must be in ${CRATE_NAME}'s owners." ; ERROR="yes";;
esac
for owner in $(sed -e '/^#.\+$/d' -e 's/^[*]\s*//' -e 's/[@]//g' < CODEOWNERS); do
case "${OWNERS_REPLY}" in
*${owner}* )
echo "OK: ${owner} is an owner."
;;
* )
echo "ERROR: ${owner} is not an owner." ; ERROR="yes"
esac
done
if [ -n "${ERROR}" ]; then
echo "Missing crate owners for ${CRATE_NAME}, please add them."
return 1
fi
}
for manifest_file in $(find . -type f -name Cargo.toml | grep --invert-match "/target/" | grep --invert-match "/fuzz/"); do
NAME=$(grep --max-count=1 name "${manifest_file}" | sed -e 's/name = "\(.\+\)"/\1/')
if [ -n "${NAME}" ]; then
echo "${NAME}"
check_onwers "${NAME}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment