49 lines
1.5 KiB
YAML
49 lines
1.5 KiB
YAML
name: Matrix Notification
|
|
|
|
on:
|
|
issues:
|
|
types: [opened]
|
|
pull_request:
|
|
types: [opened]
|
|
|
|
jobs:
|
|
notify:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Send notification to Matrix room
|
|
env:
|
|
HOMESERVER: ${{ secrets.MATRIX_HOMESERVER }}
|
|
ACCESS_TOKEN: ${{ secrets.MATRIX_ACCESS_TOKEN }}
|
|
ROOM_ID: ${{ secrets.MATRIX_ROOM_ID }}
|
|
EVENT_NAME: ${{ github.event_name }}
|
|
ISSUE_TITLE: ${{ github.event.issue.title }}
|
|
ISSUE_URL: ${{ github.event.issue.html_url }}
|
|
PR_TITLE: ${{ github.event.pull_request.title }}
|
|
PR_URL: ${{ github.event.pull_request.html_url }}
|
|
run: |
|
|
if [ "${EVENT_NAME}" = "issues" ]; then
|
|
PREFIX="New issue"
|
|
TITLE="${ISSUE_TITLE}"
|
|
URL="${ISSUE_URL}"
|
|
else
|
|
PREFIX="New pull request"
|
|
TITLE="${PR_TITLE}"
|
|
URL="${PR_URL}"
|
|
fi
|
|
|
|
PLAIN="${PREFIX}: ${TITLE} - ${URL}"
|
|
HTML="${PREFIX}: <b>${TITLE}</b> - <a href=\"${URL}\">${URL}</a>"
|
|
TXN_ID=$(date +%s%N)
|
|
|
|
curl -s -o /dev/null -w "%{http_code}" -X PUT \
|
|
"${HOMESERVER}/_matrix/client/v3/rooms/${ROOM_ID}/send/m.room.message/${TXN_ID}" \
|
|
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d @- <<EOF
|
|
{
|
|
"msgtype": "m.text",
|
|
"body": "${PLAIN}",
|
|
"format": "org.matrix.custom.html",
|
|
"formatted_body": "${HTML}"
|
|
}
|
|
EOF
|