-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-loc.js
123 lines (117 loc) · 4.77 KB
/
git-loc.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import 'promise-enhancements'
import 'colors'
import yargs from 'yargs'
import path from 'path'
import {homedir} from 'os'
import {version} from './package.json'
import countContrib from './commands/calcHistory'
import getGitContribData from './commands/getGitData'
const DEFAULT_GH_TOKEN = path.resolve(homedir(), '.github_api_token')
global.c = (s, color = 'cyan') => `${s}`[color]
// = Config ====================|
global.argv = yargs
.command(['get-github-data [ldap] [repos..]', 'get-data', 'get-prs'], 'Fetch github contribution data for user', {
ldap: {
description: 'Which user to get data for',
alias: ['u', 'user'],
type: 'string',
default: 'avdaredevil',
},
repos: {
description: 'The Kubeflow repos to scan in',
default: ['kubeflow', 'metadata', 'frontend', 'pipelines', 'testing', 'kfctl', 'manifests', 'website', 'avdaredevil/git-loc', 'avdaredevil/promise-enhancements'],
type: 'string[]',
array: true,
alias: 'r',
},
'files-to-ignore': {
description: 'Files or regexes (marked as r///<regex>/, ex. r///a/)',
default: ['package-lock.json', 'license_info.csv', 'license.txt', 'generated/src/apis', 'sdk/python/docs/_build', 'generated/ml_metadata/proto', '/__snapshots__/', 'site-packages/', 'dev/null', 'components/centraldashboard/app/clients', '/static/', 'r///(\\.(proto|pb\\.go|libsonnet|snap)|swagger\\.json)$/', 'r///^bootstrap\\//','releasing/bootstrapper/'],
type: 'string[]',
array: true,
alias: ['ign', 'ignore'],
},
'default-repo-namespace': {
description: 'If repo is a single word, look under this Github Org / User',
default: 'kubeflow',
type: 'string',
alias: ['namespace', 'org'],
},
'pr-cache-freshness': {
description: 'How old can the last PR be be before the cache is marked dirty, and I fetch newer PRs only (in days)',
default: 1,
type: 'number',
alias: ['freshness'],
},
'expire-cache': {
description: 'Expire the cache, fetch all github PR data from scratch, and re-cache',
default: false,
type: 'boolean',
},
verbose: {
description: 'Increase the output verbosity of this tool. This includes throttle errors, passive debug logs, etc',
default: false,
type: 'boolean',
},
'input-folder': {
description: 'Input folder to use (uses $cwd, unless overridden)',
default: '.',
type: 'string',
alias: ['i', 'input'],
},
'casual-commit-threshold': {
description: 'How much can max(loc_a, loc_d) be before it seems to be an auto-generated file? (Will generate a warning)',
default: 500,
type: 'number',
alias: 'file-size-threshold',
},
'github-api-token-file': {
description: `You need to create a github personal access token at https://github.com/settings/tokens`+
`, because github has a very strict limit on anonymous API usage.`,
default: DEFAULT_GH_TOKEN,
type: 'string',
alias: 'gh',
},
})
.command(['calculate [from] [to]', 'count'], 'Calculate contributions for user for a give time-range', {
from: {
description: '<num> <years|months|weeks|days|hours> ago || A date like input (what date to look from)',
alias: 'f',
type: 'string',
default: '6 months ago',
},
to: {
description: '<num> <years|quarters|months|weeks|days|hours> ago || A date like input (what date to look from)',
alias: 't',
type: 'string',
default: '0 months ago',
},
})
.version(`v${version}`)
.usage(`Git-Loc produces git line-of-change contributions for a user\nVersion: ${c('v'+version, 'italic')}`.brightYellow)
.epilog('\n-- By: AP'.grey)
.help()
.alias('help', 'h')
.wrap(yargs.terminalWidth())
.demandCommand().recommendCommands().strict()
.scriptName('git-loc').argv
// = Config ===============END==|
const runCommand = async command => {
switch(command) {
case 'get-prs':
case 'get-data':
case 'get-github-data':
return await getGitContribData()
case 'count':
case 'calculate':
return await countContrib()
}
throw `Unimplemented command [${command}] invoked`
}
const [command] = argv._
runCommand(command)
.catch(e => {
if (typeof e == 'string') {console.error(e)}
else {console.error('Error occured:', e)}
process.exit(1)
})