Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add onAny and onError methods from @octokit/webhooks #1480

Merged
merged 5 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ module.exports = (app) => {
});
return context.octokit.issues.createComment(issueComment);
});

app.onAny(async (context) => {
context.log.info({ event: context.name, action: context.payload.action });
});

app.onError(async (error) => {
context.log.error(error);
});
};
```

Expand Down
4 changes: 2 additions & 2 deletions docs/webhooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ module.exports = (app) => {
};
```

You can also use `app.webhooks.onAny()` to listen for any event that your app is subscribed to:
You can also use `app.onAny()` to listen for any event that your app is subscribed to:

```js
module.exports = (app) => {
app.webhooks.onAny(async (context) => {
app.onAny(async (context) => {
context.log.info({ event: context.name, action: context.payload.action });
});
};
Expand Down
5 changes: 5 additions & 0 deletions src/probot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class Probot {
public log: DeprecatedLogger;
public version: String;
public on: ProbotWebhooks["on"];
public onAny: ProbotWebhooks["onAny"];
public onError: ProbotWebhooks["onError"];
public auth: (
installationId?: number,
log?: Logger
Expand Down Expand Up @@ -100,6 +102,9 @@ export class Probot {
return this.webhooks.on(eventNameOrNames, callback);
};

this.onAny = this.webhooks.onAny;
this.onError = this.webhooks.onError;

this.version = VERSION;
}

Expand Down
13 changes: 13 additions & 0 deletions test/probot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@ describe("Probot", () => {
expect(spy).toHaveBeenCalled();
});

it("calls callback with onAny", async () => {
const probot = new Probot({
appId,
privateKey,
});

const spy = jest.fn();
probot.onAny(spy);

await probot.receive(event);
expect(spy).toHaveBeenCalled();
});

it("calls callback x amount of times when an array of x actions is passed", async () => {
const probot = new Probot({
appId,
Expand Down