From 6797617f2947102b61b110595d5d63f2729c5c86 Mon Sep 17 00:00:00 2001
From: ibo <41344259+sneazy-ibo@users.noreply.github.com>
Date: Sun, 23 Jun 2024 00:42:51 +0200
Subject: [PATCH] feat: use git for commit counts
---
.github/workflows/beta.yml | 49 ++++++++++++++++----------------------
1 file changed, 20 insertions(+), 29 deletions(-)
diff --git a/.github/workflows/beta.yml b/.github/workflows/beta.yml
index 85f21743..a30d9a17 100644
--- a/.github/workflows/beta.yml
+++ b/.github/workflows/beta.yml
@@ -105,49 +105,40 @@ jobs:
avatar_url=$(echo "$user_details" | jq -r '.avatar_url')
echo "$name|$login|$avatar_url"
}
-
# Additional information for the goats
declare -A additional_info
additional_info["ibo"]=" Discord: <@951737931159187457>\n AniList: [takarealist112]()\n"
additional_info["aayush262"]=" Discord: <@918825160654598224>\n AniList: [aayush262]()\n"
additional_info["rebelonion"]=" Discord: <@714249925248024617>\n AniList: [rebelonion]()\n PornHub: [rebelonion]()\n"
-
+
# Extract contributor names from commit log and make unique list
- committers=$(echo "$COMMIT_LOG" | sed 's/%0A/\n/g' | grep -oP '(?<=~)[^%]*')
- committers=$(echo "$committers" | sort | uniq)
-
- # Get commit counts on the dev branch
- commit_counts=$(git shortlog -s -n dev)
-
- # Prepare commit count JSON
- json="{"
- while IFS= read -r line; do
- count=$(echo "$line" | awk '{print $1}')
- author=$(echo "$line" | cut -d' ' -f2-)
- json+="\"$author\": $count,"
- done <<< "$commit_counts"
- json="${json%,}}"
+ committers=$(echo "$COMMIT_LOG" | sed 's/%0A/\n/g' | grep -oP '(?<=~)[^%]*' | sort | uniq)
# Initialize needed variables
developers=""
committers_count=0
thumbnail_url="https://i.imgur.com/5o3Y9Jb.gif"
- # Process commit counts
- for login in $(echo "$json" | jq -r 'keys[]'); do
- commits=$(echo "$json" | jq -r --arg login "$login" '.[$login]')
- user_info=$(fetch_user_details "$login")
- name=$(echo "$user_info" | cut -d'|' -f1)
- login=$(echo "$user_info" | cut -d'|' -f2)
- avatar_url=$(echo "$user_info" | cut -d'|' -f3)
- if echo "$committers" | grep -qw "$name"; then
+ # Process contributors and filter by committers
+ while read -r committer; do
+ # Get commit count for this committer on the dev branch
+ commit_count=$(git rev-list --count dev --author="$committer")
+
+ # Only proceed if the committer has commits on the dev branch
+ if [ "$commit_count" -gt 0 ]; then
+ user_info=$(fetch_user_details "$committer")
+ name=$(echo "$user_info" | cut -d'|' -f1)
+ login=$(echo "$user_info" | cut -d'|' -f2)
+ avatar_url=$(echo "$user_info" | cut -d'|' -f3)
+
extra_info="${additional_info[$name]}"
if [ -n "$extra_info" ]; then
extra_info=$(echo -e "$extra_info" | sed 's/^/- /')
fi
+
developers="${developers}◗ **${name}**
${extra_info} Github: [${login}](https://github.com/${login})
- - Commits: ${commits}
+ - Commits: ${commit_count}
"
committers_count=$((committers_count + 1))
if [ $committers_count -eq 1 ]; then
@@ -156,18 +147,18 @@ jobs:
thumbnail_url="https://i.imgur.com/5o3Y9Jb.gif"
fi
fi
- done
-
+ done < <(echo "$committers")
+
# Remove trailing newline
developers=$(echo "$developers" | sed '$ s/$//')
commit_messages=$(echo "$COMMIT_LOG" | sed 's/%0A/\n/g; s/^/\n/')
-
+
# Truncate field values
max_length=1000
if [ ${#developers} -gt $max_length ]; then
developers="${developers:0:$max_length}... (truncated)"
fi
- if [ ${#commit_messages} -gt $max_length]; then
+ if [ ${#commit_messages} -gt $max_length ]; then
commit_messages="${commit_messages:0:$max_length}... (truncated)"
fi