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/git-source-provider.ts
diff options
context:
space:
mode:
authoreric sciple <ericsciple@users.noreply.github.com>2020-03-18 23:33:26 -0400
committereric sciple <ericsciple@users.noreply.github.com>2020-03-18 23:33:26 -0400
commitd35c5b0d45c2389911e8fa57f5a409dc7eb4eba9 (patch)
tree9504842130011e5303867f926b8e6016a715323e /src/git-source-provider.ts
parent6f1b729011b34bc28608462b6293df85180aba9c (diff)
use token for workflow repo
Diffstat (limited to 'src/git-source-provider.ts')
-rw-r--r--src/git-source-provider.ts30
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)