Skip to content

Commit

Permalink
[command] npm run release
Browse files Browse the repository at this point in the history
  • Loading branch information
8398a7 committed Nov 12, 2021
2 parents c84a35c + 5c8520d commit b17d9de
Show file tree
Hide file tree
Showing 11 changed files with 33,367 additions and 472 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ steps:
- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took # selectable (default: repo,message)
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest # selectable (default: repo,message)
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.
Expand Down Expand Up @@ -57,7 +57,7 @@ steps:
with:
github_base_url: https://your.ghe.com # Specify your GHE
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()
Expand Down
4 changes: 2 additions & 2 deletions __tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('8398a7/action-slack', () => {
...newWith(),
status: Success,
fields:
'repo,message,commit,author,job,action,eventName,ref,workflow,took',
'repo,message,commit,author,job,action,eventName,ref,workflow,took,pullRequest',
};
const client = new Client(
withParams,
Expand Down Expand Up @@ -585,7 +585,7 @@ describe('8398a7/action-slack', () => {
...newWith(),
status: Success,
fields:
'repo,message,commit,author,job,action,eventName,ref,workflow,took',
'repo,message,commit,author,job,action,eventName,ref,workflow,took,pullRequest',
};
const client = new Client(
withParams,
Expand Down
18 changes: 17 additions & 1 deletion __tests__/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { readFileSync } from 'fs';
import { resolve } from 'path';
import { Field, With } from '../src/client';
import { FieldFactory } from '../src/fields';
import { getOctokit } from '@actions/github';
import github, { context, getOctokit } from '@actions/github';

export const gitHubToken = 'github-token';
export const gitHubBaseUrl = '';
Expand Down Expand Up @@ -92,6 +92,7 @@ export const fixedFields = (fields: string, sha?: string) => {
ff.includes('eventName') ? eventName() : undefined,
ff.includes('ref') ? ref() : undefined,
ff.includes('workflow') ? workflow(sha) : undefined,
ff.includes('pullRequest') ? pullRequest() : undefined,
],
undefined,
);
Expand Down Expand Up @@ -175,3 +176,18 @@ export const took = (): Field => {
value: '1 hour 1 min 1 sec',
};
};

export const pullRequest = (): Field => {
let value;
if (context.eventName.startsWith('pull_request')) {
value =
'<https://github.com/8398a7/action-slack/pull/123|Add pullRequest field #123>';
} else {
value = 'n/a';
}
return {
short: true,
title: 'pullRequest',
value: value,
};
};
42 changes: 42 additions & 0 deletions __tests__/pull_request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
webhookUrl,
} from './helper';
import { Client, Success } from '../src/client';
import github from '@actions/github';

beforeAll(() => {
nock.disableNetConnect();
Expand Down Expand Up @@ -52,3 +53,44 @@ describe('pull request event', () => {
expect(await client.prepare(msg)).toStrictEqual(payload);
});
});

describe.each`
eventName
${`pull_request`}
${`pull_request_review`}
${`pull_request_review_comment`}
${`pull_request_target`}
`('pullRequest field on pull_request events', ({ eventName }) => {
test(`${eventName}`, async () => {
const github = require('@actions/github');
const sha = 'expected-sha-for-pull_request_event';
github.context.payload = {
pull_request: {
html_url: 'https://github.com/8398a7/action-slack/pull/123',
title: 'Add pullRequest field',
number: 123,
head: { sha },
},
};
github.context.eventName = eventName;

const withParams = {
...newWith(),
status: Success,
fields: 'pullRequest',
};
const client = new Client(
withParams,
gitHubToken,
gitHubBaseUrl,
webhookUrl,
);
const msg = 'pullRequest test';
const payload = getTemplate(withParams.fields, msg, sha);
payload.attachments[0].color = 'good';
expect(await client.prepare(msg)).toStrictEqual(payload);
expect(process.env.AS_PULL_REQUEST).toStrictEqual(
'<https://github.com/8398a7/action-slack/pull/123|Add pullRequest field #123>',
);
});
});
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

57 changes: 44 additions & 13 deletions docs/content/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metaDescription: This explains the values that can be specified in Fields.

caution: Additional configuration is required to work with matrix.

Don't forget to add `MATRIX_CONTEXT`.
Don't forget to add `MATRIX_CONTEXT`.
Not required if the fields do not contain jobs or tooks.

```yaml
Expand All @@ -19,22 +19,23 @@ steps:
MATRIX_CONTEXT: ${{ toJson(matrix) }} # required
```
If you have more than one, please enter it in csv format.
If you have more than one, please enter it in csv format.
Corresponding types are as follows.
<img width="495" alt="success" src="https://user-images.githubusercontent.com/8043276/84587112-64844800-ae57-11ea-8007-7ce83a91dae3.png" />
| Field | Environment Variable | Description |
| --------- | ----------------------- | ------------------------------------------------------------ |
| repo | `AS_REPO` | A working repository name |
| commit | `AS_COMMIT` | commit hash |
| eventName | `AS_EVENT_NAME` | trigger event name |
| ref | `AS_REF` | git refrence |
| workflow | `AS_WORKFLOW` | Generate a workflow link from git sha |
| message | `AS_MESSAGE` | commit message |
| author | `AS_AUTHOR` | The author who pushed |
| job | `AS_JOB` | Generate a job run link of the job that was executed |
| took | `AS_TOOK` | Execution time for the job |
| Field | Environment Variable | Description |
| ----------- | ----------------------- | ----------------------------------------------------------- |
| repo | `AS_REPO` | A working repository name |
| commit | `AS_COMMIT` | commit hash |
| eventName | `AS_EVENT_NAME` | trigger event name |
| ref | `AS_REF` | git reference |
| workflow | `AS_WORKFLOW` | Generate a workflow link from git sha |
| message | `AS_MESSAGE` | commit message |
| author | `AS_AUTHOR` | The author who pushed |
| job | `AS_JOB` | Generate a job run link of the job that was executed |
| took | `AS_TOOK` | Execution time for the job |
| pullRequest | `AS_PULL_REQUEST` | Pull Request title, number with link |

```yaml
steps:
Expand All @@ -55,3 +56,33 @@ steps:
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
```

In either of the following cases, You must use the `job_name` parameter instead of the `MATRIX_CONTEXT`.

1. Overwrite job name by `name` syntax
1. Using `matrix` with `include`

Because when constructing the job name in the action-slack, the key specified by `include` is included in the `matrix` map.
It does not match the actual job name.

```yaml
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-18.04]
node: [8, 10, 12, 14]
include:
- os: windows-latest
node: 8
npm: 6
steps:
- uses: 8398a7/action-slack@v3
with:
job_name: test (${{ matrix.os }}, ${{ matrix.node }}) # named without `npm`
fields: job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
```
4 changes: 2 additions & 2 deletions docs/content/usecase/01-general.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ steps:
- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took # selectable (default: repo,message)
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest # selectable (default: repo,message)
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.
```
`status: ${{ job.status }}` allows a job to succeed, fail or cancel etc. to action-slack.
`status: ${{ job.status }}` allows a job to succeed, fail or cancel etc. to action-slack.
`if: always()` to trigger action-slack even if the job fails Let them.

For the fields, look at [Fields](/fields) to determine what you want.
Loading

0 comments on commit b17d9de

Please sign in to comment.