diff options
| author | eric sciple <ericsciple@users.noreply.github.com> | 2020-03-18 23:33:26 -0400 |
|---|---|---|
| committer | eric sciple <ericsciple@users.noreply.github.com> | 2020-03-18 23:33:26 -0400 |
| commit | d35c5b0d45c2389911e8fa57f5a409dc7eb4eba9 (patch) | |
| tree | 9504842130011e5303867f926b8e6016a715323e /src/git-source-provider.ts | |
| parent | 6f1b729011b34bc28608462b6293df85180aba9c (diff) | |
use token for workflow repo
Diffstat (limited to 'src/git-source-provider.ts')
| -rw-r--r-- | src/git-source-provider.ts | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 4bce702..c1859a6 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -14,17 +14,21 @@ import {IGitSourceSettings} from './git-source-settings' const hostname = 'github.com' export async function getSource(settings: IGitSourceSettings): Promise<void> { - // Repository URL core.info( `Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}` ) - const repositoryUrl = settings.sshKey - ? `git@${hostname}:${encodeURIComponent( - settings.repositoryOwner - )}/${encodeURIComponent(settings.repositoryName)}.git` - : `https://${hostname}/${encodeURIComponent( - settings.repositoryOwner - )}/${encodeURIComponent(settings.repositoryName)}` + + // Remote URL + const httpsUrl = `https://${hostname}/${encodeURIComponent( + settings.repositoryOwner + )}/${encodeURIComponent(settings.repositoryName)}` + const sshUrl = `git@${hostname}:${encodeURIComponent( + settings.repositoryOwner + )}/${encodeURIComponent(settings.repositoryName)}.git` + + // Always fetch the workflow repository using the token, not the SSH key + const initialRemoteUrl = + !settings.sshKey || settings.isWorkflowRepository ? httpsUrl : sshUrl // Remove conflicting file path if (fsHelper.fileExistsSync(settings.repositoryPath)) { @@ -46,7 +50,8 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { await gitDirectoryHelper.prepareExistingDirectory( git, settings.repositoryPath, - repositoryUrl, + initialRemoteUrl, + [httpsUrl, sshUrl], settings.clean ) } @@ -86,7 +91,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { !fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git')) ) { await git.init() - await git.remoteAdd('origin', repositoryUrl) + await git.remoteAdd('origin', initialRemoteUrl) } // Disable automatic garbage collection @@ -124,6 +129,11 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { await git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref) } + // Fix URL when using SSH + if (settings.sshKey && initialRemoteUrl != sshUrl) { + await git.setRemoteUrl(sshUrl) + } + // Checkout await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint) |
