From 04d58f25587e074cd9e3a148902edd459d9e2d71 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Mon, 28 Nov 2016 10:43:54 +0100 Subject: [PATCH] Throw error if URL is not valid --- bin/now-deploy.js | 8 ++++++-- lib/github.js | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/now-deploy.js b/bin/now-deploy.js index a19d1de..c9c6d41 100755 --- a/bin/now-deploy.js +++ b/bin/now-deploy.js @@ -203,12 +203,14 @@ async function sync(token) { process.exit(1) } + const isValidRepo = isRepoPath(rawPath) + try { await fs.stat(path) } catch (err) { let repo - if (isRepoPath(rawPath)) { + if (isValidRepo && isValidRepo !== 'no-valid-url') { const searchMessage = setTimeout(() => { console.log('> Didn\'t find directory. Searching on GitHub...') }, 500) @@ -230,7 +232,9 @@ async function sync(token) { // Set global variable for deleting tmp dir later // once the deployment has finished Object.assign(gitHubRepo, repo) - } else if (isRepoPath(rawPath)) { + } else if (isValidRepo === 'no-valid-url') { + stopDeployment(`URL is no valid repository from GitHub or GitLab.`) + } else if (isValidRepo) { const gitRef = gitHubRepo.ref ? `with the ref "${gitHubRepo.ref}" ` : '' stopDeployment(`There's no repository named "${gitHubRepo.main}" ${gitRef}on GitHub`) } else { diff --git a/lib/github.js b/lib/github.js index fadc3af..9fcfacb 100644 --- a/lib/github.js +++ b/lib/github.js @@ -85,6 +85,8 @@ export const isRepoPath = path => { if (allowedHosts.includes(urlParts.host) && notBare) { return true } + + return 'no-valid-url' } return /[^\s\\]\/[^\s\\]/g.test(path)