|
3 | 3 | var GitHub = require('github4') |
4 | 4 | var github = new GitHub() |
5 | 5 | var Request = require('request') |
| 6 | +var async = require('async') |
6 | 7 |
|
7 | 8 | var opts = { |
8 | 9 | registry: 'http://registry.npmjs.org/', |
@@ -92,46 +93,59 @@ function queryGithub (msg, done) { |
92 | 93 | token: opts.token |
93 | 94 | }) |
94 | 95 |
|
95 | | - var params = { |
96 | | - user: msg.user, |
97 | | - repo: msg.repo |
98 | | - } |
| 96 | + async.parallel({ |
| 97 | + getRepository: function (cb) { |
| 98 | + github.repos.get({user: msg.user, repo: msg.repo}, cb) |
| 99 | + }, |
| 100 | + |
| 101 | + getReadme: function (cb) { |
| 102 | + github.repos.getReadme({user: msg.user, repo: msg.repo}, (err, readme) => { |
| 103 | + if (err) return cb(err) |
| 104 | + if (!readme.content) return cb(null, false) |
99 | 105 |
|
100 | | - github.repos.get(params, (err, repo) => { |
| 106 | + github.misc.renderMarkdownRaw({ |
| 107 | + data: new Buffer(readme.content, 'base64').toString('ascii') |
| 108 | + }, (err, response) => { |
| 109 | + if (err && !response) return cb(err) // API fails expecting a JSON object |
| 110 | + |
| 111 | + cb(null, response.data) |
| 112 | + }) |
| 113 | + }) |
| 114 | + }, |
| 115 | + |
| 116 | + getPullRequests: function (cb) { |
| 117 | + github.pullRequests.getAll({user: msg.user, repo: msg.repo, state: 'open'}, cb) |
| 118 | + } |
| 119 | + }, (err, results) => { |
101 | 120 | if (err) return done(err) |
102 | | - if (!repo) return done() |
103 | 121 |
|
104 | | - params.state = 'open' |
| 122 | + var data = { |
| 123 | + name: msg.repo || '', |
| 124 | + user: msg.user || '', |
| 125 | + repo: msg.repo || '', |
| 126 | + stars: results.getRepository.stargazers_count || 0, |
| 127 | + watches: results.getRepository.subscribers_count || 0, |
| 128 | + forks: results.getRepository.forks_count || 0, |
| 129 | + last: results.getRepository.pushed_at || '', |
| 130 | + urlRepo: 'https://github.com/' + msg.user + '/' + msg.repo, |
| 131 | + urlClone: 'git+https://github.com/' + msg.user + '/' + msg.repo + '.git', |
| 132 | + urlSsh: 'git@github.com:' + msg.user + '/' + msg.repo + '.git', |
| 133 | + readme: results.getReadme, |
| 134 | + pullRequests: results.getPullRequests && results.getPullRequests.length || 0, |
| 135 | + cached: Date.now() |
| 136 | + } |
105 | 137 |
|
106 | | - github.pullRequests.getAll(params, (err, prs) => { |
| 138 | + function complete (err, data) { |
107 | 139 | if (err) return done(err) |
108 | | - var data = { |
109 | | - name: msg.repo || '', |
110 | | - user: msg.user || '', |
111 | | - repo: msg.repo || '', |
112 | | - stars: repo.stargazers_count || 0, |
113 | | - watches: repo.subscribers_count || 0, |
114 | | - forks: repo.forks_count || 0, |
115 | | - last: repo.pushed_at || '', |
116 | | - urlRepo: 'https://github.com/' + msg.user + '/' + msg.repo, |
117 | | - urlClone: 'git+https://github.com/' + msg.user + '/' + msg.repo + '.git', |
118 | | - urlSsh: 'git@github.com:' + msg.user + '/' + msg.repo + '.git', |
119 | | - pullRequests: prs && prs.length || 0, |
120 | | - cached: Date.now() |
121 | | - } |
122 | | - |
123 | | - function complete (err, data) { |
124 | | - if (err) return done(err) |
125 | | - else done(null, data.data$(data)) |
126 | | - } |
| 140 | + else done(null, data.data$(data)) |
| 141 | + } |
127 | 142 |
|
128 | | - cache.load$(msg.name, (err, cached) => { |
129 | | - if (err) return done(err) |
130 | | - if (cached) return cached.data$(data).save$(complete) |
| 143 | + cache.load$(msg.name, (err, cached) => { |
| 144 | + if (err) return done(err) |
| 145 | + if (cached) return cached.data$(data).save$(complete) |
131 | 146 |
|
132 | | - data.id$ = msg.name |
133 | | - cache.make$(data).save$(complete) |
134 | | - }) |
| 147 | + data.id$ = msg.name |
| 148 | + cache.make$(data).save$(complete) |
135 | 149 | }) |
136 | 150 | }) |
137 | 151 | } |
0 commit comments