@@ -24,15 +24,9 @@ fetch_repos() {
24
24
while true ; do
25
25
RESPONSE=$( fetch_repos)
26
26
27
- # Debug: Output the raw response
28
- echo " Response: $RESPONSE " >> debug.log
29
-
30
27
# Parse the JSON response to extract repository names
31
28
REPO_NAMES=$( echo " $RESPONSE " | jq -r ' .[] | select(.name != ".github") | .name' )
32
29
33
- # Debug: Output the extracted repository names
34
- echo " Repository Names: $REPO_NAMES " >> debug.log
35
-
36
30
# Check if no more repositories were returned
37
31
if [ -z " $REPO_NAMES " ]; then
38
32
break
@@ -46,9 +40,6 @@ while true; do
46
40
# Check if the .jsonld file exists in the annotations repository
47
41
FILE_EXISTS=$( curl -s -H " Authorization: token $GH_TOKEN " " https://api.github.com/repos/$ANNOTATIONS_REPO /contents/${JSONLD_FILE} " | jq -r ' .name // empty' )
48
42
49
- # Debug: Output the result of the file existence check
50
- echo " Checking $JSONLD_FILE : $FILE_EXISTS " >> debug.log
51
-
52
43
if [ -n " $FILE_EXISTS " ]; then
53
44
ANNOTATED=true
54
45
fi
@@ -61,9 +52,14 @@ while true; do
61
52
(( PAGE++ ))
62
53
done
63
54
64
- # Write repository information to the JSON file, ensuring it's clean
65
- echo " [${REPOS[*]} ]" | jq ' .' > " $OUTPUT_FILE "
55
+ # Refactor JSON output handling
56
+ if [ ${# REPOS[@]} -eq 0 ]; then
57
+ # If no repositories were found, write an empty array
58
+ echo " []" > " $OUTPUT_FILE "
59
+ else
60
+ # Join the REPOS array into a single JSON array
61
+ JSON_ARRAY=$( printf " %s," " ${REPOS[@]} " | sed ' s/,$//' ) # Remove trailing comma
62
+ echo " [$JSON_ARRAY ]" | jq ' .' > " $OUTPUT_FILE "
63
+ fi
66
64
67
- # Debug: Output final JSON file content
68
- cat " $OUTPUT_FILE " >> debug.log
69
65
echo " Repository information has been fetched and saved to $OUTPUT_FILE "
0 commit comments