Skip to content

Commit

Permalink
Minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuens committed Jul 8, 2019
1 parent 57c1cc3 commit 3364b58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/utils/downloadTemplateFromRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ function parseGitHubURL(url) {
const owner = parts[1];
const repo = parts[2];
const branch = isSubdirectory ? parts[pathLength] : 'master';
const isGhe = url.hostname !== 'github.com';
const isGitHubEnterprise = url.hostname !== 'github.com';

if (!isGhe) {
if (!isGitHubEnterprise) {
// validate if given url is a valid GitHub url
validateUrl(url, 'github.com', 'GitHub', owner, repo);
}

const downloadUrl = `https://${
isGhe ? url.hostname : 'github.com'
isGitHubEnterprise ? url.hostname : 'github.com'
}/${owner}/${repo}/archive/${branch}.zip`;

return {
Expand All @@ -74,7 +74,7 @@ function parseGitHubURL(url) {
downloadUrl,
isSubdirectory,
pathToDirectory: getPathDirectory(pathLength + 1, parts),
auth: url.auth ? url.auth : '',
auth: url.auth || '',
};
}

Expand Down Expand Up @@ -181,6 +181,7 @@ function downloadTemplateFromRepo(inputUrl, templateName, downloadPath) {
let serviceName;
let dirName;
let downloadServicePath;
const { auth } = repoInformation;

if (repoInformation.isSubdirectory) {
const folderName = repoInformation.pathToDirectory.split('/').splice(-1)[0];
Expand Down Expand Up @@ -208,7 +209,7 @@ function downloadTemplateFromRepo(inputUrl, templateName, downloadPath) {
extract: true,
strip: 1,
mode: '755',
auth: repoInformation.auth || '',
auth,
};
// download service
return download(repoInformation.downloadUrl, downloadServicePath, downloadOptions)
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/downloadTemplateFromRepo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('downloadTemplateFromRepo', () => {
});

it('should throw an error if the passed URL is not a valid GitHub URL', () => {
expect(() => downloadTemplateFromRepo('http://no-git-url.com/foo/bar')).to.throw(Error);
expect(() => downloadTemplateFromRepo('http://no-git-hub-url.com/foo/bar')).to.throw(Error);
});

it('should throw an error if a directory with the same service name is already present', () => {
Expand Down

0 comments on commit 3364b58

Please sign in to comment.