con issue #1 #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
function generate_color { | |
echo $(( 0x$(echo -n "$1" | md5sum | cut -c1-6) )) | |
} | |
BRANCH_COLOR=$(generate_color "$BRANCH") | |
if [[ $COMMIT_MESSAGE =~ \#([0-9]+) ]]; then | |
ISSUE_NUMBER="${BASH_REMATCH[1]}" | |
ISSUE_FIELD=',{ | |
"name": "<:issue:1234567890> Issue", | |
"value": "#'"$ISSUE_NUMBER"'", | |
"inline": true | |
}' | |
else | |
ISSUE_FIELD="" | |
fi | |
JSON_PAYLOAD=$(cat <<EOF | |
{ | |
"embeds": [{ | |
"title": "Repositorio: $REPO_NAME", | |
"description": "Se ha realizado un nuevo push en la rama \`$BRANCH\`.", | |
"url": "$COMMIT_URL", | |
"color": $BRANCH_COLOR, | |
"fields": [ | |
{ | |
"name": "<:commit:1234567890> Mensaje del commit", | |
"value": "\`\`\`$COMMIT_MESSAGE\`\`\`" | |
}, | |
{ | |
"name": "<:branch:1234567890> Rama", | |
"value": "\`$BRANCH\`", | |
"inline": true | |
}, | |
{ | |
"name": "<:user:1234567890> Autor", | |
"value": "$AUTHOR", | |
"inline": true | |
} | |
$ISSUE_FIELD | |
], | |
"author": { | |
"name": "$AUTHOR_USERNAME", | |
"icon_url": "https://github.com/$AUTHOR_USERNAME.png" | |
}, | |
"footer": { | |
"text": "GitHub Actions • $TIMESTAMP" | |
} | |
}] | |
} | |
EOF | |
) | |
curl -H "Content-Type: application/json" -d "$JSON_PAYLOAD" $DISCORD_WEBHOOK |