diff --git a/.github/workflows/test-cancel.yml b/.github/workflows/test-cancel.yml
index fda736c6..1d43d462 100644
--- a/.github/workflows/test-cancel.yml
+++ b/.github/workflows/test-cancel.yml
@@ -1,4 +1,4 @@
-name: 'Test cancel actions'
+name: 'test cancel'
on: [push, pull_request]
jobs:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index a16d2c90..54c93fcd 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -1,4 +1,4 @@
-name: 'Test actions'
+name: 'test'
on: [push, pull_request]
jobs:
diff --git a/README.md b/README.md
index e9e3d270..59985e39 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,19 @@
# Actions Status Discord
+![test](https://github.com/sarisia/actions-status-discord/workflows/test/badge.svg)
+![test cancel](https://github.com/sarisia/actions-status-discord/workflows/test%20cancel/badge.svg)
+
## About
A Github Actions action to notify CI status to Discord.
+
+
## Usage
```yaml
- name: Post status to Discord
+ # DO NOT point `@master` branch! It won't work.
uses: sarisia/actions-status-discord@v1
# make sure to set this `always()`
# or status failure and cancelled won't be notified!
@@ -18,10 +24,9 @@ A Github Actions action to notify CI status to Discord.
status: ${{ job.status }}
job: deploy to github pages
description: build pages and deploy to github pages!
+ nofail: false
```
-
-
## Environment Variables
| Key | Value | Description |
@@ -30,10 +35,10 @@ A Github Actions action to notify CI status to Discord.
## Inputs
-| Key | Default | Required | Description |
-| - | - | - | - |
-| webhook | | no | Discord webhook endpoind like:
`https://discordapp.com/api/webhooks/...`
You can provide webhook via env either. If both is set, inputs will be preferred. |
-| status | `success` | no | Accepts `success`, `failure` and `cancelled`. Set to `${{ job.status }}` is recommended. |
-| description | | no | Description included in message. See example above. |
-| job | | no | Job name included in message title. See example above. |
-| nofail | `true` | no | **MUST BE STRING!!!**
Accepts `true` and `false`. This action won't make workflow failed by default. If set to `false`, this action will set status failed when failed to notify. |
+| Key | Required | Value | Default | Description |
+| - | - | - | - | - |
+| webhook | No | String | `env.DISCORD_WEBHOOK` | Discord webhook endpoind like:
`https://discordapp.com/api/webhooks/...`
You can provide webhook via env either. If both is set, this input will be used.
**DO NOT INCLUDE `/github` SUFFIX!** |
+| status | No | `Success`, `Failure` or `Cancelled` | `Success` | Set to `${{ job.status }}` is recommended. |
+| description | No | String | | Description included in message. See example above. |
+| job | no | String | | Job name included in message title. See example above. |
+| nofail | no | `true` or `false` | `true` | This action won't make workflow failed by default. If set to `false`, this action will set status failed when failed to notify. |
diff --git a/lib/main.js b/lib/main.js
index 768a3b41..3e972fe5 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -65,10 +65,27 @@ function logError(msg, nofail) {
function getPayload(status, description, job) {
const ctx = github.context;
const { owner, repo } = ctx.repo;
- const { eventName, sha, ref, workflow, actor } = ctx;
+ const { eventName, sha, ref, workflow, actor, payload } = ctx;
const repoURL = `https://github.com/${owner}/${repo}`;
const workflowURL = `${repoURL}/commit/${sha}/checks`;
- let payload = {
+ core.debug(JSON.stringify(payload));
+ let eventDetail = eventName;
+ switch (eventName) {
+ case "push":
+ if (payload.head_commit) {
+ eventDetail = `Push: [\`${payload.head_commit.id.substring(0, 7)}\`](${payload.head_commit.url}) ${payload.head_commit.message}`;
+ }
+ else {
+ eventDetail = `Push: \`${sha.substring(0, 7)}\``;
+ }
+ break;
+ case "pull_request":
+ if (payload.pull_request) {
+ eventDetail = `Pull Request: [\`#${payload.pull_request.number}\`](${payload.pull_request.html_url}) ${payload.pull_request.title}`;
+ }
+ break;
+ }
+ let embed = {
embeds: [{
title: statusOpts[status].status + (job ? `: ${job}` : ''),
color: statusOpts[status].color,
@@ -87,8 +104,8 @@ function getPayload(status, description, job) {
},
{
name: 'Event',
- value: eventName,
- inline: true
+ value: eventDetail,
+ inline: false
},
{
name: 'Triggered by',
@@ -103,7 +120,7 @@ function getPayload(status, description, job) {
]
}]
};
- core.debug(`payload: ${JSON.stringify(payload)}`);
- return payload;
+ core.debug(`embed: ${JSON.stringify(embed)}`);
+ return embed;
}
run();
diff --git a/src/main.ts b/src/main.ts
index 3849d579..53096b07 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -51,11 +51,29 @@ function logError(msg: string, nofail: boolean): void {
function getPayload(status: string, description: string, job: string): object {
const ctx = github.context
const { owner, repo } = ctx.repo
- const { eventName, sha, ref, workflow, actor } = ctx
+ const { eventName, sha, ref, workflow, actor, payload } = ctx
const repoURL = `https://github.com/${owner}/${repo}`
const workflowURL = `${repoURL}/commit/${sha}/checks`
+
+ core.debug(JSON.stringify(payload))
- let payload = {
+ let eventDetail = eventName
+ switch (eventName) {
+ case "push":
+ if (payload.head_commit) {
+ eventDetail = `Push: [\`${payload.head_commit.id.substring(0, 7)}\`](${payload.head_commit.url}) ${payload.head_commit.message}`
+ } else {
+ eventDetail = `Push: \`${sha.substring(0, 7)}\``
+ }
+ break
+ case "pull_request":
+ if (payload.pull_request) {
+ eventDetail = `Pull Request: [\`#${payload.pull_request.number}\`](${payload.pull_request.html_url}) ${payload.pull_request.title}`
+ }
+ break
+ }
+
+ let embed = {
embeds: [{
title: statusOpts[status].status + (job ? `: ${job}` : ''),
color: statusOpts[status].color,
@@ -74,8 +92,8 @@ function getPayload(status: string, description: string, job: string): object {
},
{
name: 'Event',
- value: eventName,
- inline: true
+ value: eventDetail,
+ inline: false
},
{
name: 'Triggered by',
@@ -91,8 +109,8 @@ function getPayload(status: string, description: string, job: string): object {
}]
}
- core.debug(`payload: ${JSON.stringify(payload)}`)
- return payload
+ core.debug(`embed: ${JSON.stringify(embed)}`)
+ return embed
}
run()