@thanaen/ado-cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +71 -7
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -57181,27 +57181,54 @@ import { readFile } from "node:fs/promises";
|
|
|
57181
57181
|
|
|
57182
57182
|
// src/config.ts
|
|
57183
57183
|
var import_azure_devops_node_api = __toESM(require_WebApi(), 1);
|
|
57184
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
57185
|
+
import { join } from "node:path";
|
|
57186
|
+
import { homedir } from "node:os";
|
|
57184
57187
|
var DEFAULT_COLLECTION_URL = "https://dev.azure.com/<your-org>";
|
|
57185
57188
|
var DEFAULT_PROJECT = "<your-project>";
|
|
57186
57189
|
var DEFAULT_REPO = "<your-repository>";
|
|
57187
57190
|
function isDefaultPlaceholder(value) {
|
|
57188
57191
|
return value.includes("<your-");
|
|
57189
57192
|
}
|
|
57193
|
+
function getConfigDir() {
|
|
57194
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME;
|
|
57195
|
+
const base = xdgConfig && xdgConfig.length > 0 ? xdgConfig : join(homedir(), ".config");
|
|
57196
|
+
return join(base, "ado");
|
|
57197
|
+
}
|
|
57198
|
+
function getConfigFilePath() {
|
|
57199
|
+
return join(getConfigDir(), "config.json");
|
|
57200
|
+
}
|
|
57201
|
+
function loadFileConfig() {
|
|
57202
|
+
const configPath = getConfigFilePath();
|
|
57203
|
+
if (!existsSync(configPath)) {
|
|
57204
|
+
return {};
|
|
57205
|
+
}
|
|
57206
|
+
const content = readFileSync(configPath, "utf8");
|
|
57207
|
+
try {
|
|
57208
|
+
return JSON.parse(content);
|
|
57209
|
+
} catch {
|
|
57210
|
+
console.error(`Warning: could not parse config file at ${configPath}. Using defaults.`);
|
|
57211
|
+
return {};
|
|
57212
|
+
}
|
|
57213
|
+
}
|
|
57190
57214
|
function getConfig() {
|
|
57191
|
-
const
|
|
57215
|
+
const fileConfig = loadFileConfig();
|
|
57216
|
+
const pat = process.env.DEVOPS_PAT ?? fileConfig.pat;
|
|
57192
57217
|
if (!pat) {
|
|
57193
|
-
console.error("Missing DEVOPS_PAT environment variable.");
|
|
57218
|
+
console.error("Missing DEVOPS_PAT environment variable or pat in config file.");
|
|
57219
|
+
console.error(`Run "ado init" to create a config file at ${getConfigFilePath()}`);
|
|
57194
57220
|
process.exit(1);
|
|
57195
57221
|
}
|
|
57196
|
-
const collectionUrl = process.env.ADO_COLLECTION_URL ?? DEFAULT_COLLECTION_URL;
|
|
57197
|
-
const project = process.env.ADO_PROJECT ?? DEFAULT_PROJECT;
|
|
57198
|
-
const repo = process.env.ADO_REPO ?? DEFAULT_REPO;
|
|
57222
|
+
const collectionUrl = process.env.ADO_COLLECTION_URL ?? fileConfig.collectionUrl ?? DEFAULT_COLLECTION_URL;
|
|
57223
|
+
const project = process.env.ADO_PROJECT ?? fileConfig.project ?? DEFAULT_PROJECT;
|
|
57224
|
+
const repo = process.env.ADO_REPO ?? fileConfig.repo ?? DEFAULT_REPO;
|
|
57199
57225
|
if (isDefaultPlaceholder(collectionUrl) || isDefaultPlaceholder(project) || isDefaultPlaceholder(repo)) {
|
|
57200
57226
|
console.error("ADO configuration is incomplete. Set ADO_COLLECTION_URL, ADO_PROJECT, and ADO_REPO.");
|
|
57201
|
-
console.error(
|
|
57227
|
+
console.error(`You can also run "ado init" to create a config file at ${getConfigFilePath()}`);
|
|
57202
57228
|
process.exit(1);
|
|
57203
57229
|
}
|
|
57204
|
-
|
|
57230
|
+
const insecure = process.env.ADO_INSECURE === "1" || fileConfig.insecure === true;
|
|
57231
|
+
if (insecure) {
|
|
57205
57232
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
57206
57233
|
}
|
|
57207
57234
|
const authHandler = import_azure_devops_node_api.getPersonalAccessTokenHandler(pat);
|
|
@@ -57739,10 +57766,43 @@ async function cmdPrUpdate(config, idRaw, args) {
|
|
|
57739
57766
|
await linkWorkItemsToPr(config, repo, updated, workItemIds);
|
|
57740
57767
|
}
|
|
57741
57768
|
}
|
|
57769
|
+
async function cmdInit() {
|
|
57770
|
+
const { createInterface } = await import("node:readline/promises");
|
|
57771
|
+
const { mkdirSync, writeFileSync, existsSync: existsSync2 } = await import("node:fs");
|
|
57772
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
57773
|
+
const existing = loadFileConfig();
|
|
57774
|
+
const configPath = getConfigFilePath();
|
|
57775
|
+
console.log("Azure DevOps CLI — Configuration");
|
|
57776
|
+
console.log(`Config file: ${configPath}`);
|
|
57777
|
+
console.log(`Press Enter to keep existing values shown in brackets.
|
|
57778
|
+
`);
|
|
57779
|
+
const pat = await rl.question(`Personal Access Token (PAT)${existing.pat ? " [****]" : ""}: `) || existing.pat || "";
|
|
57780
|
+
const collectionUrl = await rl.question(`Collection URL${existing.collectionUrl ? ` [${existing.collectionUrl}]` : ""}: `) || existing.collectionUrl || "";
|
|
57781
|
+
const project = await rl.question(`Project${existing.project ? ` [${existing.project}]` : ""}: `) || existing.project || "";
|
|
57782
|
+
const repo = await rl.question(`Repository${existing.repo ? ` [${existing.repo}]` : ""}: `) || existing.repo || "";
|
|
57783
|
+
const insecureInput = await rl.question(`Disable TLS verification (insecure)? (y/N)${existing.insecure ? " [y]" : ""}: `) || (existing.insecure ? "y" : "n");
|
|
57784
|
+
const insecure = insecureInput.toLowerCase() === "y" || insecureInput === "1";
|
|
57785
|
+
rl.close();
|
|
57786
|
+
if (!pat || !collectionUrl || !project || !repo) {
|
|
57787
|
+
console.error(`
|
|
57788
|
+
All fields (PAT, Collection URL, Project, Repository) are required.`);
|
|
57789
|
+
process.exit(1);
|
|
57790
|
+
}
|
|
57791
|
+
const config = { pat, collectionUrl, project, repo, insecure };
|
|
57792
|
+
const configDir = getConfigDir();
|
|
57793
|
+
if (!existsSync2(configDir)) {
|
|
57794
|
+
mkdirSync(configDir, { recursive: true });
|
|
57795
|
+
}
|
|
57796
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2) + `
|
|
57797
|
+
`, "utf8");
|
|
57798
|
+
console.log(`
|
|
57799
|
+
Configuration saved to ${configPath}`);
|
|
57800
|
+
}
|
|
57742
57801
|
function printHelp() {
|
|
57743
57802
|
console.log(`Azure DevOps CLI
|
|
57744
57803
|
|
|
57745
57804
|
Commands:
|
|
57805
|
+
init
|
|
57746
57806
|
smoke
|
|
57747
57807
|
repos
|
|
57748
57808
|
branches [repo]
|
|
@@ -57766,6 +57826,10 @@ async function main() {
|
|
|
57766
57826
|
printHelp();
|
|
57767
57827
|
return;
|
|
57768
57828
|
}
|
|
57829
|
+
if (command === "init") {
|
|
57830
|
+
await cmdInit();
|
|
57831
|
+
return;
|
|
57832
|
+
}
|
|
57769
57833
|
const config = getConfig();
|
|
57770
57834
|
switch (command) {
|
|
57771
57835
|
case "smoke":
|