Skip to content

Commit 976c7c4

Browse files
author
Paweł Mitka
authored
feat: export emitterEventNames (#626)
`emitterEventNames` is a list of possible webhook event + action name combinations that is useful in GUI or validation of input
1 parent 6da50b0 commit 976c7c4

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- [webhooks.removeListener()](#webhooksremovelistener)
2222
- [createNodeMiddleware()](#createnodemiddleware)
2323
- [Webhook events](#webhook-events)
24+
- [emitterEventNames](#emittereventnames)
2425
- [TypeScript](#typescript)
2526
- [`EmitterWebhookEventName`](#emitterwebhookeventname)
2627
- [`EmitterWebhookEvent`](#emitterwebhookevent)
@@ -95,6 +96,7 @@ source.onmessage = (event) => {
9596
9. [webhooks.removeListener()](#webhooksremovelistener)
9697
10. [createNodeMiddleware()](#createnodemiddleware)
9798
11. [Webhook events](#webhook-events)
99+
12. [emitterEventNames](#emittereventnames)
98100

99101
### Constructor
100102

@@ -694,6 +696,15 @@ If there are actions for a webhook, events are emitted for both, the webhook nam
694696

695697
<!-- /autogenerated via scripts/generate-types.ts -->
696698

699+
### emitterEventNames
700+
701+
A read only tuple containing all the possible combinations of the webhook events + actions listed above. This might be useful in GUI and input validation.
702+
703+
```js
704+
import { emitterEventNames } from "@octokit/webhooks";
705+
emitterEventNames; // ["check_run", "check_run.completed", ...]
706+
```
707+
697708
## TypeScript
698709

699710
The types for the webhook payloads are sourced from [`@octokit/webhooks-types`](https://github.com/octokit/webhooks/tree/master/payload-types),

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from "./types";
1717

1818
export { createNodeMiddleware } from "./middleware/node/index";
19+
export { emitterEventNames } from "./generated/webhook-names";
1920

2021
// U holds the return value of `transform` function in Options
2122
class Webhooks<TTransformed = unknown> {

test/integration/smoke-test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Webhooks, createEventHandler } from "../../src";
1+
import { Webhooks, createEventHandler, emitterEventNames } from "../../src";
22

33
test("@octokit/webhooks", () => {
44
const emitWarningSpy = jest.spyOn(process, "emitWarning");
@@ -23,3 +23,9 @@ test('require("@octokit/webhooks").createEventHandler', () => {
2323
}).not.toThrow();
2424
expect(emitWarningSpy).not.toHaveBeenCalled();
2525
});
26+
27+
test('require("@octokit/webhooks").emitterEventNames', () => {
28+
const allEvents = emitterEventNames;
29+
expect(typeof allEvents).toBe("object");
30+
expect(typeof allEvents[0]).toBe("string");
31+
});

0 commit comments

Comments
 (0)