mirror of
https://github.com/jadolg/rocketchat-notification-action.git
synced 2026-05-31 08:37:51 +00:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b88d4128c7 | |||
| 96b6b24841 | |||
| c551865cfd | |||
| d9187e3d33 | |||
| 765bd64e1d | |||
| 3a3db59139 | |||
| bde174722c | |||
| 1503fe229e | |||
| ddfa41a902 | |||
| aac8c39c7d | |||
| 300c715940 | |||
| a4fe40969a | |||
| ab24dbba08 | |||
| d43c92f406 | |||
| a00e2b9fc1 | |||
| 15e3ca292a | |||
| 0669379328 | |||
| 6ade5e1f14 | |||
| 0d2a559372 | |||
| d3cec0115d | |||
| 9f19deb8ed | |||
| 3da587e98c | |||
| 71e5ac5817 | |||
| bbfd4d87d6 | |||
| 0c1fe6ed0b | |||
| 96cf4f14d8 | |||
| b1c8b450a3 | |||
| 7d1c5cce10 | |||
| dd226a1f62 |
@@ -0,0 +1,20 @@
|
||||
name: Test action
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Send plain message
|
||||
uses: ./
|
||||
with:
|
||||
server: ${{ secrets.ROCKETCHAT_SERVER }}
|
||||
auth-token: ${{ secrets.ROCKETCHAT_AUTH_TOKEN }}
|
||||
user-id: ${{ secrets.ROCKETCHAT_USER_ID }}
|
||||
channel: "#test-notifications-akiel"
|
||||
message: "Test plain message from ${{ github.repository }}@${{ github.sha }}"
|
||||
@@ -1,3 +0,0 @@
|
||||
FROM alpine:3.10
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -1,4 +1,73 @@
|
||||
# Rocket.Chat notifications GitHub action
|
||||
|
||||
This is my first action so I'll experiment here.
|
||||
I'll write nice docs once I have at least a POC.
|
||||
This action sends a message to a Rocket.Chat server using a personal access token.
|
||||
Read <https://docs.rocket.chat/docs/manage-personal-access-tokens> to obtain a new access token.
|
||||
|
||||
## Inputs
|
||||
|
||||
### `auth-token`
|
||||
|
||||
**Required** Personal access token for your Rocket.Chat server.
|
||||
|
||||
### `user-id`
|
||||
|
||||
**Required** User ID associated with the personal access token.
|
||||
|
||||
### `message`
|
||||
|
||||
**Required** The message you want to send.
|
||||
|
||||
### `server`
|
||||
|
||||
Your rocket.chat server. Default `"https://open.rocket.chat"`.
|
||||
|
||||
### `channel`
|
||||
|
||||
The channel you want to write to. Default `"GENERAL"`.
|
||||
|
||||
## Example usage
|
||||
|
||||
### Push a chat notification when your job fails
|
||||
|
||||
```yaml
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
rocketchat_job:
|
||||
runs-on: ubuntu-latest
|
||||
name: Push notification to rocket.chat
|
||||
steps:
|
||||
- name: Push notification to rocket.chat if the job failed
|
||||
id: error-notification
|
||||
if: ${{ failure() }}
|
||||
uses: jadolg/rocketchat-notification-action@v3.0.0
|
||||
with:
|
||||
server: ${{ secrets.ROCKETCHAT_SERVER }}
|
||||
message: Wooops! Looks like something went wrong!
|
||||
auth-token: ${{ secrets.ROCKETCHAT_AUTH_TOKEN }}
|
||||
user-id: ${{ secrets.ROCKETCHAT_USER_ID }}
|
||||
channel: alerts
|
||||
```
|
||||
|
||||
### Push a chat notification when someone opens a pull request in your project
|
||||
|
||||
```yaml
|
||||
name: PR_alert
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened]
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
alert:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Push notification when a Pull Request is created
|
||||
uses: jadolg/rocketchat-notification-action@v3.0.0
|
||||
with:
|
||||
message: Woop! Woop! A new Pull Request has being created at ${{ github.event.pull_request.html_url }}
|
||||
auth-token: ${{ secrets.ROCKETCHAT_AUTH_TOKEN }}
|
||||
user-id: ${{ secrets.ROCKETCHAT_USER_ID }}
|
||||
channel: python_rocketchat_api
|
||||
```
|
||||
|
||||
+34
-8
@@ -1,9 +1,35 @@
|
||||
# action.yml
|
||||
name: 'Rocket.Chat Notification'
|
||||
description: 'Send a message to Rocket.Chat'
|
||||
outputs:
|
||||
response_code:
|
||||
description: 'The response code for the http call'
|
||||
name: "Rocket.Chat notification"
|
||||
description: "Send a message to Rocket.Chat"
|
||||
branding:
|
||||
icon: "bell"
|
||||
color: "red"
|
||||
inputs:
|
||||
auth-token:
|
||||
description: "Personal access token for your rocket.chat server"
|
||||
required: true
|
||||
user-id:
|
||||
description: "User ID associated with the personal access token"
|
||||
required: true
|
||||
message:
|
||||
description: "The message you want to send"
|
||||
required: true
|
||||
server:
|
||||
description: "Your rocket.chat server"
|
||||
required: false
|
||||
default: "https://open.rocket.chat"
|
||||
channel:
|
||||
description: "The channel you want to write to"
|
||||
required: false
|
||||
default: "GENERAL"
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Send Rocket.Chat notification
|
||||
shell: bash
|
||||
run: ${{ github.action_path }}/entrypoint.sh
|
||||
env:
|
||||
INPUT_AUTH_TOKEN: ${{ inputs.auth-token }}
|
||||
INPUT_USER_ID: ${{ inputs.user-id }}
|
||||
INPUT_MESSAGE: ${{ inputs.message }}
|
||||
INPUT_SERVER: ${{ inputs.server }}
|
||||
INPUT_CHANNEL: ${{ inputs.channel }}
|
||||
|
||||
+48
-1
@@ -1,2 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
echo "something going on here"
|
||||
set -euo pipefail
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
BOLD='\033[1m'
|
||||
RESET='\033[0m'
|
||||
|
||||
SERVER="${INPUT_SERVER}"
|
||||
AUTH_TOKEN="${INPUT_AUTH_TOKEN}"
|
||||
USER_ID="${INPUT_USER_ID}"
|
||||
MESSAGE="${INPUT_MESSAGE}"
|
||||
CHANNEL="${INPUT_CHANNEL}"
|
||||
|
||||
HTTP_CODE=$(curl -s -o /tmp/rc_response -w "%{http_code}" -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-Auth-Token: ${AUTH_TOKEN}" \
|
||||
-H "X-User-Id: ${USER_ID}" \
|
||||
-d "$(jq -n --arg channel "$CHANNEL" --arg text "$MESSAGE" '{"channel": $channel, "text": $text}')" \
|
||||
"${SERVER}/api/v1/chat.postMessage") || {
|
||||
echo -e "${RED}${BOLD}✗ Connection failed${RESET} — could not reach ${SERVER}"
|
||||
exit 1
|
||||
}
|
||||
RESPONSE=$(cat /tmp/rc_response)
|
||||
|
||||
if [ "$HTTP_CODE" = "401" ]; then
|
||||
echo -e "${RED}${BOLD}✗ Authentication failed${RESET} — invalid auth-token or user-id"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! jq -e '.success' <<< "$RESPONSE" > /dev/null 2>&1; then
|
||||
echo -e "${RED}${BOLD}✗ Unexpected response${RESET} (HTTP ${HTTP_CODE})"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SUCCESS=$(jq -r '.success' <<< "$RESPONSE")
|
||||
|
||||
if [ "$SUCCESS" != "true" ]; then
|
||||
ERROR=$(jq -r '.error // .message // "unknown error"' <<< "$RESPONSE")
|
||||
echo -e "${RED}${BOLD}✗ Failed to send message${RESET} — ${ERROR}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mapfile -t response_data < <(jq -r '.channel, .message.u.username, .message._id' <<< "$RESPONSE")
|
||||
CHANNEL_NAME="${response_data[0]}"
|
||||
SENDER="${response_data[1]}"
|
||||
MSG_ID="${response_data[2]}"
|
||||
|
||||
echo -e "${GREEN}${BOLD}✓ Message sent${RESET} — channel: ${BOLD}${CHANNEL_NAME}${RESET}, sender: ${SENDER}, id: ${MSG_ID}"
|
||||
|
||||
Reference in New Issue
Block a user