runContribution
uses tcmts.cli.main.execute, which uses tcmts.cli.help.usageError, which uses tcmts.cli.help.usageOf, which uses tcmts.cli.style.bold, which uses node:util
Runs tcm contribution.
import { routeContribution } from "#codebase/tcmts/cli/commands"; import { author, printContribution, printContributions } from "#codebase/tcmts/cli/contributions"; import { execute } from "#codebase/tcmts/cli/main"; import type { Context } from "#codebase/tcmts/cli/run"; import { dim, green, yellow } from "#codebase/tcmts/cli/style"; import { openRemote, reviewUrl } from "#codebase/tcmts/cli/sync"; import { ask, choose } from "#codebase/tcmts/cli/ui"; import { shortHash } from "#codebase/tcmts/core/hash"; import { parse } from "@bomb.sh/router"; export async function runContribution({ cb, cmd, rest }: Context): Promise<number> { const r = execute(cmd, parse(routeContribution(), { argv: rest })); const { remote } = openRemote(cb, r.model.remote); if (r.route === "/") { printContributions(await remote.contributions(r.model.all), r.model.remote); const url = reviewUrl(cb, r.model.remote); if (url) console.log(dim(`\n ${url}`)); return 0; } const id = r.model.id ?? (await choose( `contribution ${r.route.slice(1)} <id>`, "Which contribution?", (await remote.contributions(false)).map((c) => ({ value: c.id, label: `#${c.id} ${c.title}`, hint: `${c.source} → ${c.target}, ${c.author}`, })), false, )); if (r.route === "/view") printContribution(await remote.contribution(id)); else if (r.route === "/comment") { const body = r.model.text.length ? r.model.text.join(" ") : await ask(`contribution comment ${id} <text>`, "Comment"); await remote.comment(id, { author: author(), body, about: r.model.about ?? null }); console.log(`commented on #${id}`); } else if (r.route === "/merge") { const m = await remote.mergeContribution(id, author()); console.log( `${green("merged")} #${id} on ${r.model.remote} as ${shortHash(m.mergedAs)}${m.todo ? yellow(` (${m.todo} definition(s) to fix there: tcm todo)`) : ""}`, ); console.log(dim(` \`tcm pull ${r.model.remote}\` brings it here`)); } else { await remote.closeContribution(id, author(), r.route === "/reopen"); console.log(`${r.route === "/reopen" ? "reopened" : "closed"} #${id}`); } return 0; }
uses
- tcmts.cli.commands.routeContribution
- tcmts.cli.contributions.author
- tcmts.cli.contributions.printContribution
- tcmts.cli.contributions.printContributions
- tcmts.cli.main.execute
- tcmts.cli.run.Context
- tcmts.cli.style.dim
- tcmts.cli.style.green
- tcmts.cli.style.yellow
- tcmts.cli.sync.openRemote
- tcmts.cli.sync.reviewUrl
- tcmts.cli.ui.ask
- tcmts.cli.ui.choose
- tcmts.core.hash.shortHash