Update git2tg.yml #7
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: Send Git Updates to Telegram Chat | |
on: | |
[push, pull_request, issues] | |
jobs: | |
send_updates: | |
runs-on: ubuntu-latest | |
environment: git-updates | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
repository: PayTechUz/payme-pkg | |
- name: Get commit messages | |
id: commit_messages | |
run: | | |
commit_messages=$(git log --format="%h %s" -n 5) | |
echo "::set-output name=commit_messages::$commit_messages" | |
- name: Determine Update Type and Files | |
id: update_info | |
run: | | |
if [[ ${{ github.event_name }} == 'push' ]]; then | |
update_type="Push" | |
updated_files=$(git diff --name-only HEAD^ HEAD) | |
commit_title=$(git log --format="%s" -n 1) | |
commit_description=$(git log --format="%B" -n 1) | |
elif [[ ${{ github.event_name }} == 'pull_request' ]]; then | |
update_type="PR" | |
updated_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }}) | |
commit_title="${{ github.event.pull_request.title }}" | |
commit_description="${{ github.event.pull_request.body }}" | |
else | |
update_type="Issue" | |
updated_files="" | |
commit_title="${{ github.event.issue.title }}" | |
commit_description="${{ github.event.comment.body }}" | |
fi | |
echo "::set-output name=update_type::$update_type" | |
echo "::set-output name=updated_files::$updated_files" | |
echo "::set-output name=commit_title::$commit_title" | |
echo "::set-output name=commit_description::$commit_description" | |
- name: Send updates to Telegram | |
run: | | |
telegram_message="New Update! Update Type: *${{ steps.update_info.outputs.update_type }}* Updated Files: *${{ steps.update_info.outputs.updated_files }}* Update *${{ steps.update_info.outputs.commit_title }}*: ${{ steps.update_info.outputs.commit_description }}" | |
curl -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \ | |
--header 'Content-Type: application/json' \ | |
--data-raw '{ | |
"chat_id": ${{ secrets.TELEGRAM_CHAT_ID }}, | |
"text": "'"$telegram_message"'", | |
"parse_mode": "Markdown" | |
}' |