-
Notifications
You must be signed in to change notification settings - Fork 12
/
build-dev-docs.sh
executable file
·49 lines (40 loc) · 1.48 KB
/
build-dev-docs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
# NOTE/WARNING: This will break once we go over 100 repos.
# Then we'll need to introduce pagination.
ORG=StatCan
DOCS_DIR=docs/dev/
camelcase () {
echo $@ | tr '-' ' ' | sed 's/[^ ]\+/\L\u&/g'
}
let NUM_REPOS=$(curl --silent 'https://api.github.com/users/statcan' | jq -r .public_repos)
echo "Total number of repos: $NUM_REPOS"
echo "Fetching all READMEs. This might take a minute."
{
let i=1
while [ $NUM_REPOS -gt 0 ]; do
let "NUM_REPOS-=50"
echo curl --silent "https://api.github.com/users/StatCan/repos?per_page=50&page=$i" >&2
curl --silent \
-H 'Accept: application/vnd.github.mercy-preview+json' \
"https://api.github.com/users/StatCan/repos?per_page=50&page=$i" |
jq -cr '.[] | select(.topics | .[] | contains("daaas")) | @text "\(.name) \(.url) \(.html_url)"'
((i++))
done
} |
while IFS=" " read name url html_url; do
NAME=$(camelcase $name)
mkdir -p "$DOCS_DIR/$NAME/"
for f in CHANGELOG.md README.md DEVELOPMENT.md; do
# If the file exists, then write it to file and
# prepend the filename.
wget --quiet https://raw.githubusercontent.com/$ORG/$name/master/$f -O "$DOCS_DIR/$NAME/$f.tmp"
if [ -s "$DOCS_DIR/$NAME/$f.tmp" ]; then
cat <<EOF > "$DOCS_DIR/$NAME/$f"
$(cat "$DOCS_DIR/$NAME/$f.tmp")
# Link
[$name]($html_url)
EOF
fi
rm "$DOCS_DIR/$NAME/$f.tmp"
done
done