Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/cli/commands/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import { hideBin } from "yargs/helpers"
import type { Config } from "../../config"
import { createGitHubService, type GitHubService } from "../../github"
import { getGroupedRepos, includesTopic } from "../../github/util"
import { createCacheProvider, createConfig } from "../util"
import type { Reporter } from "../reporter"
import { createCacheProvider, createConfig, createReporter } from "../util"

async function generateCloneCommands({
config,
github,
reporter,
org,
...opt
}: {
config: Config
github: GitHubService
reporter: Reporter
all: boolean
skipCloned: boolean
group: string | undefined
Expand All @@ -29,6 +32,7 @@ async function generateCloneCommands({
return
}

reporter.status(`Fetching repositories from ${org}...`)
const repos = await github.getOrgRepoList({ org })
const groups = getGroupedRepos(repos)

Expand Down Expand Up @@ -103,6 +107,7 @@ const command: CommandModule = {
github: await createGitHubService({
cache: createCacheProvider(config, argv),
}),
reporter: createReporter(),
all: !!argv.all,
includeArchived: !!argv["include-archived"],
name: argv.name as string | undefined,
Expand Down
69 changes: 48 additions & 21 deletions src/cli/commands/groups.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,58 @@
import fs from "node:fs"
import path from "node:path"
import process from "node:process"
import { findUp } from "find-up"
import yaml from "js-yaml"
import type { CommandModule } from "yargs"
import { createGitHubService } from "../../github"
import { getGroupedRepos } from "../../github/util"
import { createCacheProvider, createConfig, createReporter } from "../util"
import { DefinitionFile } from "../../definition"
import { createReporter } from "../util"

const CALS_YAML = ".cals.yaml"

interface CalsManifest {
version: 2
githubOrganization: string
resourcesDefinition: {
path: string
}
}

const command: CommandModule = {
command: "groups",
describe: "List available repository groups in a GitHub organization",
builder: (yargs) =>
yargs.options("org", {
alias: "o",
default: "capralifecycle",
requiresArg: true,
describe: "GitHub organization",
type: "string",
}),
handler: async (argv) => {
const config = createConfig()
describe: "List available project groups from the definition file",
builder: (yargs) => yargs,
handler: async () => {
const reporter = createReporter()
const github = await createGitHubService({
cache: createCacheProvider(config, argv),
})

const repos = await github.getOrgRepoList({ org: argv.org as string })
const groups = getGroupedRepos(repos)
const manifestPath = await findUp(CALS_YAML)
if (manifestPath === undefined) {
reporter.error(`File ${CALS_YAML} not found`)
process.exitCode = 1
return
}

const manifest: CalsManifest = yaml.load(
fs.readFileSync(manifestPath, "utf-8"),
) as CalsManifest

const definitionPath = path.resolve(
path.dirname(manifestPath),
manifest.resourcesDefinition.path,
)

if (!fs.existsSync(definitionPath)) {
reporter.error(`Definition file not found: ${definitionPath}`)
process.exitCode = 1
return
}

const definition = await new DefinitionFile(definitionPath).getDefinition()
const projectNames = definition.projects
.map((p) => p.name)
.sort((a, b) => a.localeCompare(b))

for (const group of groups) {
reporter.log(group.name)
for (const name of projectNames) {
reporter.log(name)
}
},
}
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async function listRepos({
csv: boolean
org: string
}) {
reporter.status(`Fetching repositories from ${org}...`)
let repos = await github.getOrgRepoList({ org })

if (!includeArchived) {
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ async function getExpectedRepos(
expectedRepos: ExpectedRepo[]
definitionRepo: ExpectedRepo | null
}> {
reporter.status(`Fetching repositories from ${cals.githubOrganization}...`)
const githubRepos = await github.getOrgRepoList({
org: cals.githubOrganization,
})
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const command: CommandModule = {
cache: createCacheProvider(config, argv),
})

reporter.status(`Fetching repositories from ${argv.org}...`)
const repos = await github.getOrgRepoList({ org: argv.org as string })

const topics = new Set<string>()
Expand Down
8 changes: 8 additions & 0 deletions src/cli/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,12 @@ export class Reporter {
clearLine(this.stdout)
this.stdout.write(`${this.format.blue("info")} ${msg}\n`)
}

/**
* Write a status message to stderr for feedback during long-running operations.
* Writing to stderr ensures it doesn't interfere with piped stdout.
*/
public status(msg: string): void {
this.stderr.write(`${this.format.dim(msg)}\n`)
}
}