Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix. Discord Embed Msg #120

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 122 additions & 123 deletions .github/workflows/publish_alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ jobs:

- name: Upload APK to Discord and Telegram
shell: bash
run: |
run: |
fetch_user_details() {
local login=$1
user_details=$(curl -s "https://api.github.com/users/$login")
name=$(echo "$user_details" | jq -r '.name // .login')
login=$(echo "$user_details" | jq -r '.login')
avatar_url=$(echo "$user_details" | jq -r '.avatar_url')
echo "$name|$login|$avatar_url"
local login=$1
user_details=$(curl -s "https://api.github.com/users/$login")
name=$(echo "$user_details" | jq -r '.name // .login')
login=$(echo "$user_details" | jq -r '.login')
avatar_url=$(echo "$user_details" | jq -r '.avatar_url')
echo "$name|$login|$avatar_url"
}

declare -A additional_info
additional_info["Sheby"]="\n Discord: <@612532963938271232>\n AniList: [Sheby](<https://anilist.co/user/5724017/>)"
additional_info["itsmechinmoy"]="\n Discord: <@523539866311720963>\n AniList: [itsmechinmoy](<https://anilist.co/user/6110204/>)"
Expand All @@ -128,81 +128,83 @@ jobs:
contributor_colors["MrBoomDev"]="#ff7e95"

hex_to_decimal() { printf '%d' "0x${1#"#"}"; }

declare -A recent_commit_counts
echo "Debug: Processing COMMIT_LOG:"
echo "$COMMIT_LOG"
while read -r count name; do
recent_commit_counts["$name"]=$count
echo "Debug: Commit count for $name: $count"
recent_commit_counts["$name"]=$count
echo "Debug: Commit count for $name: $count"
done < <(echo "$COMMIT_LOG" | sed 's/%0A/\n/g' | grep -oP '(?<=~)[^[]*' | sort | uniq -c | sort -rn)

echo "Debug: Fetching contributors from GitHub"
contributors=$(curl -s "https://api.github.com/repos/${{ github.repository }}/contributors")
echo "Debug: Contributors response:"
echo "$contributors"

sorted_contributors=$(for login in $(echo "$contributors" | jq -r '.[].login'); do
user_info=$(fetch_user_details "$login")
name=$(echo "$user_info" | cut -d'|' -f1)
count=${recent_commit_counts["$name"]:-0}
echo "$count|$login"
user_info=$(fetch_user_details "$login")
name=$(echo "$user_info" | cut -d'|' -f1)
count=${recent_commit_counts["$name"]:-0}
echo "$count|$login"
done | sort -rn | cut -d'|' -f2)

developers=""
developers=""
committers_count=0
max_commits=0
top_contributor=""
top_contributor_count=0
top_contributor_avatar=""
embed_color=$default_color

while read -r login; 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)

commit_count=${recent_commit_counts["$name"]:-0}
if [ $commit_count -gt 0 ]; then
if [ $commit_count -gt $max_commits ]; then
max_commits=$commit_count
top_contributor="$login"
top_contributor_count=1
top_contributor_avatar="$avatar_url"
embed_color=$(hex_to_decimal "${contributor_colors[$name]:-$default_color}")
elif [ $commit_count -eq $max_commits ]; then
top_contributors+=("$login")
top_contributor_count=$((top_contributor_count + 1))
embed_color=$default_color
fi

branch_commit_count=$(git log --author="$login" --author="$name" --oneline | awk '!seen[$0]++' | wc -l)

echo "Debug: recent_commit_counts contents:"
for key in "${!recent_commit_counts[@]}"; 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)

commit_count=${recent_commit_counts["$name"]:-0}
if [ $commit_count -gt 0 ]; then
if [ $commit_count -gt $max_commits ]; then
max_commits=$commit_count
top_contributors=("$login")
top_contributor_count=1
top_contributor_avatar="$avatar_url"
embed_color=$(hex_to_decimal "${contributor_colors[$name]:-$default_color}")
elif [ $commit_count -eq $max_commits ]; then
top_contributors+=("$login")
top_contributor_count=$((top_contributor_count + 1))
embed_color=$default_color
fi
echo "Debug top contributors:"
echo "$top_contributors"

branch_commit_count=$(git log --author="$login" --author="$name" --oneline | awk '!seen[$0]++' | wc -l)

echo "Debug: recent_commit_counts contents:"
for key in "${!recent_commit_counts[@]}"; do
echo "$key: ${recent_commit_counts[$key]}"
done

extra_info="${additional_info[$name]}"
if [ -n "$extra_info" ]; then
extra_info=$(echo "$extra_info" | sed 's/\\n/\n- /g')
fi

done
extra_info="${additional_info[$name]}"
if [ -n "$extra_info" ]; then
extra_info=$(echo "$extra_info" | sed 's/\\n/\n- /g')
fi
developer_entry="◗ **${name}** ${extra_info}
- Github: [${login}](https://github.com/${login})
- Commits: ${branch_commit_count}"

if [ -n "$developers" ]; then
developers="${developers}
if [ -n "$developers" ]; then
developers="${developers}
${developer_entry}"
else
developers="${developer_entry}"
fi
committers_count=$((committers_count + 1))
else
developers="${developer_entry}"
fi
committers_count=$((committers_count + 1))
fi
done <<< "$sorted_contributors"

if [ $top_contributor_count -eq 1 ]; then
thumbnail_url="$top_contributor_avatar"
else
Expand All @@ -213,102 +215,99 @@ jobs:
max_length=1000
commit_messages=$(echo "$COMMIT_LOG" | sed 's/%0A/\n/g; s/^/\n/')
if [ ${#developers} -gt $max_length ]; then
developers="${developers:0:$max_length}... (truncated)"
developers="${developers:0:$max_length}"
fi
if [ ${#commit_messages} -gt $max_length ]; then
commit_messages="${commit_messages:0:$max_length}"
commit_messages="${commit_messages:0:$max_length}"
fi

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 "$thumbnail_url" \
--arg embed_color "$embed_color" \
'{
"content": "<@&1208839371575529572>",
"embeds": [
{
"title": "New Alpha-Build dropped",
"color": $embed_color,
"fields": [
{
--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 "$thumbnail_url" \
--argjson embed_color "$embed_color" \
'{
"content": "<@&1208839371575529572>",
"embeds": [
{
"title": "New Alpha-Build dropped 🔥",
"color": $embed_color,
"fields": [
{
"name": "Commits:",
"value": $field_value,
"inline": false
},
{
"inline": true
},
{
"name": "Developers:",
"value": $author_value,
"inline": false
}
],
"footer": {
"text": $footer_text
},
"timestamp": $timestamp,
"thumbnail": {
"url": $thumbnail_url
}
}
],
"footer": {
"text": $footer_text
},
"timestamp": $timestamp,
"thumbnail": {
"url": $thumbnail_url
}
}
]
}')

echo "Debug: Final Discord payload:"
echo "$discord_data"

curl -H "Content-Type: application/json" \
-H "User-Agent: GitHub-Action-Script" \
-X POST \
"attachments": []
}')
echo "Debug: Final Discord payload:"
echo "$discord_data"

curl -H "Content-Type: application/json" \
-d "$discord_data" \
"${{ secrets.DISCORD_WEBHOOK_URL }}" || echo "Failed to send embed message"

if [ "$SKIP_BUILD" != "true" ]; then
curl -H "User-Agent: GitHub-Action-Script" \
-F "file=@app/build/outputs/apk/alpha/release/app-alpha-release-signed.apk" \
"${{ secrets.DISCORD_WEBHOOK_URL }}" || echo "Failed to send APK file"
else
echo "Skipping APK upload to Discord due to SKIP_BUILD being set to true"
fi
${{ secrets.DISCORD_WEBHOOK_URL }}
echo "You have only send an embed to discord due to SKIP_BUILD being set to true"

if [ "$SKIP_BUILD" != "true" ]; then
curl -F "payload_json=${contentbody}" \
-F "Awery_debug=@app/build/outputs/apk/alpha/release/app-alpha-release-signed.apk" \
${{ secrets.DISCORD_WEBHOOK_URL }}
else
echo "Skipping APK upload to Discord due to SKIP_BUILD being set to true"
fi

COMMIT_LOG=$(cat commit_log.txt)
if [ ${#COMMIT_LOG} -gt 1024 ]; then
COMMIT_LOG="${COMMIT_LOG:0:900}... (truncated)"
fi
TRUNCATED_COMMIT_LOG="$COMMIT_LOG"
telegram_commit_messages=$(echo "$TRUNCATED_COMMIT_LOG" | sed 's/%0A/\n/g' | while read -r line; do
telegram_commit_messages=$(echo "$COMMIT_LOG" | sed 's/%0A/\n/g' | while read -r line; do
message=$(echo "$line" | sed -E 's/● (.*) ~(.*) \[֍\]\((.*)\)/● \1 ~\2 <a href="\3">֍<\/a>/')
message=$(echo "$message" | sed -E 's/\[#([0-9]+)\]\((https:\/\/github\.com\/[^)]+)\)/<a href="\2">#\1<\/a>/g')
echo "$message"
done)

telegram_commit_messages="<blockquote>${telegram_commit_messages}</blockquote>"

echo "$developers" > dev_info.txt
echo "$developers"
chmod +x workflowscripts/tel_parser.sed
./workflowscripts/tel_parser.sed dev_info.txt >> output.txt
dev_info_tel=$(< output.txt)

telegram_dev_info="<blockquote>${dev_info_tel}</blockquote>"
echo "$telegram_dev_info"

if [ "$SKIP_BUILD" != "true" ]; then
response=$(curl -sS -f -X POST \
"https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendDocument" \
-F "chat_id=-1002206819738" \
-F "message_thread_id=174" \
-F "document=@app/build/outputs/apk/alpha/release/app-alpha-release-signed.apk" \
-F "caption=New Alpha-Build dropped 🔥
Commits:
${telegram_commit_messages}
Dev:
${telegram_dev_info}
version: ${VERSION}" \
APK_PATH="app/build/outputs/apk/alpha/release/app-alpha-release-signed.apk"
response=$(curl -sS -f -X POST \
"https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendDocument" \
-F "chat_id=-1002206819738" \
-F "message_thread_id=174" \
-F "document=@$APK_PATH" \
-F "caption=New Alpha-Build dropped🔥

Commits:
${telegram_commit_messages}
Dev:
${telegram_dev_info}
version: ${VERSION}" \
-F "parse_mode=HTML")
else
echo "Skipping because skip build set to true"
echo "skipping because skip build set to true"
fi

env:
COMMIT_LOG: ${{ env.COMMIT_LOG }}
VERSION: ${{ env.VERSION }}
Expand Down