Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/src/octokit-provider.ts
diff options
context:
space:
mode:
authorPeter Murray <681306+peter-murray@users.noreply.github.com>2022-09-26 17:34:52 +0100
committerGitHub <noreply@github.com>2022-09-26 12:34:52 -0400
commite33cfa574212e8722034156757f8383979e76cb9 (patch)
tree0c9284b63ea98535c6a10b080a477136102a6856 /src/octokit-provider.ts
parentfa9591092fd91f59e3dbebbb92da3e2787a0bc03 (diff)
Inject GitHub host to be able to clone from another GitHub instance (#922)
* Adding the ability to specify the GitHub Server URL and allowing for it to differ from the Actions workflow host * Adding tests for injecting the GitHub URL * Addressing code review comments for PR #922
Diffstat (limited to 'src/octokit-provider.ts')
-rw-r--r--src/octokit-provider.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/octokit-provider.ts b/src/octokit-provider.ts
new file mode 100644
index 0000000..4fb1285
--- /dev/null
+++ b/src/octokit-provider.ts
@@ -0,0 +1,23 @@
+import * as github from '@actions/github'
+import {Octokit} from '@octokit/rest'
+import {getServerApiUrl} from './url-helper'
+
+// Centralize all Octokit references by re-exporting
+export {Octokit} from '@octokit/rest'
+
+export type OctokitOptions = {
+ baseUrl?: string
+ userAgent?: string
+}
+
+export function getOctokit(authToken: string, opts: OctokitOptions) {
+ const options: Octokit.Options = {
+ baseUrl: getServerApiUrl(opts.baseUrl)
+ }
+
+ if (opts.userAgent) {
+ options.userAgent = opts.userAgent
+ }
+
+ return new github.GitHub(authToken, options)
+}