Skip to content

Commit

Permalink
feat: finish updates & adding github event support
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwmale committed Mar 28, 2024
1 parent a976623 commit 14b045d
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 26 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-explicit-any": "off",
"github/no-then": "off",
"import/no-namespace": "off",
"i18n-text/no-en": "off"
}
}
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Example:
url: ${{ secrets.WEBHOOK_URL }}
headers: '{"repository": "joelwmale/webhook-action"}'
body: '{"event": "deployment", "repository": "joelwmale/webhook-action"}'
github_event: ${{ toJson(github.event) }}
github_event_payload: true
```
It is **highly** recommended to use the action is an explicit commit SHA-1:
Expand All @@ -35,12 +35,28 @@ The action has support for the following input variables (arguments):
* **`headers`** (**optional**): Any headers you want to be sent with the webhook
* **`body`** (**optional**): The body of data send with the webhook
* **`insecure`** (**optional**): Enables calling to known self-signed or invalid SSL certificates
* **`github_event`** (**optional**): Enables forwarding the Github event to your webhook
* **`github_event_payload`** (**optional**): Enables forwarding the Github event payload to your webhook.

You can find more information on how to use these input variables below.

## Arguments

#### URL

**Required:** true

The URL to send the webhook to

```yml
url: ${{ secrets.WEBHOOK_URL }}
```

or

```yml
url: https://webhook.site/8b1b1b1b-8b1b-8b1b-8b1b-8b1b1b1b1b1b
```

#### Headers

**Required:** false
Expand All @@ -62,6 +78,30 @@ Allows you to send a custom JSON object to the webhook
body: '{"event": "deployment", "repository": "joelwmale/webhook-action"}'
```

#### Insecure

**Required:** false
**Default:** false

Allows you to send a webhook to a known self-signed or invalid SSL certificate

```yml
insecure: true
```

#### Github Event Payload

**Required:** false
**Default:** false

Allows you to send the Github event payload to your webhook

The payload will be sent as a JSON object under the key `githubEventPayload` on the root of the payload sent to your webhook

```yml
github_event_payload: true
```

## Issues

If you find any issues or have an improvement feel free to [submit an issue](https://github.com/joelwmale/webhook-action/issues/new)
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ inputs:
insecure:
description: 'Enables calling to known self-signed or invalid SSL certificates'
required: false
github_event:
description: 'Include the event that triggered the action in the payload body'
github_event_payload:
description: 'Include the github event payload that triggered the action in the payload'
required: false
outputs:
status:
Expand Down
10 changes: 5 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ function run() {
? process.env.data
: null;
const insecure = core.getInput('insecure')
? core.getInput('insecure') == 'true'
? core.getInput('insecure') === 'true'
: process.env.insecure
? process.env.insecure == 'true'
? process.env.insecure === 'true'
: false;
const githubEvent = core.getInput('github_event') == 'true';
if (githubEvent) {
const githubEventPayload = core.getInput('github_event_payload') === 'true';
if (githubEventPayload) {
const decodedBody = JSON.parse(body || '{}');
decodedBody.github_event = github_1.context;
decodedBody.githubEventPayload = github_1.context.payload || {};
body = JSON.stringify(decodedBody);
}
if (!url) {
Expand Down
23 changes: 23 additions & 0 deletions dist/licenses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
node-fetch
MIT
The MIT License (MIT)

Copyright (c) 2016 - 2020 Node Fetch Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 5 additions & 5 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 108 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"description": "Github Webhook Action",
"main": "dist/main.js",
"scripts": {
"build": "tsc && ncc build",
"build": "tsc && ncc build --license licenses.txt",
"format": "prettier --write '**/*.ts'",
"format-check": "prettier --check '**/*.ts'",
"lint": "eslint src/**/*.ts",
"package": "ncc build --source-map --license licenses.txt",
"test": "jest",
"all": "npm run build && npm run format && npm test && npm run lint && npm run package"
"all": "npm run format && npm run lint && npm run test&& npm run build"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,6 +38,7 @@
"babel-jest": "^29.3.1",
"eslint": "^8.57.0",
"eslint-plugin-github": "^4.10.2",
"eslint-plugin-jest": "^27.9.0",
"https": "^1.0.0",
"jest": "^29.7.0",
"js-yaml": "^4.1.0",
Expand Down
10 changes: 5 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ async function run() {
: null

const insecure = core.getInput('insecure')
? core.getInput('insecure') == 'true'
? core.getInput('insecure') === 'true'
: process.env.insecure
? process.env.insecure == 'true'
? process.env.insecure === 'true'
: false

const githubEvent = core.getInput('github_event') == 'true'
const githubEventPayload = core.getInput('github_event_payload') === 'true'

// if github_event is set to true, append it to the body
if (githubEvent) {
if (githubEventPayload) {
// decode the body
const decodedBody = JSON.parse(body || '{}')

// set the github event
decodedBody.github_event = context
decodedBody.githubEventPayload = context.payload || {}

// re-set the body
body = JSON.stringify(decodedBody)
Expand Down
Loading

0 comments on commit 14b045d

Please sign in to comment.