/
api.ts
36 lines (33 loc) · 972 Bytes
/
api.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 { isDebug } from '@actions/core'
import { Octokit } from '@octokit/core'
import { restEndpointMethods } from '@octokit/plugin-rest-endpoint-methods'
import { requestLog } from '@octokit/plugin-request-log'
const GitHub = Octokit.plugin(restEndpointMethods, requestLog).defaults({
baseUrl: 'https://api.github.com',
})
export type API = InstanceType<typeof GitHub>
export default function (
token: string,
options?: { logRequests?: boolean; fetch?: any }
): API {
return new GitHub({
request: { fetch: options && options.fetch },
auth: `token ${token}`,
log: {
info(msg: string) {
if (options && options.logRequests === false) return
return console.info(msg)
},
debug(msg: string) {
if (!isDebug()) return
return console.debug(msg)
},
warn(msg: string) {
return console.warn(msg)
},
error(msg: string) {
return console.error(msg)
},
},
})
}