前準備
- cloc をインストール
- read repositoryの権限を持ったaccess tokenを環境変数
GITHUB_TOKEN
に設定
以下のスクリプトの3行目の''
にorganization idを追記して実行
count.sh
#!/bin/bash
organization=''
repositories=''
cursor='null'
has_next_page='true'
while [ $has_next_page = 'true' ]
do
response=$(curl -H "Authorization: bearer $GITHUB_TOKEN" -X POST \
-d '{ "query": "query { organization(login: \"'${organization}'\"){ repositories(first: 100, after: '${cursor}'){ nodes { name } pageInfo { hasNextPage endCursor }}}}"}' \
https://api.github.com/graphql)
echo $response
repositories=$repositories' '$(echo $response | jq -r '.data.organization.repositories.nodes[].name')
has_next_page=$(echo $response | jq '.data.organization.repositories.pageInfo.hasNextPage')
cursor='\"'$(echo $response | jq -r '.data.organization.repositories.pageInfo.endCursor')'\"'
echo $cursor
done
dir=$(mktemp -d)
echo $dir
for repository in $repositories
do
git clone --depth 1 "https://github.com/acall-inc/${repository}.git" "${dir}/${repository}"
done
cloc --timeout 0 $dir
rm -rf $dir
bash count.sh