Skip to content

Commit 5180916

Browse files
committed
Merge pull request #67 from shanel262/master
Check url before extracting user and repo
2 parents 920c6ce + 35cb19f commit 5180916

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
##Pending - x.x.x
22

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

57
## 10 April - 6.2.0
68

lib/github.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,32 @@ function cmdGet (msg, done) {
4141

4242
var data = null
4343

44-
try {data = JSON.parse(body)}
45-
catch (e) {return done(e)}
44+
try { data = JSON.parse(body) }
45+
catch (e) { return done(e) }
4646

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

52-
var matches = /[\/:]([^\/:]+?)[\/:]([^\/]+?)(\.git)*$/.exec(url)
53-
var params = {
54-
name: msg.name,
55-
url: url,
56-
user: matches[1] || null,
57-
repo: matches[2] || null
58-
}
52+
if(url.length > 0) {
53+
var matches = /[\/:]([^\/:]+?)[\/:]([^\/]+?)(\.git)*$/.exec(url)
54+
var params = {
55+
name: msg.name,
56+
url: url,
57+
user: matches[1] || null,
58+
repo: matches[2] || null
59+
}
60+
61+
if (!params.user || !params.repo) {
62+
return done(new Error('not found on npm'))
63+
}
5964

60-
if (!params.user || !params.repo) {
65+
queryGithub(params, done)
66+
}
67+
else{
6168
return done(new Error('not found on npm'))
6269
}
63-
64-
queryGithub(params, done)
6570
})
6671
})
6772
}
@@ -104,9 +109,9 @@ function queryGithub (msg, done) {
104109
name: msg.repo || '',
105110
user: msg.user || '',
106111
repo: msg.repo || '',
107-
stars: repo.stargazers_count || '',
108-
watches: repo.subscribers_count || '',
109-
forks: repo.forks_count || '',
112+
stars: repo.stargazers_count || 0,
113+
watches: repo.subscribers_count || 0,
114+
forks: repo.forks_count || 0,
110115
last: repo.pushed_at || '',
111116
urlRepo: 'https://github.com/' + msg.user + '/' + msg.repo,
112117
urlClone: 'git+https://github.com/' + msg.user + '/' + msg.repo + '.git',

0 commit comments

Comments
 (0)