generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverview.ts
122 lines (108 loc) · 3.46 KB
/
overview.ts
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 {Args, Flags} from '@oclif/core'
import sortBy from 'lodash/sortBy.js'
import {match} from 'minimatch'
import BaseCommand from '../../base-command.js'
import {Github} from '../../github.js'
import {Repos} from '../../repos.js'
import {printTable} from '../../table.js'
export default class Overview extends BaseCommand {
public static args = {
org: Args.string({description: 'Github org', required: true}),
}
static description =
'Provides issue, pull request, and discussion counts for the request repositories. Requires GH_TOKEN to be set in the environment.'
static enableJsonFlag = true
static examples = [
{
command: '<%= config.bin %> <%= command.id %> my-github-org',
description: 'Get an overview of the issues and PRs for an org',
},
{
command: '<%= config.bin %> <%= command.id %> my-github-org --discussions',
description: 'Get an overview of the issues, PRs, and discussions for an org',
},
{
command: '<%= config.bin %> <%= command.id %> my-github-org --filter "my-repo-*"',
description: 'Filter out repositories by minimatch pattern',
},
]
static flags = {
discussions: Flags.boolean({
char: 'd',
description: 'Include discussions',
}),
filter: Flags.string({
char: 'f',
description: 'Filter out repositories by minimatch pattern',
multiple: true,
}),
'sort-by': Flags.option({
char: 'b',
default: 'repo',
description: 'Sort by',
options: ['repo', 'issues', 'pulls'] as const,
})(),
}
public async run(): Promise<Record<string, {discussions: number; issues: number; pulls: number}>> {
const {args, flags} = await this.parse(Overview)
const repos = await new Repos().init()
const github = new Github()
let filtered = repos.getReposOfOrg(args.org)
for (const filter of flags.filter ?? []) {
const matches = match(
filtered.map((r) => r.name),
filter,
)
filtered = filtered.filter((r) => matches.includes(r.name))
}
const [discussions, issues, pulls] = await Promise.all([
flags.discussions ? await github.repoDiscussions(filtered) : [],
await github.repoIssues(filtered),
await github.repoPulls(filtered),
])
const results = Object.fromEntries(
filtered.map((repo) => [
repo.name,
{
discussions: discussions.filter((d) => d.repo === repo.name).length,
issues: issues.filter((i) => i.repo === repo.name).length,
pulls: pulls.filter((p) => p.repo === repo.name).length,
},
]),
)
const totals = {
discussions: discussions.length,
issues: issues.length,
pulls: pulls.length,
repo: 'totals',
}
if (!this.jsonEnabled()) {
const sorted = [
...sortBy(
Object.entries(results).map(([repo, {discussions, issues, pulls}]) => ({
discussions,
issues,
pulls,
repo,
})),
flags['sort-by'],
).reverse(),
totals,
]
const data = sorted.map(({discussions, issues, pulls, repo}) => ({
issues,
pulls,
repository: repo,
...(flags.discussions ? {discussions} : {}),
}))
printTable({
columns: flags.discussions
? ['repository', 'issues', 'pulls', 'discussions']
: ['repository', 'issues', 'pulls'],
data,
title: 'Overview',
})
}
return results
}
}