-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #268 from sue445/add_matrix_input
feat: Add matrix input
- Loading branch information
Showing
17 changed files
with
155 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import * as github from '@actions/github' | ||
import axios from 'axios' | ||
import MockAdapter from 'axios-mock-adapter' | ||
import {send} from '../src/slack' | ||
import {readFileSync} from 'fs' | ||
|
||
const url = 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX' | ||
const jobName = 'Build and Test' | ||
const jobStatus = 'Success' | ||
const jobSteps = {} | ||
const jobMatrix = { | ||
name1: 'value1', | ||
name2: 'value2' | ||
} | ||
const channel = '@override' | ||
const message = undefined | ||
|
||
// mock github context | ||
const dump = JSON.parse(readFileSync('./__tests__/fixtures/push.json', 'utf-8')) | ||
|
||
github.context.payload = dump.event | ||
github.context.eventName = dump.event_name | ||
github.context.sha = dump.sha | ||
github.context.ref = dump.ref | ||
github.context.workflow = dump.workflow | ||
github.context.action = dump.action | ||
github.context.actor = dump.actor | ||
|
||
process.env.CI = 'true' | ||
process.env.GITHUB_WORKFLOW = 'build-test' | ||
process.env.GITHUB_RUN_ID = '100143423' | ||
process.env.GITHUB_RUN_NUMBER = '8' | ||
process.env.GITHUB_ACTION = 'self2' | ||
process.env.GITHUB_ACTIONS = 'true' | ||
process.env.GITHUB_ACTOR = 'satterly' | ||
process.env.GITHUB_REPOSITORY = 'act10ns/slack' | ||
process.env.GITHUB_EVENT_NAME = 'push' | ||
process.env.GITHUB_EVENT_PATH = '/home/runner/work/_temp/_github_workflow/event.json' | ||
process.env.GITHUB_WORKSPACE = '/home/runner/work/slack/slack' | ||
process.env.GITHUB_SHA = '68d48876e0794fba714cb331a1624af6b20942d8' | ||
process.env.GITHUB_REF = 'refs/heads/master' | ||
process.env.GITHUB_HEAD_REF = '' | ||
process.env.GITHUB_BASE_REF = '' | ||
process.env.GITHUB_SERVER_URL = 'https://github.com' | ||
process.env.GITHUB_API_URL = 'https://github.com' | ||
process.env.GITHUB_GRAPHQL_URL = 'https://api.github.com/graphql' | ||
|
||
test('push event to slack', async () => { | ||
const mockAxios = new MockAdapter(axios, {delayResponse: 200}) | ||
|
||
mockAxios | ||
.onPost() | ||
.reply(config => { | ||
console.log(config.data) | ||
return [200, {status: 'ok'}] | ||
}) | ||
.onAny() | ||
.reply(500) | ||
|
||
const res = await send(url, jobName, jobStatus, jobSteps, jobMatrix, channel, message) | ||
await expect(res).toStrictEqual({text: {status: 'ok'}}) | ||
|
||
expect(JSON.parse(mockAxios.history.post[0].data)).toStrictEqual({ | ||
username: 'GitHub Actions', | ||
icon_url: 'https://octodex.github.com/images/original.png', | ||
channel: '@override', | ||
attachments: [ | ||
{ | ||
fallback: '[GitHub]: [act10ns/slack] build-test push Success', | ||
color: 'good', | ||
author_name: 'satterly', | ||
author_link: 'https://github.com/satterly', | ||
author_icon: 'https://avatars0.githubusercontent.com/u/615057?v=4', | ||
mrkdwn_in: ['pretext', 'text', 'fields'], | ||
pretext: '', | ||
text: '*<https://github.com/act10ns/slack/actions?query=workflow:build-test|Workflow _build-test_ job _Build and Test_ triggered by _push_ is _Success_>* for <https://github.com/act10ns/slack/commits/master|`master`>\n<https://github.com/act10ns/slack/compare/db9fe60430a6...68d48876e079|`68d48876`> - 4 commits', | ||
title: '', | ||
fields: [ | ||
{ | ||
title: 'Job Matrix', | ||
value: 'name1: value1\nname2: value2\n', | ||
short: false | ||
} | ||
], | ||
footer: '<https://github.com/act10ns/slack|act10ns/slack> #8', | ||
footer_icon: 'https://github.githubassets.com/favicon.ico', | ||
ts: expect.stringMatching(/[0-9]+/) | ||
} | ||
] | ||
}) | ||
|
||
mockAxios.resetHistory() | ||
mockAxios.reset() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters