Created
October 8, 2024 10:51
-
-
Save aeltorio/88aa8932df0b4d9f35a46e35d9ad4929 to your computer and use it in GitHub Desktop.
Collect and Concatenate All README.md Files of a GitHub Organization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set the GitHub organization from the environment variable or default to "sctg-development" | |
GITHUB_ORG=${GITHUB_ORG:-"sctg-development"} | |
# Set the GitHub API endpoint | |
GH_API_Endpoint="https://api.github.com/orgs/${GITHUB_ORG}/repos" | |
# Check if the required command-line tools are installed | |
if ! command -v curl &> /dev/null; then | |
echo "curl command not found. Please install curl." | |
exit 1 | |
fi | |
if ! command -v jq &> /dev/null; then | |
echo "jq command not found. Please install jq." | |
exit 1 | |
fi | |
# Retrieve the list of repositories for the organization | |
repos=$(curl -s -X GET "${GH_API_Endpoint}" | jq -r '.[] | .name') | |
# Loop through each repository and retrieve the README.md file | |
for repo in $repos; do | |
# Set the repository README.md API endpoint | |
repo_readme_endpoint="https://raw.githubusercontent.com/${GITHUB_ORG}/${repo}/master/README.md" | |
# Retrieve and save the README.md file | |
curl -s -X GET "${repo_readme_endpoint}" -o "${repo}_README.md" | |
echo "Retrieved README.md for repository: ${repo}" | |
done | |
# Create a single README.md file with the contents of all README.md files separated by a line containing "# repository name" | |
for repo in $repos; do | |
echo "# ${repo}" >> all_READMEMD.md | |
cat "${repo}_README.md" >> all_READMEMD.md | |
echo "" >> all_READMEMD.md | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment