Skip to content

Instantly share code, notes, and snippets.

@SgtPooki
Created July 21, 2022 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SgtPooki/279eb9efe3611162db178e5f67f9eb19 to your computer and use it in GitHub Desktop.
Save SgtPooki/279eb9efe3611162db178e5f67f9eb19 to your computer and use it in GitHub Desktop.
test if github repos are valid, or have been moved to another org/name, and output the new name if so.
#!/usr/bin/env bash
main() {
local valid_repos_file=$(mktemp)
local moved_repos_file=$(mktemp)
cat newline-delimited-repo-names.txt | while read repo; do {
local repo_site="https://github.com/$repo"
local status_code=$(curl -I -s -o /dev/null -w "%{http_code}" $repo_site)
# Test if the repo url has redirect
if [ "$status_code" == "301" ]; then
local new_repo_site="$(curl -Ls -o /dev/null -w %{url_effective} -I $repo_site)"
echo "$repo_site --> $new_repo_site" >> $moved_repos_file
# moved_repos+=("Repo $repo_site is redirecting to $new_repo_site")
else
echo "$repo_site" >> $valid_repos_file
# valid_repos+=($repo_site)
fi
}; done
echo "Valid repos:"
cat $valid_repos_file
rm $valid_repos_file
echo ""
echo "Moved repos:"
cat $moved_repos_file
rm $moved_repos_file
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment