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/url-helper.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/url-helper.ts')
-rw-r--r--src/url-helper.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/url-helper.ts b/src/url-helper.ts
new file mode 100644
index 0000000..3e0e142
--- /dev/null
+++ b/src/url-helper.ts
@@ -0,0 +1,28 @@
+import * as assert from 'assert'
+import {IGitSourceSettings} from './git-source-settings'
+import {URL} from 'url'
+
+export function getApiUrl(): string {
+ return process.env['GITHUB_API_URL'] || 'https://api.github.com'
+}
+
+export function getFetchUrl(settings: IGitSourceSettings): string {
+ assert.ok(
+ settings.repositoryOwner,
+ 'settings.repositoryOwner must be defined'
+ )
+ assert.ok(settings.repositoryName, 'settings.repositoryName must be defined')
+ const serviceUrl = getServerUrl()
+ const encodedOwner = encodeURIComponent(settings.repositoryOwner)
+ const encodedName = encodeURIComponent(settings.repositoryName)
+ if (settings.sshKey) {
+ return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`
+ }
+
+ // "origin" is SCHEME://HOSTNAME[:PORT]
+ return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
+}
+
+export function getServerUrl(): URL {
+ return new URL(process.env['GITHUB_URL'] || 'https://github.com')
+}