Skip to content

Commit

Permalink
feat: use oclif/multi-stage-output
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Sep 25, 2024
1 parent 8a83f23 commit 9159682
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 114 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"no-await-in-loop": "off",
"no-useless-escape": "off",
"unicorn/no-await-expression-member": "off",
"lines-between-class-members": "off"
"lines-between-class-members": "off",
"react/jsx-tag-spacing": "off"
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ Open a repository in github.
```
USAGE
$ multi open REPO [-f <value> | -t actions|discussions|issues|pulls|pulse|security|settings|wiki]
$ multi open REPO [-f <value> | -t
actions|discussions|issues|pulls|pulse|security|settings|wiki]

ARGUMENTS
REPO [default: .] Name of repository.
Expand Down
217 changes: 213 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@inkjs/ui": "^1",
"@inquirer/input": "^3",
"@oclif/core": "^4",
"@oclif/multi-stage-output": "^0.6.1",
"@oclif/table": "^0.1.9",
"@octokit/plugin-paginate-graphql": "^5.0.0",
"@octokit/plugin-request-log": "^5.0.0",
Expand Down
68 changes: 68 additions & 0 deletions src/commands/refresh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {Flags} from '@oclif/core'
import {ParallelMultiStageOutput} from '@oclif/multi-stage-output'

import BaseCommand from '../base-command.js'
import {Repos} from '../repos.js'

export class Refresh extends BaseCommand {
public static description = 'Refresh the list of repositories and corresponding metadata.'
public static flags = {
all: Flags.boolean({
char: 'a',
description: 'Refresh all orgs.',
exclusive: ['org'],
}),
'dry-run': Flags.boolean({
char: 'd',
description: 'Show what would be done without doing it.',
}),
'no-cache': Flags.boolean({
description: 'Find repos by looking at configured repos directory instead of using the cached repos.json file.',
}),
org: Flags.string({
char: 'o',
description: 'Github org to refresh.',
exclusive: ['all'],
multiple: true,
}),
}

public async run(): Promise<void> {
const {flags} = await this.parse(Refresh)
const repos = await new Repos().init()
const orgs = flags.all ? repos.getOrgs() : (flags.org ?? [])

const repoCounts = Object.fromEntries(orgs.map((org) => [org, repos.getReposOfOrg(org, true).length]))

if (flags['no-cache']) {
await repos.hydrateCache()
}

const mso = new ParallelMultiStageOutput<{repoCounts: typeof repoCounts}>({
jsonEnabled: this.jsonEnabled(),
stageSpecificBlock: orgs.map((org) => ({
get: (data) => data?.repoCounts[org].toString(),
label: 'repos',
stage: org,
type: 'static-key-value',
})),
stages: orgs,
title: flags['dry-run'] ? '[DRY RUN] Refreshing repositories' : 'Refreshing repositories',
})

mso.updateData({repoCounts})
await Promise.all(
orgs.map(async (org) => {
mso.startStage(org)
await repos.refresh(org, true)
mso.stopStage(org)
}),
)

mso.stop()

if (!flags['dry-run']) {
await repos.write()
}
}
}
Loading

0 comments on commit 9159682

Please sign in to comment.