16 Commits

Author SHA1 Message Date
Renovate Bot
56cbd49233 Update jest monorepo to v26 2020-05-04 20:20:12 +00:00
Renovate Bot
16c8fb978c Update dependency @typescript-eslint/parser to v2.31.0 2020-05-04 18:37:46 +00:00
Renovate Bot
f907bfd540 Update dependency eslint-plugin-jest to v23.9.0 2020-05-04 16:23:15 +00:00
Peter Evans
d1c3069352 Merge pull request #19 from peter-evans/update-distribution
Update distribution
2020-05-04 18:29:25 +09:00
peter-evans
dbeec545b7 Update distribution 2020-05-04 09:28:59 +00:00
Peter Evans
cfd43c3b5b Merge pull request #18 from peter-evans/typescript
Typescript
2020-05-04 18:27:31 +09:00
Peter Evans
ac8b848f7a Fix workflow 2020-05-04 18:20:48 +09:00
Peter Evans
3d4567b16c Update README 2020-05-04 18:20:48 +09:00
Peter Evans
0bda5274a2 Update workflows 2020-05-04 18:20:48 +09:00
Peter Evans
afd1745cdd Update action.yml 2020-05-04 18:20:48 +09:00
Peter Evans
176e52d27a Convert to Typescript 2020-05-04 18:20:48 +09:00
Peter Evans
ac6d1df23c Update gitignore 2020-05-04 18:20:48 +09:00
Peter Evans
48f2af69f2 Add jest config 2020-05-04 18:20:48 +09:00
Peter Evans
e5b7800e31 Add prettier config 2020-05-04 18:20:48 +09:00
Peter Evans
5065953cb1 Update eslint config 2020-05-04 18:20:48 +09:00
Peter Evans
8f68ab9db2 Update workflow 2020-05-04 18:20:33 +09:00
16 changed files with 22353 additions and 780 deletions

3
.eslintignore Normal file
View File

@@ -0,0 +1,3 @@
dist/
lib/
node_modules/

View File

@@ -1,17 +1,19 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
}
"env": { "node": true, "jest": true },
"parser": "@typescript-eslint/parser",
"parserOptions": { "ecmaVersion": 9, "sourceType": "module" },
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/camelcase": "off"
}
}

View File

@@ -13,8 +13,10 @@ jobs:
with:
node-version: 12.x
- run: npm ci
- run: npm run build
- run: npm run format-check
- run: npm run lint
- run: npm run test
- run: npm run package
- uses: actions/upload-artifact@v2
with:
name: dist
@@ -34,13 +36,19 @@ jobs:
name: dist
path: dist
- name: Repository Dispatch
- name: Test repository dispatch
uses: ./
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
event-type: tests
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
- name: Test repository dispatch (default payload)
uses: ./
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
event-type: tests
package:
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
needs: [test]

View File

@@ -6,7 +6,14 @@ jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Dump the client payload context
env:
PAYLOAD_CONTEXT: ${{ toJson(github.event.client_payload) }}
run: echo "$PAYLOAD_CONTEXT"
- uses: actions/checkout@v2
if: github.event.client_payload.ref != ''
with:
ref: ${{ github.event.client_payload.ref }}
- run: echo ${{ github.event.client_payload.sha }}

3
.gitignore vendored
View File

@@ -1 +1,2 @@
node_modules
lib/
node_modules/

3
.prettierignore Normal file
View File

@@ -0,0 +1,3 @@
dist/
lib/
node_modules/

11
.prettierrc.json Normal file
View File

@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}

View File

@@ -13,12 +13,14 @@ A GitHub action to create a repository dispatch event.
event-type: my-event
```
## Parameters
### Action inputs
- `token` (**required**) - A `repo` scoped GitHub [Personal Access Token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line).
- `repository` - The full name of the repository to send the dispatch. Defaults to the current repository.
- `event-type` (**required**) - A custom webhook event name.
- `client-payload` - JSON payload with extra information about the webhook event that your action or workflow may use. Default: {}
| Name | Description | Default |
| --- | --- | --- |
| `token` | (**required**) A `repo` scoped GitHub [Personal Access Token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). | |
| `repository` | The full name of the repository to send the dispatch. | `github.repository` (current repository) |
| `event-type` | (**required**) A custom webhook event name. | |
| `client-payload` | JSON payload with extra information about the webhook event that your action or workflow may use. | `{}` |
## Example

View File

@@ -6,15 +6,16 @@ inputs:
required: true
repository:
description: 'The full name of the repository to send the dispatch. Defaults to the current repository.'
default: ${{ github.repository }}
event-type:
description: 'A custom webhook event name.'
required: true
client-payload:
description: 'JSON payload with extra information about the webhook event that your action or worklow may use. Default: {}'
description: 'JSON payload with extra information about the webhook event that your action or worklow may use.'
default: '{}'
runs:
using: 'node12'
main: 'dist/index.js'
branding:
icon: 'target'
icon: 'target'
color: 'gray-dark'

18977
dist/index.js vendored

File diff suppressed because it is too large Load Diff

11
jest.config.js Normal file
View File

@@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}

3933
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +1,25 @@
{
"name": "repository-dispatch",
"version": "1.0.0",
"private": true,
"description": "Create a repository dispatch event",
"main": "src/index.js",
"main": "lib/main.js",
"scripts": {
"lint": "eslint src/index.js",
"package": "ncc build src/index.js -o dist",
"test": "eslint src/index.js && jest --passWithNoTests"
"build": "tsc && ncc build",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
"test": "jest --passWithNoTests"
},
"repository": {
"type": "git",
"url": "git+https://github.com/peter-evans/repository-dispatch.git"
},
"keywords": [],
"keywords": [
"actions",
"repository",
"dispatch"
],
"author": "Peter Evans",
"license": "MIT",
"bugs": {
@@ -21,11 +28,21 @@
"homepage": "https://github.com/peter-evans/repository-dispatch#readme",
"dependencies": {
"@actions/core": "1.2.4",
"@octokit/request": "5.4.2"
"@actions/github": "2.1.1"
},
"devDependencies": {
"@zeit/ncc": "0.22.1",
"@types/jest": "25.2.1",
"@types/node": "13.13.4",
"@typescript-eslint/parser": "2.31.0",
"@zeit/ncc": "0.20.5",
"eslint": "6.8.0",
"jest": "25.5.4"
"eslint-plugin-github": "3.4.1",
"eslint-plugin-jest": "23.9.0",
"jest": "26.0.0",
"jest-circus": "26.0.0",
"js-yaml": "3.13.1",
"prettier": "2.0.5",
"ts-jest": "25.4.0",
"typescript": "3.8.3"
}
}

View File

@@ -1,40 +0,0 @@
const { inspect } = require("util");
const core = require("@actions/core");
const { request } = require("@octokit/request");
async function run() {
try {
const inputs = {
token: core.getInput("token"),
repository: core.getInput("repository"),
eventType: core.getInput("event-type"),
clientPayload: core.getInput("client-payload")
};
core.debug(`Inputs: ${inspect(inputs)}`);
const repository = inputs.repository ? inputs.repository : process.env.GITHUB_REPOSITORY;
core.debug(`repository: ${repository}`);
const clientPayload = inputs.clientPayload ? inputs.clientPayload : '{}';
core.debug(`clientPayload: ${clientPayload}`);
await request(
`POST /repos/${repository}/dispatches`,
{
headers: {
authorization: `token ${inputs.token}`
},
mediaType: {
previews: ['everest']
},
event_type: `${inputs.eventType}`,
client_payload: JSON.parse(clientPayload),
}
);
} catch (error) {
core.debug(inspect(error));
core.setFailed(error.message);
}
}
run();

31
src/main.ts Normal file
View File

@@ -0,0 +1,31 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {inspect} from 'util'
async function run(): Promise<void> {
try {
const inputs = {
token: core.getInput('token'),
repository: core.getInput('repository'),
eventType: core.getInput('event-type'),
clientPayload: core.getInput('client-payload')
}
core.debug(`Inputs: ${inspect(inputs)}`)
const [owner, repo] = inputs.repository.split('/')
const octokit = new github.GitHub(inputs.token)
await octokit.repos.createDispatchEvent({
owner: owner,
repo: repo,
event_type: inputs.eventType,
client_payload: JSON.parse(inputs.clientPayload)
})
} catch (error) {
core.debug(inspect(error))
core.setFailed(error.message)
}
}
run()

16
tsconfig.json Normal file
View File

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6"
],
"outDir": "./lib",
"rootDir": "./src",
"declaration": true,
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true
},
"exclude": ["__test__", "lib", "node_modules"]
}