How Many Commits Did You Make in Last Month

Been playing with opencommit and wanted to assess how much using it on every single commit I still could track locally might cost me.

This script loops through all the ${HOME}/git directories and totals the commits made in last month.

Looks like using OpenAI’s api would cost me about $4-$5 if I’d used on every single commit and the size of the commits was smaller.

Not as bad as I’d thought it would be.

 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
#!/usr/bin/env bash
# Use https://github.com/sharkdp/fd
set -e
# Initialize variables
total_commits=0
username=$(whoami)

# Capture the directories found by fd to a variable
directories=$(fd -H --max-depth 6 "^\.git$" "$HOME/git")

# Loop through each directory

for directory in $directories; do
    # Change to the git directory
    printf "...⚙️ $(dirname $directory)" &&
    pushd "$(dirname "$directory")" &&
    # Get the repo name
    repo=$(basename "$PWD") &&
    # Get the count of commits made by a user with the partial name match of "username"
    commits=$(git log \
                --branches \
                --author=".*${username}.*" \
                --since="1 month ago" \
                --no-merges \
                --format="%H" | wc -l | awk "{print \$1}"
    ) &&
    # Output the repo name and count of commits
    printf "\t%-50s %-50s \n" "$repo", "$commits" &&
    # Add to the total count of commits
    total_commits=$((total_commits + commits)) &&
    popd
done

# Output the total count of commits
echo "Total commits: $total_commits"

Webmentions

(No webmentions yet.)