Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

allow passing emoji for avatar icon #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
SLACK_WEBHOOK=
SLACK_CHANNEL=
SLACK_AVATAR=sender
SLACK_EMOJI=
SLACK_USERNAME=$USER
# SLACK_CUSTOM_PAYLOAD=

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This GitHub action is part of a list of Actions that are located in an other rep
SLACK_USERNAME: ThisIsMyUsername # Optional. (defaults to webhook app)
SLACK_CHANNEL: general # Optional. (defaults to webhook)
SLACK_AVATAR: repository # Optional. can be (repository, sender, an URL) (defaults to webhook app avatar)
SLACK_EMOJI: octocat # Optional. (defaults to null)
uses: Ilshidur/action-slack@2.0.2
with:
args: 'A new commit has been pushed.' # Optional
Expand Down Expand Up @@ -62,6 +63,7 @@ e.g.: `Action called: {{ GITHUB_ACTION }} as {{ EVENT_PAYLOAD.pull_request.id }}
* **`SLACK_USERNAME`** *(optional)* : overrides username. Defaults to the Slack webhook bot name.
* **`SLACK_CHANNEL`** *(optional)* : overrides the default channel of the webhook. If not set, the message will be sent to the channel associated to the webhook.
* **`SLACK_AVATAR`** *(optional)* : overrides the message avatar. Can be `'repository'`, `'sender'` or an URL. If not set, the avatar of the Slack webhook's bot picture will be used.
* **`SLACK_EMOJI`** *(optional)* : overrides the message avatar. If not set, the avatar of the Slack webhook's bot picture will be used.
* **`SLACK_CUSTOM_PAYLOAD`** *(advanced)* : JSON string that sets full payload. instructions see [CUSTOM_PAYLOAD](CUSTOM_PAYLOAD.md)

## Debugging / testing / development
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;

const {
SLACK_AVATAR,
SLACK_EMOJI,
SLACK_CUSTOM_PAYLOAD,
GITHUB_EVENT_PATH,
GITHUB_ACTOR,
Expand Down Expand Up @@ -40,3 +41,7 @@ exports.selectAvatar = () => {
default: return SLACK_AVATAR || false;
}
};

exports.emoji = () => {
return SLACK_EMOJI ? `:${SLACK_EMOJI}:` : null
};
8 changes: 7 additions & 1 deletion message.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@description
Message payload to be sent with Slack webhook
*/
const { selectAvatar, getMessage, parsePayload } = require("./handlers");
const { selectAvatar, emoji, getMessage, parsePayload } = require("./handlers");

const {
SLACK_USERNAME,
Expand Down Expand Up @@ -33,6 +33,12 @@ const messageSingleton = (() => {
*/
if (selectAvatar()) message.icon_url = selectAvatar();

/*
If provided emoji add it,
defaults to null;
*/
if (emoji()) message.icon_emoji = emoji();

return message;
}

Expand Down