Skip to content

Commit

Permalink
Updated fetch-repos script
Browse files Browse the repository at this point in the history
  • Loading branch information
neurobagel-bot[bot] authored and rmanaem committed Aug 24, 2024
1 parent e7e3d7e commit c14f14a
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions scripts/fetch-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,28 @@ REPOS=()
PAGE=1
PER_PAGE=100

# Fetch all repositories
while true; do
# Make the API call
# Function to fetch repository names
fetch_repos() {
if [ -n "$GH_TOKEN" ]; then
RESPONSE=$(curl -s -H "Authorization: token $GH_TOKEN" "https://api.github.com/orgs/$ORG/repos?per_page=$PER_PAGE&page=$PAGE")
curl -s -H "Authorization: token $GH_TOKEN" "https://api.github.com/orgs/$ORG/repos?per_page=$PER_PAGE&page=$PAGE"
else
RESPONSE=$(curl -s "https://api.github.com/orgs/$ORG/repos?per_page=$PER_PAGE&page=$PAGE")
curl -s "https://api.github.com/orgs/$ORG/repos?per_page=$PER_PAGE&page=$PAGE"
fi
}

# Fetch all repositories
while true; do
RESPONSE=$(fetch_repos)

# Debug: Output the response to check if we're getting data
echo "Response: $RESPONSE" >> debug.log

# Parse the JSON response to extract repository names
REPO_NAMES=$(echo "$RESPONSE" | jq -r '.[] | select(.name != ".github") | .name')

# Debug: Output the repository names to verify they are being extracted
echo "Repository Names: $REPO_NAMES" >> debug.log

# Check if no more repositories were returned
if [ -z "$REPO_NAMES" ]; then
break
Expand All @@ -36,12 +46,16 @@ while true; do
# Check if the .jsonld file exists in the annotations repository
FILE_EXISTS=$(curl -s -H "Authorization: token $GH_TOKEN" "https://api.github.com/repos/$ANNOTATIONS_REPO/contents/${JSONLD_FILE}" | jq -r '.name // empty')

# Debug: Output the result of the file existence check
echo "Checking $JSONLD_FILE: $FILE_EXISTS" >> debug.log

if [ -n "$FILE_EXISTS" ]; then
ANNOTATED=true
fi

# Add the repository information to the array
REPOS+=("{\"name\": \"$REPO_NAME\", \"annotated\": $ANNOTATED}")
echo "$REPO_NAME is annotated: $ANNOTATED"
done

# Increment page number
Expand All @@ -50,4 +64,7 @@ done

# Write repository information to the JSON file
echo "[${REPOS[*]}]" | jq '.' > "$OUTPUT_FILE"

# Debug: Output final JSON file content
cat "$OUTPUT_FILE" >> debug.log
echo "Repository information has been fetched and saved to $OUTPUT_FILE"

0 comments on commit c14f14a

Please sign in to comment.