Skip to content

Commit

Permalink
[#3] Merge branch 'master' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
8398a7 committed Jun 12, 2020
2 parents 65bb51f + 631738b commit 0de1d5f
Show file tree
Hide file tree
Showing 9 changed files with 2,943 additions and 412 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/slack-mainline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_FOR_INTEGRATION_TEST }}
- name: Check
- name: All Field Check
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message
fields: repo,message,commit,author,action,eventName,ref,workflow,job
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ steps:
- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow # selectable (default: repo,message)
fields: repo,message,commit,author,action,eventName,ref,workflow,job # selectable (default: repo,message)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # optional
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
Expand Down
19 changes: 18 additions & 1 deletion __tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ process.env.GITHUB_SHA = 'b24f03a32e093fe8d55e23cfd0bb314069633b2f';
process.env.GITHUB_REF = 'refs/heads/feature/19';
process.env.GITHUB_EVENT_NAME = 'push';
process.env.GITHUB_TOKEN = 'test-token';
process.env.GITHUB_RUN_ID = '1';
process.env.GITHUB_JOB = 'notification';

import {
Client,
Expand Down Expand Up @@ -79,13 +81,22 @@ const workflow = (): Field => {
};
};

const job = (): Field => {
return {
short: true,
title: 'job',
value: `<https://github.com/8398a7/action-slack/runs/762195612|${process.env.GITHUB_JOB}>`,
};
};

const fixedFields = (client: Client, sha?: string) => {
return client.filterField(
[
client.includesField('repo') ? repo() : undefined,
client.includesField('message') ? message() : undefined,
client.includesField('commit') ? commit() : undefined,
client.includesField('author') ? author() : undefined,
client.includesField('job') ? job() : undefined,
client.includesField('action') ? action(sha) : undefined,
client.includesField('eventName') ? eventName() : undefined,
client.includesField('ref') ? ref() : undefined,
Expand Down Expand Up @@ -126,6 +137,12 @@ beforeAll(() => {
.persist()
.get(`/repos/8398a7/action-slack/commits/${process.env.GITHUB_SHA}`)
.reply(200, () => getApiFixture('repos.commits.get'));
nock('https://api.github.com')
.persist()
.get(
`/repos/8398a7/action-slack/actions/runs/${process.env.GITHUB_RUN_ID}/jobs`,
)
.reply(200, () => getApiFixture('actions.runs.jobs'));
});
afterAll(() => {
nock.cleanAll();
Expand All @@ -151,7 +168,7 @@ describe('8398a7/action-slack', () => {
icon_emoji: '',
icon_url: '',
channel: '',
fields: 'repo,message,commit,author,action,eventName,ref,workflow',
fields: 'repo,message,commit,author,action,eventName,ref,workflow,job',
};
const client = new Client(withParams, process.env.GITHUB_TOKEN, '');
const payload = getTemplate(client, `${successMsg}\n`);
Expand Down
30 changes: 30 additions & 0 deletions __tests__/fixtures/actions.runs.jobs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"total_count": 1,
"jobs": [
{
"id": 762195612,
"run_id": 132308092,
"run_url": "https://api.github.com/repos/8398a7/action-slack/actions/runs/132308092",
"node_id": "MDg6Q2hlY2tSdW43NjIxOTU2MTI=",
"head_sha": "cd15a66fc57d465564195faeb5308a63b4317cde",
"url": "https://api.github.com/repos/8398a7/action-slack/actions/jobs/762195612",
"html_url": "https://github.com/8398a7/action-slack/runs/762195612",
"status": "in_progress",
"conclusion": null,
"started_at": "2020-06-11T15:05:49Z",
"completed_at": null,
"name": "notification",
"steps": [
{
"name": "Set up job",
"status": "in_progress",
"conclusion": null,
"number": 1,
"started_at": "2020-06-11T15:05:49.000Z",
"completed_at": null
}
],
"check_run_url": "https://api.github.com/repos/8398a7/action-slack/check-runs/762195612"
}
]
}
2 changes: 2 additions & 0 deletions docs/content/with.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Corresponding types are as follows.
- required GITHUB_TOKEN
- author
- required GITHUB_TOKEN
- job
- required GITHUB_TOKEN
- action
- eventName
- ref
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ module.exports = {
verbose: true,
coverageDirectory: './coverage/',
collectCoverage: true,
preset: 'ts-jest',
};
Loading

0 comments on commit 0de1d5f

Please sign in to comment.