chore: Add matrix notify workflow
This commit is contained in:
parent
0436f16aa9
commit
13bd504f17
1 changed files with 49 additions and 0 deletions
49
.github/workflows/matrix_notify.yaml
vendored
Normal file
49
.github/workflows/matrix_notify.yaml
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue