UNPKG

@mesh-tech/mesh-cli

Version:

CLI for Mesh platform development utilities

45 lines (44 loc) 1.95 kB
import { resolveTarget, resolveToken, vcsApi } from "./common.js"; async function call(opts, repo, path, method = "GET", body) { const target = await resolveTarget({ ...opts, repo }); const token = await resolveToken(opts); return vcsApi(target.baseUrl, token, `/v1/repos/${repo}${path}`, method, body); } export async function draftsListCommand(repo, opts) { const data = (await call(opts, repo, `/drafts${opts.all ? "?all=true" : ""}`)); const drafts = data.drafts; if (drafts.length === 0) { console.log("no drafts"); return; } for (const d of drafts) { console.log(`${d.draftId} [${d.state}] ${d.title} (updated ${d.updatedAt})`); } } export async function draftsShowCommand(repo, draftId, opts) { const d = (await call(opts, repo, `/drafts/${draftId}`)); console.log(`${d.draftId} [${d.state}] ${d.title}`); if (d.headSha !== undefined) { console.log(`head: ${d.headSha}`); } if (d.mergeable === false) { console.log("⚠ the page changed while this draft was being edited"); } if (d.changedFiles) { for (const f of d.changedFiles) { console.log(` ${f.status} ${f.path}`); } } } export async function draftsCreateCommand(repo, opts) { const d = (await call(opts, repo, "/drafts", "POST", opts.title ? { title: opts.title } : {})); console.log(`draft ${d.draftId} created — submit with: mesh vcs drafts submit ${repo} ${d.draftId}`); } export async function draftsSubmitCommand(repo, draftId, opts) { const d = (await call(opts, repo, `/drafts/${draftId}/submit`, "POST", opts.note ? { note: opts.note } : {})); console.log(`draft ${d.draftId} submitted for review [${d.state}]`); } export async function draftsDiscardCommand(repo, draftId, opts) { const d = (await call(opts, repo, `/drafts/${draftId}/discard`, "POST", {})); console.log(`draft ${d.draftId} discarded`); }