mirror of
https://github.com/jadolg/rocketchat-notification-action.git
synced 2026-05-31 08:37:51 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 765bd64e1d | |||
| 3a3db59139 | |||
| bde174722c | |||
| 1503fe229e | |||
| ddfa41a902 | |||
| aac8c39c7d | |||
| 300c715940 | |||
| a4fe40969a | |||
| ab24dbba08 | |||
| d43c92f406 | |||
| a00e2b9fc1 | |||
| 15e3ca292a | |||
| 0669379328 | |||
| 6ade5e1f14 |
@@ -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 }}
|
||||
user: ${{ secrets.ROCKETCHAT_USER }}
|
||||
password: ${{ secrets.ROCKETCHAT_PASSWORD }}
|
||||
channel: "#test-notifications-akiel"
|
||||
message: "Test plain message from ${{ github.repository }}@${{ github.sha }}"
|
||||
@@ -1,5 +0,0 @@
|
||||
FROM alpine:3.10
|
||||
RUN apk --no-cache add ca-certificates
|
||||
RUN wget https://github.com/aleph-engineering/rocketchat-notification/releases/download/1.4.1/rocketchat-notification -P /usr/bin/ && chmod +x /usr/bin/rocketchat-notification
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -1,4 +1,72 @@
|
||||
# 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 will write a message on your rocket.chat server using credentials instead of a webhook.
|
||||
|
||||
## Inputs
|
||||
|
||||
### `user`
|
||||
|
||||
**Required** The username to login to your rocket.chat server.
|
||||
|
||||
### `password`
|
||||
|
||||
**Required** The password to login to your rocket.chat server.
|
||||
|
||||
### `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@v1.0.1
|
||||
with:
|
||||
server: ${{ secrets.ROCKETCHAT_SERVER }}
|
||||
message: Wooops! Looks like something went wrong!
|
||||
user: ${{ secrets.ROCKETCHAT_USER }}
|
||||
password: ${{ secrets.ROCKETCHAT_PASSWORD }}
|
||||
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@v1.0.1
|
||||
with:
|
||||
message: Woop! Woop! A new Pull Request has being created at ${{ github.event.pull_request.html_url }}
|
||||
user: ${{ secrets.ROCKETCHAT_USER }}
|
||||
password: ${{ secrets.ROCKETCHAT_PASSWORD }}
|
||||
channel: python_rocketchat_api
|
||||
```
|
||||
|
||||
+25
-23
@@ -1,35 +1,37 @@
|
||||
name: 'Rocket.Chat Notification'
|
||||
description: 'Send a message to Rocket.Chat'
|
||||
name: "Rocket.Chat notification with credentials"
|
||||
description: "Send a message to Rocket.Chat"
|
||||
branding:
|
||||
icon: "bell"
|
||||
color: "red"
|
||||
inputs:
|
||||
user:
|
||||
description: 'The username to login to your rocket.chat server'
|
||||
description: "The username to login to your rocket.chat server"
|
||||
required: true
|
||||
default: ''
|
||||
default: ""
|
||||
password:
|
||||
description: 'The password to login to your rocket.chat server'
|
||||
description: "The password to login to your rocket.chat server"
|
||||
required: true
|
||||
message:
|
||||
description: 'The message you want to send'
|
||||
description: "The message you want to send"
|
||||
required: true
|
||||
server:
|
||||
description: 'Your rocket.chat server'
|
||||
description: "Your rocket.chat server"
|
||||
required: false
|
||||
default: 'https://open.rocket.chat'
|
||||
default: "https://open.rocket.chat"
|
||||
channel:
|
||||
description: 'The channel you want to write to'
|
||||
description: "The channel you want to write to"
|
||||
required: false
|
||||
default: 'GENERAL'
|
||||
code:
|
||||
description: 'Set it to true if you wish to have a code block'
|
||||
required: false
|
||||
default: 'false'
|
||||
default: "GENERAL"
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.user }}
|
||||
- ${{ inputs.password }}
|
||||
- ${{ inputs.message }}
|
||||
- ${{ inputs.server }}
|
||||
- ${{ inputs.channel }}
|
||||
- ${{ inputs.code }}
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Send Rocket.Chat notification
|
||||
shell: bash
|
||||
run: ${{ github.action_path }}/entrypoint.sh
|
||||
env:
|
||||
INPUT_USER: ${{ inputs.user }}
|
||||
INPUT_PASSWORD: ${{ inputs.password }}
|
||||
INPUT_MESSAGE: ${{ inputs.message }}
|
||||
INPUT_SERVER: ${{ inputs.server }}
|
||||
INPUT_CHANNEL: ${{ inputs.channel }}
|
||||
INPUT_CODE: ${{ inputs.code }}
|
||||
|
||||
+62
-2
@@ -1,2 +1,62 @@
|
||||
#!/usr/bin/env sh
|
||||
rocketchat-notification -u "$1" -p "$2" -m "$3" -s "$4" -c "$5" -code "$6"
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
BOLD='\033[1m'
|
||||
RESET='\033[0m'
|
||||
|
||||
SERVER="${INPUT_SERVER}"
|
||||
USER="${INPUT_USER}"
|
||||
PASSWORD="${INPUT_PASSWORD}"
|
||||
MESSAGE="${INPUT_MESSAGE}"
|
||||
CHANNEL="${INPUT_CHANNEL}"
|
||||
|
||||
LOGIN_RESPONSE=$(curl -s -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg user "$USER" --arg password "$PASSWORD" '{"user": $user, "password": $password}')" \
|
||||
"${SERVER}/api/v1/login")
|
||||
|
||||
mapfile -t login_data < <(jq -r '.data.authToken, .data.userId' <<< "$LOGIN_RESPONSE")
|
||||
AUTH_TOKEN="${login_data[0]}"
|
||||
USER_ID="${login_data[1]}"
|
||||
|
||||
if [ -z "$AUTH_TOKEN" ] || [ "$AUTH_TOKEN" = "null" ]; then
|
||||
LOGIN_ERROR=$(jq -r '.message // "unknown error"' <<< "$LOGIN_RESPONSE")
|
||||
echo -e "${RED}${BOLD}✗ Login failed${RESET} — ${LOGIN_ERROR}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✓ Logged in${RESET} — ${USER}@${SERVER}"
|
||||
|
||||
RESPONSE=$(curl -s -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")
|
||||
|
||||
mapfile -t response_data < <(jq -r '.success, .channel, .message.u.username, .message._id' <<< "$RESPONSE")
|
||||
SUCCESS="${response_data[0]}"
|
||||
CHANNEL_NAME="${response_data[1]}"
|
||||
SENDER="${response_data[2]}"
|
||||
MSG_ID="${response_data[3]}"
|
||||
|
||||
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
|
||||
|
||||
echo -e "${GREEN}${BOLD}✓ Message sent${RESET} — channel: ${BOLD}${CHANNEL_NAME}${RESET}, sender: ${SENDER}, id: ${MSG_ID}"
|
||||
|
||||
LOGOUT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
|
||||
-H "X-Auth-Token: ${AUTH_TOKEN}" \
|
||||
-H "X-User-Id: ${USER_ID}" \
|
||||
"${SERVER}/api/v1/logout") || true
|
||||
|
||||
if [ "${LOGOUT_STATUS}" = "200" ]; then
|
||||
echo -e "${GREEN}✓ Logged out${RESET}"
|
||||
else
|
||||
echo -e "${RED}✗ Logout failed${RESET} — HTTP ${LOGOUT_STATUS}"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user