Skip to content

a la uno again #1

a la uno again #1 #6

name: Discord Notification
on:
push:
branches:
- "*"
jobs:
send_notification:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Extract commit information and send Discord message
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
AUTHOR=$(git log -1 --pretty=format:'%an')
AUTHOR_USERNAME=$(echo "${{ github.actor }}")
BRANCH=$(echo ${{ github.ref }} | awk -F'/' '{print $NF}')
REPO_NAME=$(echo ${{ github.repository }} | awk -F'/' '{print $NF}')
COMMIT_URL="${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}"
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Función para generar un color basado en el nombre de la rama
function generate_color {
echo $(( 0x$(echo -n "$1" | md5sum | cut -c1-6) ))
}
BRANCH_COLOR=$(generate_color "$BRANCH")
REPO_COLOR=$(generate_color "$REPO_NAME")
# Detectar si hay un número de issue en el mensaje del commit
if [[ $COMMIT_MESSAGE =~ \#([0-9]+) ]]; then
ISSUE_NUMBER="${BASH_REMATCH[1]}"
ISSUE_FIELD=',{
"name": "Issue",
"value": "#'"$ISSUE_NUMBER"'",
"inline": true
}'
else
ISSUE_FIELD=""
fi
JSON_PAYLOAD=$(cat <<EOF
{
"embeds": [{
"title": "Repositorio: \`\`\`ansi\n[0;30;43m $REPO_NAME \u001b[0m\`\`\`",
"url": "$COMMIT_URL",
"color": $BRANCH_COLOR,
"fields": [
{
"name": "Mensaje del commit",
"value": "\`\`\`$COMMIT_MESSAGE\`\`\`"
},
{
"name": "▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬",
"value": "\u200b"
},
{
"name": "Rama",
"value": "\`$BRANCH\`",
"inline": true
},
{
"name": "Autor",
"value": "$AUTHOR",
"inline": true
}
$ISSUE_FIELD
],
"author": {
"name": "$AUTHOR",
"icon_url": "https://github.com/$AUTHOR_USERNAME.png"
},
"footer": {
"text": "GitHub Actions",
"icon_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
},
"timestamp": "$TIMESTAMP"
}]
}
EOF
)
curl -H "Content-Type: application/json" -d "$JSON_PAYLOAD" $DISCORD_WEBHOOK