Skip to content

Commit

Permalink
Merge branch 'master' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
8398a7 committed Aug 19, 2019
2 parents 4d1544e + 4a713dc commit 2f40446
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 19 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/slack-pre.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Slack Checks
on:
push:
branches:
- pre

jobs:
notification:
runs-on: ubuntu-latest
steps:
- name: Succeeded Check
uses: 8398a7/action-slack@pre
with:
type: success
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Failed Check
uses: 8398a7/action-slack@pre
with:
type: failure
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Custom Field Check
uses: 8398a7/action-slack@pre
with:
payload: |
{
"text": "Custom Field Check",
"attachments": [{
"author_name": "slack-actions",
"fallback": "fallback",
"color": "good",
"title": "CI Result",
"text": "Succeeded",
"fields": [{
"title": "short title1",
"value": "short value1",
"short": true
},
{
"title": "short title2",
"value": "short value2",
"short": true
},
{
"title": "long title1",
"value": "long value1",
"short": false
}],
"actions": [{
}]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- master
- v0
- v1

jobs:
Expand All @@ -15,12 +14,14 @@ jobs:
with:
type: success
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Failed Check
uses: 8398a7/action-slack@v1
with:
type: failure
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Custom Field Check
uses: 8398a7/action-slack@v1
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,47 @@ See [action.yml](action.yml), [checkin.yml](.github/workflows/checkin.yml)

### Succeeded Notification

![](https://user-images.githubusercontent.com/8043276/63113235-10a59a00-bfcd-11e9-83be-2dd8662c9ebb.png)
![](https://user-images.githubusercontent.com/8043276/63276385-3e952200-c2de-11e9-9f07-7e0fc4cf8d3a.png)

```yaml
- uses: 8398a7/action-slack@v1
with:
type: success
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
- uses: 8398a7/action-slack@v1
with:
type: success
text: overwrite text
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
```
### Failed Notification
### Failure Notification
![](https://user-images.githubusercontent.com/8043276/63113244-14392100-bfcd-11e9-962b-03a19ba86680.png)
![](https://user-images.githubusercontent.com/8043276/63276493-6edcc080-c2de-11e9-97df-861d6564a888.png)
```yaml
- uses: 8398a7/action-slack@v1
with:
type: failure
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
- uses: 8398a7/action-slack@v1
with:
type: failure
failedMention: channel
failedMention: channel # The default is here. No mention if empty character specified.
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
```
### Custom Notification
![](https://user-images.githubusercontent.com/8043276/63113021-9f65e700-bfcc-11e9-97cf-9a962c7ce611.png)
![](https://user-images.githubusercontent.com/8043276/63276528-86b44480-c2de-11e9-9ad9-42a33d638c4c.png)
```yaml
- uses: 8398a7/action-slack@v0
Expand Down Expand Up @@ -83,7 +87,7 @@ See [action.yml](action.yml), [checkin.yml](.github/workflows/checkin.yml)
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
```
### Auto Notification
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ async function run() {
case 'auto':
throw new Error('not implement');
case 'success':
payload = successPayload(text);
payload = await successPayload(text);
break;
case 'failure':
payload = failurePayload(text, failedMention);
payload = await failurePayload(text, failedMention);
break;
default:
payload = JSON.parse(core.getInput('payload'));
Expand Down
28 changes: 22 additions & 6 deletions src/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,33 @@ export async function Send(payload: IncomingWebhookSendArguments) {
core.debug('send message');
}

export function successPayload(text: string) {
const client = new github.GitHub(process.env.GITHUB_TOKEN as string);

export async function successPayload(text: string) {
const { sha } = github.context;
const { owner, repo } = github.context.repo;
const commit = await client.repos.getCommit({ owner, repo, ref: sha });
const { author } = commit.data.commit;

const payload: IncomingWebhookSendArguments = {
text: 'Succeeded Workflow',
attachments: [
{
color: 'good',
author_name: 'action-slack',
fields: [
{ title: 'repo', value: github.context.repo.repo, short: true },
{ title: 'sha', value: github.context.sha, short: true },
{ title: 'actor', value: github.context.actor, short: true },
{ title: 'repo', value: repo, short: true },
{ title: 'message', value: commit.data.commit.message, short: true },
{
title: 'commit',
value: `<https://github.com/${owner}/${repo}/commit/${sha}|${sha}>`,
short: true,
},
{
title: 'author',
value: `${author.name}<${author.email}>`,
short: true,
},
{ title: 'eventName', value: github.context.eventName, short: true },
{ title: 'ref', value: github.context.ref, short: true },
{ title: 'workflow', value: github.context.workflow, short: true },
Expand All @@ -33,8 +49,8 @@ export function successPayload(text: string) {
return payload;
}

export function failurePayload(text: string, mention: string) {
const payload: IncomingWebhookSendArguments = successPayload(text);
export async function failurePayload(text: string, mention: string) {
const payload: IncomingWebhookSendArguments = await successPayload(text);
payload.text = '';
if (mention !== '') {
payload.text = `<!${mention}> `;
Expand Down

0 comments on commit 2f40446

Please sign in to comment.