feat: testing dynamic developer field

This commit is contained in:
ibo
2024-06-21 02:10:54 +02:00
committed by GitHub
parent bbbb13e4be
commit 9c4936f988

View File

@@ -96,22 +96,39 @@ jobs:
- name: Upload APK to Discord and Telegram
shell: bash
run: |
# Discord
commit_messages=$(echo "$COMMIT_LOG" | sed 's/%0A/\n/g; s/^/\n/')
# Truncate commit messages if they are too long
# Function to fetch user details
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"
}
# Fetch contributors
contributors=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/rebelonion/Dantotsu/contributors")
# Process contributors
developers=""
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)
developers="${developers}◗ **${name}**\n- Github: [${login}](https://github.com/${login})\n- Commits: ${commits}\n\n"
done < <(echo "$contributors" | jq -r '.[] | "\(.login) \(.contributions)"')
# Truncate developers if too long
max_length=1000
if [ ${#developers} -gt $max_length ]; then
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
authors=$(echo "$COMMIT_LOG" | sed 's/%0A/\n/g' | grep -oP '~\K[^\n]+' | sort -u | sed 's/^/◗ **/' | sed 's/$/**/' | paste -sd '\n' -)
max_authors_length=800
if [ ${#authors} -gt $max_authors_length ]; then
authors="${authors:0:$max_authors_length}... (and more)"
fi
echo "$authors"
# Construct Discord payload
discord_data=$(jq -nc \
--arg field_value "$commit_messages" \
--arg author_value "$authors" \
--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" \
@@ -144,19 +161,22 @@ jobs:
],
"attachments": []
}')
echo "$discord_data"
# Send Discord message
curl -H "Content-Type: application/json" \
-d "$discord_data" \
${{ secrets.DISCORD_WEBHOOK }}
echo "$response_headers"
curl -F "payload_json=${contentbody}" -F "dantotsu_debug=@app/build/outputs/apk/google/alpha/app-google-alpha.apk" ${{ secrets.DISCORD_WEBHOOK }}
#Telegram
# Upload APK to Discord
curl -F "payload_json=${contentbody}" \
-F "dantotsu_debug=@app/build/outputs/apk/google/alpha/app-google-alpha.apk" \
${{ secrets.DISCORD_WEBHOOK }}
# Send Telegram message and upload APK
curl -F "chat_id=${{ secrets.TELEGRAM_CHANNEL_ID }}" \
-F "document=@app/build/outputs/apk/google/alpha/app-google-alpha.apk" \
-F "caption=Alpha-Build: ${VERSION}: ${commit_messages}" \
https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendDocument
env:
COMMIT_LOG: ${{ env.COMMIT_LOG }}
VERSION: ${{ env.VERSION }}