-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.ts
36 lines (32 loc) · 1008 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Octokit } from "@octokit/core";
import { VERSION } from "./version";
/**
* @param octokit Octokit instance
* @param options Options passed to Octokit constructor
*/
export function requestLog(octokit: Octokit) {
octokit.hook.wrap("request", (request, options) => {
octokit.log.debug("request", options);
const start = Date.now();
const requestOptions = octokit.request.endpoint.parse(options);
const path = requestOptions.url.replace(options.baseUrl, "");
return (request as typeof octokit.request)(options)
.then((response) => {
octokit.log.info(
`${requestOptions.method} ${path} - ${response.status} in ${
Date.now() - start
}ms`
);
return response;
})
.catch((error) => {
octokit.log.info(
`${requestOptions.method} ${path} - ${error.status} in ${
Date.now() - start
}ms`
);
throw error;
});
});
}
requestLog.VERSION = VERSION;