From 4837a166c2fbb34b77896cbd962c92f62c25bb75 Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Thu, 8 Oct 2020 07:45:29 -0400 Subject: [PATCH] Make token optional --- .../src/scaffolder/stages/prepare/github.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts index 54265736f3..49703c5616 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/prepare/github.ts @@ -24,9 +24,9 @@ import GitUriParser from 'git-url-parse'; import { Clone, Cred } from 'nodegit'; export class GithubPreparer implements PreparerBase { - token: string; + token?: string; - constructor(params: { token: string }) { + constructor(params: { token?: string } = {}) { this.token = params.token; } @@ -52,15 +52,19 @@ export class GithubPreparer implements PreparerBase { template.spec.path ?? '.', ); - await Clone.clone(repositoryCheckoutUrl, tempDir, { - fetchOpts: { - callbacks: { - credentials() { - return Cred.userpassPlaintextNew(token, 'x-oauth-basic'); + const cloneOptions = token + ? { + fetchOpts: { + callbacks: { + credentials() { + return Cred.userpassPlaintextNew(token, 'x-oauth-basic'); + }, + }, }, - }, - }, - }); + } + : {}; + + await Clone.clone(repositoryCheckoutUrl, tempDir, cloneOptions); return path.resolve(tempDir, templateDirectory); }