From 9f19e23ae1b7afcec6545f4d6089540b5432306d Mon Sep 17 00:00:00 2001 From: Tan Zhen Yong Date: Thu, 21 Feb 2019 14:36:55 +0800 Subject: [PATCH] Fix Travis repo regex to only match .git at end - match .git only at end of string - match periods in repository name --- src/Site.js | 2 +- test/unit/Site.test.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Site.js b/src/Site.js index d2bb91c595..fc112e1f27 100644 --- a/src/Site.js +++ b/src/Site.js @@ -895,7 +895,7 @@ Site.prototype.deploy = function (travisTokenVar) { let repoSlug = process.env.TRAVIS_REPO_SLUG; if (options.repo) { // Extract repo slug from user-specified repo URL so that we can include the access token - const repoSlugRegex = /github\.com[:/]([\w-]+\/[\w-]+)\.git/; + const repoSlugRegex = /github\.com[:/]([\w-]+\/[\w-.]+)\.git$/; const repoSlugMatch = repoSlugRegex.exec(options.repo); if (!repoSlugMatch) { reject(new Error('-t/--travis expects a GitHub repository.\n' diff --git a/test/unit/Site.test.js b/test/unit/Site.test.js index 1596f94b42..56367760f0 100644 --- a/test/unit/Site.test.js +++ b/test/unit/Site.test.js @@ -433,6 +433,23 @@ describe('Site deploy with Travis', () => { .toEqual(`https://${process.env.GITHUB_TOKEN}@github.com/USER/REPO.git`); }); + test('Site deploy -t/--travis deploys to correct repo when .git is in repo name', async () => { + process.env.TRAVIS = true; + process.env.GITHUB_TOKEN = 'githubToken'; + process.env.TRAVIS_REPO_SLUG = 'TRAVIS_USER/TRAVIS_REPO.github.io'; + + const json = { + 'src/template/page.ejs': PAGE_EJS, + 'site.json': SITE_JSON_DEFAULT, + _site: {}, + }; + fs.vol.fromJSON(json, ''); + const site = new Site('./', '_site'); + await site.deploy(true); + expect(ghpages.options.repo) + .toEqual(`https://${process.env.GITHUB_TOKEN}@github.com/TRAVIS_USER/TRAVIS_REPO.github.io.git`); + }); + test('Site deploy -t/--travis should not deploy if not in Travis', async () => { const json = { 'src/template/page.ejs': PAGE_EJS,