mirror of
https://github.com/jadolg/rocketchat-notification-action.git
synced 2026-05-31 08:37:51 +00:00
Use access tokens instead of userand password
This commit is contained in:
@@ -14,7 +14,7 @@ jobs:
|
|||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
server: ${{ secrets.ROCKETCHAT_SERVER }}
|
server: ${{ secrets.ROCKETCHAT_SERVER }}
|
||||||
user: ${{ secrets.ROCKETCHAT_USER }}
|
auth-token: ${{ secrets.ROCKETCHAT_AUTH_TOKEN }}
|
||||||
password: ${{ secrets.ROCKETCHAT_PASSWORD }}
|
user-id: ${{ secrets.ROCKETCHAT_USER_ID }}
|
||||||
channel: "#test-notifications-akiel"
|
channel: "#test-notifications-akiel"
|
||||||
message: "Test plain message from ${{ github.repository }}@${{ github.sha }}"
|
message: "Test plain message from ${{ github.repository }}@${{ github.sha }}"
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
# Rocket.Chat notifications GitHub action
|
# Rocket.Chat notifications GitHub action
|
||||||
|
|
||||||
This action will write a message on your rocket.chat server using credentials instead of a webhook.
|
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
|
## Inputs
|
||||||
|
|
||||||
### `user`
|
### `auth-token`
|
||||||
|
|
||||||
**Required** The username to login to your rocket.chat server.
|
**Required** Personal access token for your Rocket.Chat server.
|
||||||
|
|
||||||
### `password`
|
### `user-id`
|
||||||
|
|
||||||
**Required** The password to login to your rocket.chat server.
|
**Required** User ID associated with the personal access token.
|
||||||
|
|
||||||
### `message`
|
### `message`
|
||||||
|
|
||||||
@@ -39,12 +40,12 @@ jobs:
|
|||||||
- name: Push notification to rocket.chat if the job failed
|
- name: Push notification to rocket.chat if the job failed
|
||||||
id: error-notification
|
id: error-notification
|
||||||
if: ${{ failure() }}
|
if: ${{ failure() }}
|
||||||
uses: jadolg/rocketchat-notification-action@v2.0.0
|
uses: jadolg/rocketchat-notification-action@v3.0.0
|
||||||
with:
|
with:
|
||||||
server: ${{ secrets.ROCKETCHAT_SERVER }}
|
server: ${{ secrets.ROCKETCHAT_SERVER }}
|
||||||
message: Wooops! Looks like something went wrong!
|
message: Wooops! Looks like something went wrong!
|
||||||
user: ${{ secrets.ROCKETCHAT_USER }}
|
auth-token: ${{ secrets.ROCKETCHAT_AUTH_TOKEN }}
|
||||||
password: ${{ secrets.ROCKETCHAT_PASSWORD }}
|
user-id: ${{ secrets.ROCKETCHAT_USER_ID }}
|
||||||
channel: alerts
|
channel: alerts
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -63,10 +64,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Push notification when a Pull Request is created
|
- name: Push notification when a Pull Request is created
|
||||||
uses: jadolg/rocketchat-notification-action@v2.0.0
|
uses: jadolg/rocketchat-notification-action@v3.0.0
|
||||||
with:
|
with:
|
||||||
message: Woop! Woop! A new Pull Request has being created at ${{ github.event.pull_request.html_url }}
|
message: Woop! Woop! A new Pull Request has being created at ${{ github.event.pull_request.html_url }}
|
||||||
user: ${{ secrets.ROCKETCHAT_USER }}
|
auth-token: ${{ secrets.ROCKETCHAT_AUTH_TOKEN }}
|
||||||
password: ${{ secrets.ROCKETCHAT_PASSWORD }}
|
user-id: ${{ secrets.ROCKETCHAT_USER_ID }}
|
||||||
channel: python_rocketchat_api
|
channel: python_rocketchat_api
|
||||||
```
|
```
|
||||||
|
|||||||
+7
-9
@@ -1,15 +1,14 @@
|
|||||||
name: "Rocket.Chat notification with credentials"
|
name: "Rocket.Chat notification"
|
||||||
description: "Send a message to Rocket.Chat"
|
description: "Send a message to Rocket.Chat"
|
||||||
branding:
|
branding:
|
||||||
icon: "bell"
|
icon: "bell"
|
||||||
color: "red"
|
color: "red"
|
||||||
inputs:
|
inputs:
|
||||||
user:
|
auth-token:
|
||||||
description: "The username to login to your rocket.chat server"
|
description: "Personal access token for your rocket.chat server"
|
||||||
required: true
|
required: true
|
||||||
default: ""
|
user-id:
|
||||||
password:
|
description: "User ID associated with the personal access token"
|
||||||
description: "The password to login to your rocket.chat server"
|
|
||||||
required: true
|
required: true
|
||||||
message:
|
message:
|
||||||
description: "The message you want to send"
|
description: "The message you want to send"
|
||||||
@@ -29,9 +28,8 @@ runs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: ${{ github.action_path }}/entrypoint.sh
|
run: ${{ github.action_path }}/entrypoint.sh
|
||||||
env:
|
env:
|
||||||
INPUT_USER: ${{ inputs.user }}
|
INPUT_AUTH_TOKEN: ${{ inputs.auth-token }}
|
||||||
INPUT_PASSWORD: ${{ inputs.password }}
|
INPUT_USER_ID: ${{ inputs.user-id }}
|
||||||
INPUT_MESSAGE: ${{ inputs.message }}
|
INPUT_MESSAGE: ${{ inputs.message }}
|
||||||
INPUT_SERVER: ${{ inputs.server }}
|
INPUT_SERVER: ${{ inputs.server }}
|
||||||
INPUT_CHANNEL: ${{ inputs.channel }}
|
INPUT_CHANNEL: ${{ inputs.channel }}
|
||||||
INPUT_CODE: ${{ inputs.code }}
|
|
||||||
|
|||||||
+2
-30
@@ -7,28 +7,11 @@ BOLD='\033[1m'
|
|||||||
RESET='\033[0m'
|
RESET='\033[0m'
|
||||||
|
|
||||||
SERVER="${INPUT_SERVER}"
|
SERVER="${INPUT_SERVER}"
|
||||||
USER="${INPUT_USER}"
|
AUTH_TOKEN="${INPUT_AUTH_TOKEN}"
|
||||||
PASSWORD="${INPUT_PASSWORD}"
|
USER_ID="${INPUT_USER_ID}"
|
||||||
MESSAGE="${INPUT_MESSAGE}"
|
MESSAGE="${INPUT_MESSAGE}"
|
||||||
CHANNEL="${INPUT_CHANNEL}"
|
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 \
|
RESPONSE=$(curl -s -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "X-Auth-Token: ${AUTH_TOKEN}" \
|
-H "X-Auth-Token: ${AUTH_TOKEN}" \
|
||||||
@@ -49,14 +32,3 @@ if [ "$SUCCESS" != "true" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${GREEN}${BOLD}✓ Message sent${RESET} — channel: ${BOLD}${CHANNEL_NAME}${RESET}, sender: ${SENDER}, id: ${MSG_ID}"
|
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