Skip to content

Commit 2b6babd

Browse files
committed
feat: octokit.hook
1 parent 3ba1d52 commit 2b6babd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import getUserAgent from "universal-user-agent";
2+
import { Collection, HookCollection } from "before-after-hook";
23
import { request } from "@octokit/request";
34

45
import { OctokitOptions, Parameters, Plugin } from "./types";
@@ -18,10 +19,13 @@ export class Octokit {
1819
}
1920

2021
constructor(options: OctokitOptions = {}) {
22+
const hook = new Collection();
2123
const requestDefaults: Required<Parameters> = {
2224
baseUrl: request.endpoint.DEFAULTS.baseUrl,
2325
headers: {},
24-
request: options.request || {},
26+
request: Object.assign({}, options.request, {
27+
hook: hook.bind(null, "request")
28+
}),
2529
mediaType: {
2630
previews: [],
2731
format: ""
@@ -45,6 +49,7 @@ export class Octokit {
4549
}
4650

4751
this.request = request.defaults(requestDefaults);
52+
this.hook = hook;
4853

4954
// apply plugins
5055
// https://stackoverflow.com/a/16345172
@@ -54,6 +59,7 @@ export class Octokit {
5459

5560
// assigned during constructor
5661
request: typeof request;
62+
hook: HookCollection;
5763

5864
// allow for plugins to extend the Octokit instance
5965
[key: string]: any;

0 commit comments

Comments
 (0)