-
Notifications
You must be signed in to change notification settings - Fork 923
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use
octokit-auth-probot
(#1392)
- Loading branch information
Showing
7 changed files
with
888 additions
and
818 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,53 @@ | ||
import { State } from "../types"; | ||
import { ProbotOctokit } from "./probot-octokit"; | ||
|
||
type FactoryOptions = { | ||
octokit: InstanceType<typeof ProbotOctokit>; | ||
octokitOptions: ConstructorParameters<typeof ProbotOctokit> & { | ||
throttle?: Record<string, unknown>; | ||
auth?: Record<string, unknown>; | ||
}; | ||
[key: string]: unknown; | ||
}; | ||
|
||
export async function getAuthenticatedOctokit( | ||
state: State, | ||
installationId?: number | ||
) { | ||
const { githubToken, log, Octokit, octokit } = state; | ||
const { log, octokit } = state; | ||
|
||
if (!installationId) return octokit; | ||
|
||
const constructorAuthOptions = githubToken | ||
? {} | ||
: { auth: { installationId: installationId } }; | ||
return octokit.auth({ | ||
type: "installation", | ||
installationId, | ||
factory: ({ octokit, octokitOptions, ...otherOptions }: FactoryOptions) => { | ||
const pinoLog = log.child({ name: "github" }); | ||
|
||
const pinoLog = log.child({ name: "github" }); | ||
const options = { | ||
log: { | ||
fatal: pinoLog.fatal.bind(pinoLog), | ||
error: pinoLog.error.bind(pinoLog), | ||
warn: pinoLog.warn.bind(pinoLog), | ||
info: pinoLog.info.bind(pinoLog), | ||
debug: pinoLog.debug.bind(pinoLog), | ||
trace: pinoLog.trace.bind(pinoLog), | ||
}, | ||
throttle: { | ||
id: installationId, | ||
}, | ||
...constructorAuthOptions, | ||
}; | ||
const options = { | ||
...octokitOptions, | ||
log: { | ||
fatal: pinoLog.fatal.bind(pinoLog), | ||
error: pinoLog.error.bind(pinoLog), | ||
warn: pinoLog.warn.bind(pinoLog), | ||
info: pinoLog.info.bind(pinoLog), | ||
debug: pinoLog.debug.bind(pinoLog), | ||
trace: pinoLog.trace.bind(pinoLog), | ||
}, | ||
throttle: { | ||
...octokitOptions.throttle, | ||
id: installationId, | ||
}, | ||
auth: { | ||
...octokitOptions.auth, | ||
otherOptions, | ||
installationId, | ||
}, | ||
}; | ||
|
||
const Octokit = octokit.constructor as typeof ProbotOctokit; | ||
|
||
return new Octokit(options); | ||
return new Octokit(options); | ||
}, | ||
}) as Promise<InstanceType<typeof ProbotOctokit>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters