Skip to content

Instantly share code, notes, and snippets.

@andrejmaya
Created March 17, 2023 06:39
Show Gist options
  • Save andrejmaya/56f92bc607dcb0f8935ed2262ab32561 to your computer and use it in GitHub Desktop.
Save andrejmaya/56f92bc607dcb0f8935ed2262ab32561 to your computer and use it in GitHub Desktop.
Find usage of repos (like action repos) across your Github Organization
export GITHUB_ORG=<YOUR_GITHUB_ORG>
#!/bin/bash
REPO_PATTERN=$1
if [[ ! -z $REPO_PATTERN ]];then
repos=$(gh search repos --match=name ${GITHUB_ORG}/$REPO_PATTERN | grep ${GITHUB_ORG}/$REPO_PATTERN | awk '{gsub("${GITHUB_ORG}/","",$1); print $1}')
for repo in $repos
do
echo -e "\n\n\nRepository $repo is used in these repositories:"
gh api -X GET search/code -f q="org:${GITHUB_ORG} ${GITHUB_ORG}/$repo extension:yml" --jq '.items[].repository.name'
done
else
echo "Usage: $0 <YOUR_PATTERN (e.g. 'mirror-', 'packer-' etc.)>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment