diff --git a/.github/workflows/telegram-notifications.yml b/.github/workflows/telegram-notifications.yml index b6d64ca..f801a09 100644 --- a/.github/workflows/telegram-notifications.yml +++ b/.github/workflows/telegram-notifications.yml @@ -20,21 +20,21 @@ jobs: if: ${{ github.event_name == 'issues' }} run: | ESCAPED_BODY=$(echo "${{ github.event.issue.body }}" | sed 's/&/\&/g; s/\</g; s/>/\>/g') - echo "ESCAPED_BODY=$ESCAPED_BODY" >> $GITHUB_ENV + echo "ESCAPED_BODY=$(echo "$ESCAPED_BODY" | tr -d '\r')" >> $GITHUB_ENV # --- Escape Comment Body --- - name: Escape Comment Body if: ${{ github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment' }} run: | ESCAPED_COMMENT=$(echo "${{ github.event.comment.body }}" | sed 's/&/\&/g; s/\</g; s/>/\>/g') - echo "ESCAPED_COMMENT=$ESCAPED_COMMENT" >> $GITHUB_ENV + echo "ESCAPED_COMMENT=$(echo "$ESCAPED_COMMENT" | tr -d '\r')" >> $GITHUB_ENV # --- Escape PR Body --- - name: Escape PR Body if: ${{ github.event_name == 'pull_request' }} run: | ESCAPED_PR_BODY=$(echo "${{ github.event.pull_request.body }}" | sed 's/&/\&/g; s/\</g; s/>/\>/g') - echo "ESCAPED_PR_BODY=$ESCAPED_PR_BODY" >> $GITHUB_ENV + echo "ESCAPED_PR_BODY=$(echo "$ESCAPED_PR_BODY" | tr -d '\r')" >> $GITHUB_ENV # --- Telegram: Issue --- - name: Send Telegram (Issue) diff --git a/.github/workflows/telegram-notifications2.yml b/.github/workflows/telegram-notifications2.yml new file mode 100644 index 0000000..72bee21 --- /dev/null +++ b/.github/workflows/telegram-notifications2.yml @@ -0,0 +1,209 @@ +name: Telegram Notifications v2 + +on: + issues: + types: [opened, edited, closed] + issue_comment: + types: [created] + pull_request: + types: [opened, edited, closed, reopened] + pull_request_review_comment: + types: [created] + +jobs: + send_notification: + runs-on: ubuntu-latest + steps: + - name: Build Telegram message (Issue) + if: ${{ github.event_name == 'issues' }} + shell: bash + env: + BODY: ${{ github.event.issue.body }} + ISSUE_URL: ${{ github.event.issue.html_url }} + ACTOR: ${{ github.actor }} + ACTION: ${{ github.event.action }} + TITLE: ${{ github.event.issue.title }} + run: | + ESCAPED_BODY=$(printf '%s' "$BODY" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_ISSUE_URL=$(printf '%s' "$ISSUE_URL" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_ACTOR=$(printf '%s' "$ACTOR" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_ACTION=$(printf '%s' "$ACTION" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_TITLE=$(printf '%s' "$TITLE" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + cat > tg_message.html <<'EOF' + 🚨 Issue Notification 🚨 + EOF + + { + echo "Issue URL: $ESCAPED_ISSUE_URL" + echo "$ESCAPED_ACTOR triggered issue event: $ESCAPED_ACTION" + echo "Title: $ESCAPED_TITLE" + echo "
$ESCAPED_BODY" + } >> tg_message.html + + - name: Send Telegram (Issue) + if: ${{ github.event_name == 'issues' }} + uses: appleboy/telegram-action@v1.0.1 + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: html + disable_web_page_preview: true + message_file: tg_message.html + + - name: Build Telegram message (Issue Comment) + if: ${{ github.event_name == 'issue_comment' }} + shell: bash + env: + BODY: ${{ github.event.comment.body }} + COMMENT_URL: ${{ github.event.comment.html_url }} + ISSUE_URL: ${{ github.event.issue.html_url }} + ACTOR: ${{ github.actor }} + run: | + ESCAPED_COMMENT=$(printf '%s' "$BODY" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_COMMENT_URL=$(printf '%s' "$COMMENT_URL" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_ISSUE_URL=$(printf '%s' "$ISSUE_URL" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_ACTOR=$(printf '%s' "$ACTOR" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + cat > tg_message.html <<'EOF' + 📝 Comment on Issue 📝 + EOF + + { + echo "Comment URL: $ESCAPED_COMMENT_URL" + echo "Issue URL: $ESCAPED_ISSUE_URL" + echo "$ESCAPED_ACTOR commented:" + echo "
$ESCAPED_COMMENT" + } >> tg_message.html + + - name: Send Telegram (Issue Comment) + if: ${{ github.event_name == 'issue_comment' }} + uses: appleboy/telegram-action@v1.0.1 + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: html + disable_web_page_preview: true + message_file: tg_message.html + + - name: Build Telegram message (Pull Request) + if: ${{ github.event_name == 'pull_request' }} + shell: bash + env: + BODY: ${{ github.event.pull_request.body }} + PR_URL: ${{ github.event.pull_request.html_url }} + ACTOR: ${{ github.actor }} + ACTION: ${{ github.event.action }} + TITLE: ${{ github.event.pull_request.title }} + run: | + ESCAPED_PR_BODY=$(printf '%s' "$BODY" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_PR_URL=$(printf '%s' "$PR_URL" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_ACTOR=$(printf '%s' "$ACTOR" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_ACTION=$(printf '%s' "$ACTION" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_TITLE=$(printf '%s' "$TITLE" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + cat > tg_message.html <<'EOF' + 🚀 Pull Request Notification 🚀 + EOF + + { + echo "PR URL: $ESCAPED_PR_URL" + echo "$ESCAPED_ACTOR triggered PR event: $ESCAPED_ACTION" + echo "Title: $ESCAPED_TITLE" + echo "
$ESCAPED_PR_BODY" + } >> tg_message.html + + - name: Send Telegram (Pull Request) + if: ${{ github.event_name == 'pull_request' }} + uses: appleboy/telegram-action@v1.0.1 + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: html + disable_web_page_preview: true + message_file: tg_message.html + + - name: Build Telegram message (PR Comment) + if: ${{ github.event_name == 'pull_request_review_comment' }} + shell: bash + env: + BODY: ${{ github.event.comment.body }} + COMMENT_URL: ${{ github.event.comment.html_url }} + PR_URL: ${{ github.event.pull_request.html_url }} + ACTOR: ${{ github.actor }} + run: | + ESCAPED_COMMENT=$(printf '%s' "$BODY" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_COMMENT_URL=$(printf '%s' "$COMMENT_URL" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_PR_URL=$(printf '%s' "$PR_URL" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + ESCAPED_ACTOR=$(printf '%s' "$ACTOR" \ + | tr -d '\r' \ + | sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g') + + cat > tg_message.html <<'EOF' + 💬 Comment on Pull Request 💬 + EOF + + { + echo "Comment URL: $ESCAPED_COMMENT_URL" + echo "PR URL: $ESCAPED_PR_URL" + echo "$ESCAPED_ACTOR commented:" + echo "
$ESCAPED_COMMENT" + } >> tg_message.html + + - name: Send Telegram (PR Comment) + if: ${{ github.event_name == 'pull_request_review_comment' }} + uses: appleboy/telegram-action@v1.0.1 + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: html + disable_web_page_preview: true + message_file: tg_message.html