Skip to content

Commit

Permalink
release v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sarisia committed Feb 2, 2020
2 parents 7c20434 + a69e87f commit 09e3def
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-cancel.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Test cancel actions'
name: 'test cancel'
on: [push, pull_request]

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Test actions'
name: 'test'
on: [push, pull_request]

jobs:
Expand Down
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

<img src="https://user-images.githubusercontent.com/33576079/69472655-332b2880-0df0-11ea-9c33-6add9fca62e9.png" width="500px">

## 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!
Expand All @@ -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
```
<img src="https://user-images.githubusercontent.com/33576079/69472655-332b2880-0df0-11ea-9c33-6add9fca62e9.png" width="50%">
## Environment Variables
| Key | Value | Description |
Expand All @@ -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:<br>`https://discordapp.com/api/webhooks/...`<br>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!!!**<br>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:<br>`https://discordapp.com/api/webhooks/...`<br>You can provide webhook via env either. If both is set, this input will be used.<br>**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. |
29 changes: 23 additions & 6 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -87,8 +104,8 @@ function getPayload(status, description, job) {
},
{
name: 'Event',
value: eventName,
inline: true
value: eventDetail,
inline: false
},
{
name: 'Triggered by',
Expand All @@ -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();
30 changes: 24 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -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()

0 comments on commit 09e3def

Please sign in to comment.