runContribute

tcmts.cli.run.runContribute · #eypgaqwq · term · runs on the server

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 contribute.

import { routeContribute } from "#codebase/tcmts/cli/commands";
import { author } from "#codebase/tcmts/cli/contributions";
import { execute } from "#codebase/tcmts/cli/main";
import type { Context } from "#codebase/tcmts/cli/run";
import { bold, dim, green } from "#codebase/tcmts/cli/style";
import { contribute, reviewUrl } from "#codebase/tcmts/cli/sync";
import { ask, interactive } from "#codebase/tcmts/cli/ui";
import { parse } from "@bomb.sh/router";

export async function runContribute({ cb, cmd, rest }: Context): Promise<number> {
  const { model } = execute(cmd, parse(routeContribute(), { argv: rest }));
  const title =
    model.title ??
    (interactive()
      ? await ask(
          "contribute [remote] --title <title>",
          "What's the change?",
          cb.store.branch().name,
        )
      : undefined);
  const r = await contribute(cb, model.remote, {
    to: model.to,
    as: model.as,
    title,
    description: model.description,
    author: author(),
  });
  console.log(
    `${green(r.created ? "opened" : "updated")} contribution ${bold(`#${r.id}`)} on ${model.remote}`,
  );
  const url = reviewUrl(cb, model.remote, r.id);
  console.log(dim(`  review: tcm contribution view ${r.id}${url ? ` · ${url}` : ""}`));
  return 0;
}

uses

used by