webhook-action/src/main.ts
Joel Male cf3a34a9b4
v2.0.1 (#20)
* Convert action to ts

- Add optional header support
- Add optional body support

* Small fixes to action.yml and action output

* Add node_modules until bundler is added

* Add node-fetch

* Remove fetch, add axios

* Update build

* Fix issue with res.status being undefined

* Update logging for debug purposes

* Attempt to fix missing status code output

* Attempt to have code wait for request to finish

* Prepare for release

- Final cleanup

* Allow optional headers & body

* v2.0.0

* Add support for environment variables (fixed #17) (#19)

* v2.0.0 (#12)

- Convert project to Javascript/Typescript
- Allow custom headers to be passed in (optional)
- Allow body to be optional

* Update action.yml

* Update action.yml

* Add support for environment variables (fixed #17)

* Add support for header as environment variables

* Run build and package

Co-authored-by: Joel Male <joel@joelmale.com>

* Bump @actions/core from 1.2.4 to 1.2.5 (#18)

Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.4 to 1.2.5.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @vercel/ncc from 0.23.0 to 0.24.0 (#16)

Bumps [@vercel/ncc](https://github.com/vercel/ncc) from 0.23.0 to 0.24.0.
- [Release notes](https://github.com/vercel/ncc/releases)
- [Commits](https://github.com/vercel/ncc/compare/0.23.0...0.24.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump prettier from 2.0.5 to 2.1.1 (#15)

Bumps [prettier](https://github.com/prettier/prettier) from 2.0.5 to 2.1.1.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.0.5...2.1.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* ⬆️ Bump typescript from 3.9.7 to 4.0.2 (#13)

Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.9.7 to 4.0.2.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v3.9.7...v4.0.2)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Joel Male <joel@joelmale.com>

* v2.0.1

* Add backwards compatibility

Co-authored-by: Anand Chowdhary <github@anandchowdhary.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-08-27 18:25:55 +10:00

38 lines
1.2 KiB
TypeScript

import * as core from '@actions/core';
import { http } from './http';
async function run() {
const url = core.getInput('url') ? core.getInput('url') : (process.env.WEBHOOK_URL ? process.env.WEBHOOK_URL : '');
const headers = core.getInput('headers') ? core.getInput('headers') : (process.env.headers ? process.env.headers : null);
const body = core.getInput('body') ? core.getInput('body') : (process.env.data ? process.env.data : null);
if (!url) {
// validate a url
core.setFailed('A url is required to run this action.');
return;
}
// initial info
core.info(`Sending webhook request to ${url}`);
// debug start
core.debug((new Date()).toTimeString()); // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
// make the request
http.make(url, headers, body)
.then((res) => {
// output the status
core.setOutput('statusCode', res.status);
// report on the status code
core.info(`Received status code: ${res.status}`);
// debug end
core.info((new Date()).toTimeString());
})
.catch((err) => {
// set the action to failed
core.setFailed(`Received status code: ${err.status}`);
});
}
run();