From 0fc042ca35b9ee6d4c6dc650662d40f189018a49 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Mon, 1 Nov 2021 11:43:18 -0500 Subject: set insteadOf url for org-id (#621) --- src/git-auth-helper.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/git-auth-helper.ts') diff --git a/src/git-auth-helper.ts b/src/git-auth-helper.ts index af400ab..233b3e6 100644 --- a/src/git-auth-helper.ts +++ b/src/git-auth-helper.ts @@ -37,7 +37,7 @@ class GitAuthHelper { private readonly tokenConfigValue: string private readonly tokenPlaceholderConfigValue: string private readonly insteadOfKey: string - private readonly insteadOfValue: string + private readonly insteadOfValues: string[] = [] private sshCommand = '' private sshKeyPath = '' private sshKnownHostsPath = '' @@ -45,7 +45,7 @@ class GitAuthHelper { constructor( gitCommandManager: IGitCommandManager, - gitSourceSettings?: IGitSourceSettings + gitSourceSettings: IGitSourceSettings | undefined ) { this.git = gitCommandManager this.settings = gitSourceSettings || (({} as unknown) as IGitSourceSettings) @@ -63,7 +63,12 @@ class GitAuthHelper { // Instead of SSH URL this.insteadOfKey = `url.${serverUrl.origin}/.insteadOf` // "origin" is SCHEME://HOSTNAME[:PORT] - this.insteadOfValue = `git@${serverUrl.hostname}:` + this.insteadOfValues.push(`git@${serverUrl.hostname}:`) + if (this.settings.workflowOrganizationId) { + this.insteadOfValues.push( + `org-${this.settings.workflowOrganizationId}@github.com:` + ) + } } async configureAuth(): Promise { @@ -118,7 +123,9 @@ class GitAuthHelper { // Configure HTTPS instead of SSH await this.git.tryConfigUnset(this.insteadOfKey, true) if (!this.settings.sshKey) { - await this.git.config(this.insteadOfKey, this.insteadOfValue, true) + for (const insteadOfValue of this.insteadOfValues) { + await this.git.config(this.insteadOfKey, insteadOfValue, true, true) + } } } catch (err) { // Unset in case somehow written to the real global config @@ -159,10 +166,12 @@ class GitAuthHelper { ) } else { // Configure HTTPS instead of SSH - await this.git.submoduleForeach( - `git config --local '${this.insteadOfKey}' '${this.insteadOfValue}'`, - this.settings.nestedSubmodules - ) + for (const insteadOfValue of this.insteadOfValues) { + await this.git.submoduleForeach( + `git config --local --add '${this.insteadOfKey}' '${insteadOfValue}'`, + this.settings.nestedSubmodules + ) + } } } } -- cgit v1.2.3