-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
55 lines (46 loc) · 1.53 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const contributors = require('github-contributors')
const merge = require('deepmerge')
const gitRemoteUrl = require('remote-origin-url')
const format = require('github-url-from-git')
const defaultOptions = {
format: 'table',
}
let globalOptions = {} // default
module.exports = function(content, options, config) {
// args set in config transform
if (content && typeof content === 'object') {
// content is not string but a options for the plugin
globalOptions = content
}
return function githubContibutors(content, options, config) {
const userOptions = options || {}
const mergedOptions = merge(globalOptions, userOptions)
// console.log('mergedOptions', mergedOptions)
let repo = mergedOptions.repo
let contribs
if(!repo) {
const gitRemote = gitRemoteUrl.sync()
repo = format(gitRemote).split('https://github.com/')
repo = repo[1]
}
// Add in github tokens if you are hitting rate limits
if (process.env.CLIENT_ID) {
defaultOptions.id = process.env.CLIENT_ID
}
if (process.env.CLIENT_SECRET) {
defaultOptions.secret = process.env.CLIENT_SECRET
}
const contributorsOpts = merge(defaultOptions, mergedOptions)
// console.log('repo', repo)
// console.log('options', contributorsOpts)
// Get repo contributors sync
contributors(repo, contributorsOpts, function(err, res) {
if (err) console.log(err);
contribs = res
});
while(contribs === undefined) {
require('deasync').sleep(100);
}
return contribs;
}
}