-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathutils.ts
45 lines (38 loc) · 1.17 KB
/
utils.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
37
38
39
40
41
42
43
44
45
import * as Context from './context'
import * as Utils from './internal/utils'
// octokit + plugins
import {Octokit} from '@octokit/core'
import {OctokitOptions} from '@octokit/core/dist-types/types'
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'
import {paginateRest} from '@octokit/plugin-paginate-rest'
export const context = new Context.Context()
const baseUrl = Utils.getApiBaseUrl()
export const defaults: OctokitOptions = {
baseUrl,
request: {
agent: Utils.getProxyAgent(baseUrl),
fetch: Utils.getProxyFetch(baseUrl)
}
}
export const GitHub = Octokit.plugin(
restEndpointMethods,
paginateRest
).defaults(defaults)
/**
* Convience function to correctly format Octokit Options to pass into the constructor.
*
* @param token the repo PAT or GITHUB_TOKEN
* @param options other options to set
*/
export function getOctokitOptions(
token: string,
options?: OctokitOptions
): OctokitOptions {
const opts = Object.assign({}, options || {}) // Shallow clone - don't mutate the object provided by the caller
// Auth
const auth = Utils.getAuthString(token, opts)
if (auth) {
opts.auth = auth
}
return opts
}