Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use handlebars-helper library #216

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/slack.yml
@@ -1,7 +1,7 @@
username: GitHub-CI
icon_url: https://octodex.github.com/images/femalecodertocat.png

pretext: Triggered via {{eventName}} by {{actor}} {{or action "action"}} {{ref}} `{{diffRef}}`
pretext: Triggered via {{eventName}} by {{actor}} {{default action "action"}} {{ref}} `{{diffRef}}`
title: GitHub Actions
title_link: https://support.github.com

Expand All @@ -11,7 +11,7 @@ text: |
{{#if payload.commits}}
*Commits*
{{#each payload.commits}}
<{{this.url}}|`{{limitTo this.id 8}}`> - {{this.message}}
<{{this.url}}|`{{truncate this.id 8}}`> - {{this.message}}
{{/each}}
{{/if}}

Expand All @@ -20,7 +20,9 @@ fallback: |-

fields:
- title: Job Steps
value: "{{#each jobSteps}}{{icon this.outcome}} {{@key}}\n{{/each}}"
value: |-
{{#each jobSteps}}{{#compare this.outcome '!=' 'skipped'}}{{icon this.outcome}} {{@key}}
{{/compare}}{{/each}}
short: false
- title: Workflow
value: "<{{{workflowUrl}}}|{{workflow}}>"
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -27,6 +27,10 @@ test:
test.only:
npm test -- $(TEST_REGEX)

## test.package - Run ncc compiled code.
test.package:
npm run package:test

## build - Build and package.
build:
npm run build && npm run package
Expand Down
6 changes: 1 addition & 5 deletions README.md
Expand Up @@ -104,13 +104,9 @@ The following [Slack message fields](https://api.slack.com/reference/messaging/a

**Helper Functions**

Apart from the [standard helper functions](https://handlebarsjs.com/guide/builtin-helpers.html#if) such as `#if` and `#each` there are also a few custom
ones:
Apart from the [standard helper functions](https://handlebarsjs.com/guide/builtin-helpers.html#if) such as `#if` and `#each` there are also more than 130 helpers from the [handlebars-helpers library](https://github.com/helpers/handlebars-helpers), plus one additional helper specific for this slack action:

- `icon` converts a job status into an icon eg. `{{icon jobStatus}}`
- `json` dumps the value as a JSON string eg. `{{json payload.commits}}`
- `limitTo` cuts the string at the limit eg. `{{limitTo sha 8}}`
- `or` allows a alternative or default value eg. `{{or headRef baseRef}}`

**Example Using Config File**

Expand Down
15 changes: 7 additions & 8 deletions __tests__/config.test.ts
Expand Up @@ -11,8 +11,8 @@ const jobStatus = 'failure'
const jobSteps = {
'install-deps': {
outputs: {},
outcome: 'skipped',
conclusion: 'skipped'
outcome: 'success',
conclusion: 'success'
},
hooks: {
outputs: {},
Expand All @@ -21,8 +21,8 @@ const jobSteps = {
},
lint: {
outputs: {},
outcome: 'skipped',
conclusion: 'skipped'
outcome: 'failure',
conclusion: 'failure'
},
types: {
outputs: {},
Expand All @@ -36,8 +36,8 @@ const jobSteps = {
},
'integration-test': {
outputs: {},
outcome: 'skipped',
conclusion: 'skipped'
outcome: 'failure',
conclusion: 'failure'
}
}
const channel = '#github-ci'
Expand Down Expand Up @@ -122,8 +122,7 @@ test('custom config of slack action', async () => {
{
short: false,
title: 'Job Steps',
value:
':heavy_minus_sign: install-deps\n:heavy_minus_sign: hooks\n:heavy_minus_sign: lint\n:heavy_minus_sign: types\n:heavy_minus_sign: unit-test\n:heavy_minus_sign: integration-test\n'
value: ':white_check_mark: install-deps\n:grimacing: lint\n:grimacing: integration-test\n'
},
{
short: true,
Expand Down
8 changes: 5 additions & 3 deletions __tests__/fixtures/slack.yml
@@ -1,7 +1,7 @@
username: GitHub-CI
icon_url: https://octodex.github.com/images/mona-the-rivetertocat.png

pretext: Triggered via {{eventName}} by {{actor}} {{or action "action"}} {{ref}} `{{diffRef}}`
pretext: Triggered via {{eventName}} by {{actor}} {{default action "action"}} {{ref}} `{{diffRef}}`
title: GitHub Actions
title_link: https://support.github.com

Expand All @@ -11,7 +11,7 @@ text: |
{{#if payload.commits}}
*Commits*
{{#each payload.commits}}
<{{this.url}}|`{{limitTo this.id 8}}`> - {{this.message}}
<{{this.url}}|`{{truncate this.id 8}}`> - {{this.message}}
{{/each}}
{{/if}}

Expand All @@ -20,7 +20,9 @@ fallback: |-

fields:
- title: Job Steps
value: "{{#each jobSteps}}{{icon this.outcome}} {{@key}}\n{{/each}}"
value: |-
{{#each jobSteps}}{{#compare this.outcome '!=' 'skipped'}}{{icon this.outcome}} {{@key}}
{{/compare}}{{/each}}
short: false
- title: Workflow
value: "<{{{workflowUrl}}}|{{workflow}}>"
Expand Down
15 changes: 7 additions & 8 deletions __tests__/inputs.test.ts
Expand Up @@ -11,8 +11,8 @@ const jobStatus = 'in progress'
const jobSteps = {
'install-deps': {
outputs: {},
outcome: 'skipped',
conclusion: 'skipped'
outcome: 'success',
conclusion: 'success'
},
hooks: {
outputs: {},
Expand All @@ -21,8 +21,8 @@ const jobSteps = {
},
lint: {
outputs: {},
outcome: 'skipped',
conclusion: 'skipped'
outcome: 'failure',
conclusion: 'failure'
},
types: {
outputs: {},
Expand All @@ -36,8 +36,8 @@ const jobSteps = {
},
'integration-test': {
outputs: {},
outcome: 'skipped',
conclusion: 'skipped'
outcome: 'failure',
conclusion: 'failure'
}
}
const channel = '#deploy'
Expand Down Expand Up @@ -115,8 +115,7 @@ test('custom config of slack action', async () => {
{
short: false,
title: 'Job Steps',
value:
':heavy_minus_sign: install-deps\n:heavy_minus_sign: hooks\n:heavy_minus_sign: lint\n:heavy_minus_sign: types\n:heavy_minus_sign: unit-test\n:heavy_minus_sign: integration-test\n'
value: ':white_check_mark: install-deps\n:grimacing: lint\n:grimacing: integration-test\n'
},
{
short: true,
Expand Down