diff --git a/README.md b/README.md
index df60af6..d7c34d2 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,5 @@
![Notification](https://github.com/craftech-io/slack-action/workflows/Notification/badge.svg)
+[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)
# Slack Action
@@ -14,7 +15,7 @@ You can customize the following parameters:
| With Parameter | Required/Optional | Description |
| --------------------- | ----------------- | ------------|
-| `SLACK_WEBHOOK_URL` | **Required** | The Slack Incoming Webhooks URL.
[Please specify this key or SLACK_WEBHOOK_URL environment secret](https://help.github.com/es/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets)
+| `SLACK_WEBHOOK_URL` | **Required** | The Slack Incoming Webhooks URL.
Please specify the [environment secret](https://help.github.com/es/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) for SLACK_WEBHOOK_URL
| `STATUS` | ***Optional*** | The result of GitHub Actions job
This parameter value must contain the following word:
- `success`
- `failure`
- `cancelled`
default is using ${{ job.status }}
| `SLACK_CHANNEL` | ***Optional*** | Override the default incoming Webhook Slack settings
| `SLACK_USERNAME` | ***Optional*** | Override the default incoming Webhook Slack settings
diff --git a/src/index.js b/src/index.js
index b9f4e78..523d49b 100644
--- a/src/index.js
+++ b/src/index.js
@@ -7,7 +7,6 @@ const sucess_color = '#00C0C7';
const cancelled_color = '#FFA900';
const failure_color = '#FF614E';
-
function post(slackMessage) {
const slack_webhook_url = core.getInput("slack_webhook_url");
fetch(slack_webhook_url, {
@@ -15,7 +14,18 @@ function post(slackMessage) {
body: JSON.stringify(slackMessage),
headers: { 'Content-Type': 'application/json' },
}).catch(console.error);
-}
+
+ if (!core.getInput("slack_webhook_url")) {
+ try {
+ throw new Error(`[Error] Missing Slack Incoming Webhooks URL
+ Please configure "SLACK_WEBHOOK" as environment variable or
+ specify the key called "slack_webhook_url" in "with" section`);
+ }
+ catch (error) {
+ console.error(error.message);
+ }
+ }
+ }
function getColor(status) {
@@ -25,19 +35,13 @@ function getColor(status) {
if (status.toLowerCase() === 'cancelled') {
return cancelled_color;
}
-
if (status.toLowerCase() === 'failure') {
return failure_color;
}
-
return start_color;
}
-
-
function getText(status) {
- const token = core.getInput("repoToken");
- const {owner, repo} = github.context.repo;
const actor = github.context.actor;
const workflow = github.context.workflow;
started = `` + ' has *started* the "' + `${workflow}` + '"' + ' workflow ';
@@ -51,15 +55,12 @@ function getText(status) {
if (status.toLowerCase() === 'cancelled') {
return cancelled;
}
-
if (status.toLowerCase() === 'failure') {
return failure;
}
-
if (status.toLowerCase() === 'started') {
return started;
}
-
return 'status no valido';
}
@@ -69,8 +70,6 @@ function generateSlackMessage(text) {
const status = core.getInput("status");
const channel = core.getInput("slack_channel");
const username = core.getInput("slack_username");
- const workflow = github.context.workflow;
-
return {
channel,
username,
@@ -92,7 +91,6 @@ function generateSlackMessage(text) {
"title": "Ref",
"value": github.context.ref,
"short": true
-
},
],
"actions": [
@@ -111,9 +109,8 @@ function generateSlackMessage(text) {
]
};
}
-
try {
- post(generateSlackMessage(' '));
+ post(generateSlackMessage('Sending message'));
} catch (error) {
- core.setFailed(error.message);
-}
\ No newline at end of file
+ core.setFailed(`[Error] There was an error when sending the slack notification`);
+}
\ No newline at end of file