Skip to content

Commit 9d43ff9

Browse files
committed
feat: add topics command for listing customer topics
1 parent 7bcee6d commit 9d43ff9

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

src/cli/commands/topics.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { CommandModule } from "yargs"
2+
import { createGitHubService } from "../../github"
3+
import { createCacheProvider, createConfig, createReporter } from "../util"
4+
5+
const command: CommandModule = {
6+
command: "topics",
7+
describe: "List customer topics in a GitHub organization",
8+
builder: (yargs) =>
9+
yargs.options("org", {
10+
alias: "o",
11+
default: "capralifecycle",
12+
requiresArg: true,
13+
describe: "GitHub organization",
14+
type: "string",
15+
}),
16+
handler: async (argv) => {
17+
const config = createConfig()
18+
const reporter = createReporter()
19+
const github = await createGitHubService({
20+
cache: createCacheProvider(config, argv),
21+
})
22+
23+
const repos = await github.getOrgRepoList({ org: argv.org as string })
24+
25+
const topics = new Set<string>()
26+
for (const repo of repos) {
27+
for (const edge of repo.repositoryTopics.edges) {
28+
const name = edge.node.topic.name
29+
if (name.startsWith("customer-")) {
30+
topics.add(name)
31+
}
32+
}
33+
}
34+
35+
const sorted = [...topics].sort((a, b) => a.localeCompare(b))
36+
for (const topic of sorted) {
37+
reporter.log(topic)
38+
}
39+
},
40+
}
41+
42+
export default command

src/cli/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import clone from "./commands/clone"
77
import groups from "./commands/groups"
88
import repos from "./commands/repos"
99
import sync from "./commands/sync"
10+
import topics from "./commands/topics"
1011

1112
declare const BUILD_TIMESTAMP: string
1213

@@ -52,6 +53,7 @@ Before using, authenticate with: cals auth`)
5253
.command(groups)
5354
.command(repos)
5455
.command(sync)
56+
.command(topics)
5557
.version(version)
5658
.demandCommand()
5759
.option("no-cache", {
@@ -61,6 +63,7 @@ Before using, authenticate with: cals auth`)
6163
.example("cals auth", "Set GitHub token")
6264
.example("cals repos", "List repositories")
6365
.example("cals groups", "List repository groups")
66+
.example("cals topics", "List customer topics")
6467
.example("cals clone --all | bash", "Clone all repos")
6568
.example("cals sync", "Pull latest changes")
6669
.parse()

0 commit comments

Comments
 (0)