feat: added dynamic thumbnail url

This commit is contained in:
ibo
2024-06-21 05:50:51 +02:00
committed by GitHub
parent 87304d219e
commit 3ec4300d38

View File

@@ -94,62 +94,71 @@ jobs:
- name: Upload APK to Discord and Telegram
shell: bash
run: |
# Function to fetch user details
# Prepare Discord embed
fetch_user_details() {
local login=$1
user_details=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/users/$login")
name=$(echo "$user_details" | jq -r '.name // .login')
echo "$name|$login"
avatar_url=$(echo "$user_details" | jq -r '.avatar_url')
echo "$name|$login|$avatar_url"
}
# Extract contributor names from commit log
# Extract contributor names from commit log and make unique list
committers=$(echo "$COMMIT_LOG" | sed 's/%0A/\n/g' | grep -oP '(?<=~)[^%]*')
# Get unique list of committers
committers=$(echo "$committers" | sort | uniq)
# Fetch contributors from GitHub
contributors=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/rebelonion/Dantotsu/contributors")
# Initialize developers variable
# Initialize needed variables
developers=""
committers_count=0
thumbnail_url="https://i.imgur.com/5o3Y9Jb.gif"
# Process contributors and filter by committers
while read -r login commits; do
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
developers="${developers}◗ **${name}**
- Github: [${login}](https://github.com/${login})
- Commits: ${commits}
"
committers_count=$((committers_count + 1))
# Set thumbnail_url to the committer's avatar if only one committer
if [ $committers_count -eq 1 ]; then
thumbnail_url="$avatar_url"
else
# Use default thumbnail if more than one committer
thumbnail_url="https://i.imgur.com/5o3Y9Jb.gif"
fi
fi
done < <(echo "$contributors" | jq -r '.[] | "\(.login) \(.contributions)"')
# Remove trailing newline
developers=$(echo "$developers" | sed '$ s/$//')
commit_messages=$(echo "$COMMIT_LOG" | sed 's/%0A/\n/g; s/^/\n/')
# Truncate developers if too long
# Truncate field values
max_length=1000
if [ ${#developers} -gt $max_length ]; then
developers="${developers:0:$max_length}... (and more)"
developers="${developers:0:$max_length}... (truncated)"
fi
# Process commit messages
commit_messages=$(echo "$COMMIT_LOG" | sed 's/%0A/\n/g; s/^/\n/')
if [ ${#commit_messages} -gt $max_length ]; then
commit_messages="${commit_messages:0:$max_length}... (truncated)"
fi
# Construct Discord payload
discord_data=$(jq -nc \
--arg field_value "$commit_messages" \
--arg author_value "$developers" \
--arg footer_text "Version $VERSION" \
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" \
--arg thumbnail_url "https://avatars.githubusercontent.com/u/41344259?v=4" \
--arg thumbnail_url "$thumbnail_url" \
'{
"content": "@here",
"embeds": [