From 431babb42e9e4678c4f20646c52f7f2a9e2a1215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Thu, 16 Jul 2015 14:07:52 +0200 Subject: [PATCH] fix(verify): ensure repo url in package.json is well formed --- src/lib/verify.js | 7 +++++++ test/specs/verify.js | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/lib/verify.js b/src/lib/verify.js index 6b6a4340..d8c68381 100644 --- a/src/lib/verify.js +++ b/src/lib/verify.js @@ -1,3 +1,5 @@ +const parseSlug = require('parse-github-repo-url') + const SemanticReleaseError = require('@semantic-release/error') module.exports = function (pkg, options, env) { @@ -15,6 +17,11 @@ module.exports = function (pkg, options, env) { 'No "repository" found in package.json.', 'ENOPKGREPO' )) + } else if (!parseSlug(pkg.repository.url)) { + errors.push(new SemanticReleaseError( + 'The "repository" field in the package.json is malformed.', + 'EMALFORMEDPKGREPO' + )) } if (options.debug) return errors diff --git a/test/specs/verify.js b/test/specs/verify.js index 731c7812..8c4f34cd 100644 --- a/test/specs/verify.js +++ b/test/specs/verify.js @@ -23,6 +23,18 @@ test('verify pkg, options and env', (t) => { tt.is(errors[0].code, 'ENOPKGNAME') tt.is(errors[1].code, 'ENOPKGREPO') + const errors2 = verify({ + name: 'package', + repository: { + url: 'lol' + } + }, { + debug: true + }, {}) + + tt.is(errors2.length, 1) + tt.is(errors2[0].code, 'EMALFORMEDPKGREPO') + tt.end() })