Skip to content

Instantly share code, notes, and snippets.

@kokoichi206
Last active November 20, 2022 17:33
Show Gist options
  • Save kokoichi206/5618a2f4927a189ebef9e95795d5b9f3 to your computer and use it in GitHub Desktop.
Save kokoichi206/5618a2f4927a189ebef9e95795d5b9f3 to your computer and use it in GitHub Desktop.
今日コード何行書いた?
# 1週間分の変更履歴
## List repositories for the authenticated user
## https://docs.github.com/ja/rest/repos/repos#list-repositories-for-the-authenticated-user
## Get the weekly commit activity
## https://docs.github.com/ja/rest/metrics/statistics#get-the-weekly-commit-activity
curl -s \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $REPO_TOKEN"\
"https://api.github.com/users/$USER_NAME/repos?per_page=100" |\
jq '.[].name' |\
xargs -I@ curl -s \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $REPO_TOKEN" \
"https://api.github.com/repos/$USER_NAME/@/stats/code_frequency" |\
jq '.[-1][]' | paste - - - | awk '{print $2+$3}' |\
awk '{a += $0} END {print a}'
@kokoichi206
Copy link
Author

kokoichi206 commented Nov 20, 2022

後半の、各々のリポジトリからコミットを求めるところについて。
以下の git log を使った方が正確。

メリット

  • 特定のユーザーからのコミットのみ
  • 特定のコミットメッセージを除外(下の例は case-ignore で initial commit,first commit
  • clone さえできれば token が不要
# 出力例
# 2022/01/27 19
# 2022/01/28 389
# 2022/01/31 87
# 2022/02/04 1874
# 2022/02/05 1030
# 2022/02/06 94
cat <(git log \
        --numstat \
        --branches \
        --date=format:'%Y/%m/%d' \
        --no-merges \
        --author="$(git config user.name)" |\
    awk '$1 == "Date:" { date = $2$3$4 } ( NF == 3 && $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ ) { print date,$1,$2 }') \
    <(git log \
        --numstat \
        --branches \
        --date=format:'%Y/%m/%d' \
        --no-merges \
        --author="$(git config user.name)" \
        --all-match \
        -i --grep="initial commit" |\
 awk '$1 == "Date:" { date = $2$3$4 } ( NF == 3 && $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ ) { print date,-$1,-$2 }') \
    <(git log \
        --numstat \
        --branches \
        --date=format:'%Y/%m/%d' \
        --no-merges \
        --author="$(git config user.name)" \
        --all-match \
        -i --grep="first commit" |\
 awk '$1 == "Date:" { date = $2$3$4 } ( NF == 3 && $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ ) { print date,-$1,-$2 }') |\
awk '{ a[$1] += $2 + $3 } END { for(date in a) print date, a[date] }'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment