Browse Source

Throw error if URL is not valid

master
Leo Lamprecht 8 years ago
parent
commit
04d58f2558
No known key found for this signature in database GPG Key ID: B08517883D5E0E10
  1. 8
      bin/now-deploy.js
  2. 2
      lib/github.js

8
bin/now-deploy.js

@ -203,12 +203,14 @@ async function sync(token) {
process.exit(1) process.exit(1)
} }
const isValidRepo = isRepoPath(rawPath)
try { try {
await fs.stat(path) await fs.stat(path)
} catch (err) { } catch (err) {
let repo let repo
if (isRepoPath(rawPath)) { if (isValidRepo && isValidRepo !== 'no-valid-url') {
const searchMessage = setTimeout(() => { const searchMessage = setTimeout(() => {
console.log('> Didn\'t find directory. Searching on GitHub...') console.log('> Didn\'t find directory. Searching on GitHub...')
}, 500) }, 500)
@ -230,7 +232,9 @@ async function sync(token) {
// Set global variable for deleting tmp dir later // Set global variable for deleting tmp dir later
// once the deployment has finished // once the deployment has finished
Object.assign(gitHubRepo, repo) 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}" ` : '' const gitRef = gitHubRepo.ref ? `with the ref "${gitHubRepo.ref}" ` : ''
stopDeployment(`There's no repository named "${gitHubRepo.main}" ${gitRef}on GitHub`) stopDeployment(`There's no repository named "${gitHubRepo.main}" ${gitRef}on GitHub`)
} else { } else {

2
lib/github.js

@ -85,6 +85,8 @@ export const isRepoPath = path => {
if (allowedHosts.includes(urlParts.host) && notBare) { if (allowedHosts.includes(urlParts.host) && notBare) {
return true return true
} }
return 'no-valid-url'
} }
return /[^\s\\]\/[^\s\\]/g.test(path) return /[^\s\\]\/[^\s\\]/g.test(path)

Loading…
Cancel
Save