Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
##Pending - x.x.x

* toolbag removed.
* Checking that github url exists before trying to extract user and repo
* Stars, forks and watches are now assigned 0 instead of an empty string if repo.* is empty

## 10 April - 6.2.0

Expand Down
35 changes: 20 additions & 15 deletions lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,32 @@ function cmdGet (msg, done) {

var data = null

try {data = JSON.parse(body)}
catch (e) {return done(e)}
try { data = JSON.parse(body) }
catch (e) { return done(e) }

var distTags = data['dist-tags'] || {}
var latest = ((data.versions || {})[distTags.latest]) || {}
var repository = latest.repository || {}
var url = repository.url || ''

var matches = /[\/:]([^\/:]+?)[\/:]([^\/]+?)(\.git)*$/.exec(url)
var params = {
name: msg.name,
url: url,
user: matches[1] || null,
repo: matches[2] || null
}
if(url.length > 0) {
var matches = /[\/:]([^\/:]+?)[\/:]([^\/]+?)(\.git)*$/.exec(url)
var params = {
name: msg.name,
url: url,
user: matches[1] || null,
repo: matches[2] || null
}

if (!params.user || !params.repo) {
return done(new Error('not found on npm'))
}

if (!params.user || !params.repo) {
queryGithub(params, done)
}
else{
return done(new Error('not found on npm'))
}

queryGithub(params, done)
})
})
}
Expand Down Expand Up @@ -104,9 +109,9 @@ function queryGithub (msg, done) {
name: msg.repo || '',
user: msg.user || '',
repo: msg.repo || '',
stars: repo.stargazers_count || '',
watches: repo.subscribers_count || '',
forks: repo.forks_count || '',
stars: repo.stargazers_count || 0,
watches: repo.subscribers_count || 0,
forks: repo.forks_count || 0,
last: repo.pushed_at || '',
urlRepo: 'https://github.com/' + msg.user + '/' + msg.repo,
urlClone: 'git+https://github.com/' + msg.user + '/' + msg.repo + '.git',
Expand Down