Comparing version 0.0.2 to 0.0.3
@@ -21,27 +21,36 @@ const resolver = require('../src/packageRepoResolver'); | ||
it('parses git urls', () => { | ||
const svgo = 'https://github.com/svg/svgo.git'; | ||
const inquirer = 'git+https://github.com/sboudrias/Inquirer.js.git'; | ||
const ghStar = 'git+https://github.com/fedebertolini/gh-star.git'; | ||
const urlWithoutGitExt = 'https://github.com/svg/svgo'; | ||
const urlWithTag = 'git+https://github.com/sboudrias/Inquirer.js.git#v3.0.1'; | ||
const bitbuckerUrl = 'https://bitbucket.org/simpletechs/node-safe-enum.git'; | ||
const malformedUrl = 'https://github.com/fedebertolini/'; | ||
it('parses valid git urls', () => { | ||
repos = [{ | ||
url: 'https://github.com/svg/svgo.git', | ||
fullName: 'svg/svgo', | ||
}, { | ||
url: 'git+https://github.com/sboudrias/Inquirer.js.git', | ||
fullName: 'sboudrias/Inquirer.js', | ||
}, { | ||
url: 'git+https://github.com/fedebertolini/gh-star.git', | ||
fullName: 'fedebertolini/gh-star', | ||
}, { | ||
url: 'https://github.com/svg/svgo', | ||
fullName: 'svg/svgo', | ||
}, { | ||
url: 'git+https://github.com/sboudrias/Inquirer.js.git#v3.0.1', | ||
fullName: 'sboudrias/Inquirer.js', | ||
}]; | ||
const svgoResult = resolver.parseGitUrl(svgo); | ||
const inquirerResult = resolver.parseGitUrl(inquirer); | ||
const ghStarResult = resolver.parseGitUrl(ghStar); | ||
const urlWithoutGitExtResult = resolver.parseGitUrl(urlWithoutGitExt); | ||
const urlWithTagResult = resolver.parseGitUrl(urlWithTag); | ||
const bitbuckerUrlResult = resolver.parseGitUrl(bitbuckerUrl); | ||
const malformedUrlResult = resolver.parseGitUrl(bitbuckerUrl); | ||
repos.forEach(repo => { | ||
const repoInfo = resolver.parseGitUrl(repo.url); | ||
expect(repoInfo.fullName).toBe(repo.fullName); | ||
}); | ||
}); | ||
expect(svgoResult.fullName).toBe('svg/svgo'); | ||
expect(inquirerResult.fullName).toBe('sboudrias/Inquirer.js'); | ||
expect(ghStarResult.fullName).toBe('fedebertolini/gh-star'); | ||
expect(urlWithoutGitExtResult.fullName).toBe('svg/svgo'); | ||
expect(urlWithTagResult.fullName).toBe('sboudrias/Inquirer.js'); | ||
expect(bitbuckerUrlResult).toBe(null); | ||
expect(malformedUrlResult).toBe(null); | ||
it('parses invalid git urls', () => { | ||
repos = [ | ||
'https://bitbucket.org/simpletechs/node-safe-enum.git', | ||
'https://github.com/fedebertolini/', | ||
]; | ||
repos.forEach(url => { | ||
expect(resolver.parseGitUrl(url)).toBe(null); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "gh-star", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "NodeJS app that stars the GitHub repos referenced in a package.json file", | ||
@@ -5,0 +5,0 @@ "preferGlobal": true, |
@@ -14,5 +14,4 @@ # :star: gh-star :star: | ||
Since **gh-star** impersonates you for starring repositories, you | ||
need to provide a Github Personal Access Token. You can | ||
[get an access token by following this instructions] | ||
(https://help.github.com/articles/creating-an-access-token-for-command-line-use/). | ||
need to provide a [Github Personal Access Token](https://github.com/settings/tokens). | ||
You can [get an access token by following this instructions](https://help.github.com/articles/creating-an-access-token-for-command-line-use/). | ||
The only required scope for the access token is `public_repo`. | ||
@@ -19,0 +18,0 @@ |
@@ -32,3 +32,3 @@ const GitHubApi = require('github'); | ||
result.forEach(item => { | ||
repos[item.full_name] = true; | ||
repos[item.full_name.toLowerCase()] = true; | ||
}); | ||
@@ -39,11 +39,15 @@ return repos; | ||
exports.starRepos = (repos) => { | ||
return Promise.all(repos.map(repo => { | ||
return github.activity.starRepo({ | ||
owner: repo.username, | ||
repo: repo.repository, | ||
}).catch(e => Promise.reject(`${repo.fullName}: ${e.message}`)); | ||
})); | ||
exports.starRepo = (repo) => { | ||
return github.activity.starRepo({ | ||
owner: repo.username, | ||
repo: repo.repository, | ||
}).catch(e => Promise.reject(`${repo.fullName}: ${e.message}`)); | ||
}; | ||
exports.starGHStar = () => module.exports.starRepo({ | ||
username: 'fedebertolini', | ||
repository: 'gh-star', | ||
fullName: 'fedebertolini/gh-star', | ||
}); | ||
exports.tokenAuth = (token) => { | ||
@@ -50,0 +54,0 @@ github.authenticate({ |
@@ -25,4 +25,17 @@ #! /usr/bin/env node | ||
let starredRepos = {}; | ||
let unstarredRepos = []; | ||
const promises = []; | ||
const promptStarRepoQuestion = (repositories) => { | ||
if (repositories.length === 0) { | ||
return true; | ||
} | ||
const repo = repositories[0]; | ||
return inquirer.prompt(prompt.starRepo(repo.fullName, 'star')).then((answer) => { | ||
if (answer.star) { | ||
promises.push(githubClient.starRepo(repo)); | ||
} | ||
return promptStarRepoQuestion(repositories.slice(1)); | ||
}); | ||
}; | ||
inquirer.prompt(prompt.githubPersonalToken()).then(answer => { | ||
@@ -41,13 +54,23 @@ githubClient.tokenAuth(answer.token); | ||
}).then((repositories) => { | ||
unstarredRepos = repositories.filter(repo => { | ||
const unstarredRepos = repositories.filter(repo => { | ||
return !!repo && !starredRepos[repo.fullName]; | ||
}); | ||
return inquirer.prompt(prompt.starRepos(unstarredRepos)); | ||
}).then((answers) => { | ||
const repos = unstarredRepos.filter((repo, index) => answers[index + 1]); | ||
return githubClient.starRepos(repos); | ||
}).then(() => { | ||
logger.info('The selected repos have been starred!'); | ||
if (unstarredRepos.length) { | ||
return promptStarRepoQuestion(unstarredRepos).then(() => { | ||
return Promise.all(promises); | ||
}).then(() => { | ||
return inquirer.prompt(prompt.starGHStar('star')); | ||
}).then((answer) => { | ||
if (answer.star) { | ||
return githubClient.starGHStar(); | ||
} | ||
}).then(() => { | ||
logger.info('The selected repos have been starred!'); | ||
}); | ||
} else { | ||
logger.info('All repos are already starred'); | ||
} | ||
}).catch(e => { | ||
logger.error(e); | ||
}); |
@@ -27,11 +27,9 @@ const logger = require('./logger'); | ||
const parseDependenciesObject = (obj) => { | ||
const parseDependenciesObject = (obj = {}) => { | ||
const result = []; | ||
if (obj) { | ||
for (key in obj) { | ||
result.push({ | ||
name: key, | ||
version: obj[key], | ||
}); | ||
} | ||
for (key in obj) { | ||
result.push({ | ||
name: key, | ||
version: obj[key], | ||
}); | ||
} | ||
@@ -38,0 +36,0 @@ return result; |
@@ -51,7 +51,9 @@ const npa = require('npm-package-arg'); | ||
const hostedInfo = hostedGitInfo.fromUrl(gitUrl); | ||
if (hostedInfo.type === 'github') { | ||
if (hostedInfo && hostedInfo.type === 'github') { | ||
const username = hostedInfo.user.toLowerCase(); | ||
const repository = hostedInfo.project.toLowerCase(); | ||
return { | ||
username: hostedInfo.user, | ||
repository: hostedInfo.project, | ||
fullName: `${hostedInfo.user}/${hostedInfo.project}`, | ||
username: username, | ||
repository: repository, | ||
fullName: `${username}/${repository}`, | ||
}; | ||
@@ -58,0 +60,0 @@ } |
@@ -8,7 +8,14 @@ exports.githubPersonalToken = () => ({ | ||
exports.starRepos = (repos) => repos.map((repo, index) => ({ | ||
exports.starRepo = (repoName, questionName) => ({ | ||
type: 'confirm', | ||
name: index + 1, | ||
message: `Do you want to star ${repo.fullName}?`, | ||
name: questionName, | ||
message: `Do you want to star ${repoName}?`, | ||
default: true, | ||
})); | ||
}); | ||
exports.starGHStar = (questionName) => ({ | ||
type: 'confirm', | ||
name: questionName, | ||
message: `Would you like to star gh-star too?`, | ||
default: true, | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91628
427
28