@mesh-tech/mesh-cli
Version:
CLI for Mesh platform development utilities
35 lines (34 loc) • 1.57 kB
JavaScript
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 proposalsCommand(repo, opts) {
console.log(JSON.stringify(await call(opts, repo, "/proposals"), null, 2));
}
export async function showCommand(repo, id, opts) {
console.log(JSON.stringify(await call(opts, repo, `/proposals/${id}`), null, 2));
}
export async function diffCommand(repo, id, opts) {
const d = (await call(opts, repo, `/proposals/${id}/diff`));
console.log(d.patch);
}
export async function approveCommand(repo, id, opts) {
const sha = opts.sha ??
(await call(opts, repo, `/proposals/${id}`)).headSha;
await call(opts, repo, `/proposals/${id}/approve`, "POST", { sha });
console.log(`approved ${id} @ ${sha.slice(0, 8)}`);
}
export async function rejectCommand(repo, id, opts) {
await call(opts, repo, `/proposals/${id}/reject`, "POST", { reason: opts.reason });
console.log(`rejected ${id}`);
}
export async function commentCommand(repo, id, text, opts) {
await call(opts, repo, `/proposals/${id}/comment`, "POST", { text });
console.log("comment added");
}
export async function requestChangesCommand(repo, id, opts) {
await call(opts, repo, `/proposals/${id}/request-changes`, "POST", { note: opts.note });
console.log(`changes requested on ${id}`);
}