0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

clocでgithub organizationの全てのリポジトリコード行をカウントする

Posted at

前準備

  • 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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?