azdo-cli 0.5.0-025-multi-org-support.447 → 0.5.0-025-multi-org-support.449
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/index.js +66 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -806,6 +806,8 @@ async function status() {
|
|
|
806
806
|
|
|
807
807
|
// src/services/git-remote.ts
|
|
808
808
|
import { execSync } from "child_process";
|
|
809
|
+
import fs from "fs";
|
|
810
|
+
import path from "path";
|
|
809
811
|
|
|
810
812
|
// src/services/remote-warning.ts
|
|
811
813
|
var warned = false;
|
|
@@ -884,17 +886,69 @@ function selectRemote(candidates) {
|
|
|
884
886
|
`Ambiguous Azure DevOps remotes (${names}). Provide --org and --project explicitly.`
|
|
885
887
|
);
|
|
886
888
|
}
|
|
889
|
+
function readGitConfigContent() {
|
|
890
|
+
const gitDirEnv = process.env.GIT_DIR;
|
|
891
|
+
if (gitDirEnv) {
|
|
892
|
+
return fs.readFileSync(path.join(gitDirEnv, "config"), "utf-8");
|
|
893
|
+
}
|
|
894
|
+
let dir = process.cwd();
|
|
895
|
+
for (; ; ) {
|
|
896
|
+
const gitPath = path.join(dir, ".git");
|
|
897
|
+
try {
|
|
898
|
+
const stat = fs.statSync(gitPath);
|
|
899
|
+
if (stat.isDirectory()) {
|
|
900
|
+
return fs.readFileSync(path.join(gitPath, "config"), "utf-8");
|
|
901
|
+
}
|
|
902
|
+
if (stat.isFile()) {
|
|
903
|
+
const ref = fs.readFileSync(gitPath, "utf-8");
|
|
904
|
+
const m = /^gitdir:\s*(.+)$/m.exec(ref);
|
|
905
|
+
if (m) {
|
|
906
|
+
return fs.readFileSync(path.join(path.resolve(dir, m[1].trim()), "config"), "utf-8");
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
} catch {
|
|
910
|
+
}
|
|
911
|
+
const parent = path.dirname(dir);
|
|
912
|
+
if (parent === dir) break;
|
|
913
|
+
dir = parent;
|
|
914
|
+
}
|
|
915
|
+
throw new Error("Not in a git repository. Provide --org and --project explicitly.");
|
|
916
|
+
}
|
|
917
|
+
function gitConfigToRemoteLines(configContent) {
|
|
918
|
+
const lines = [];
|
|
919
|
+
let currentRemote = null;
|
|
920
|
+
let emittedUrl = false;
|
|
921
|
+
for (const line of configContent.split("\n")) {
|
|
922
|
+
const sectionMatch = /^\[remote\s+"([^"]+)"\]/.exec(line);
|
|
923
|
+
if (sectionMatch) {
|
|
924
|
+
currentRemote = sectionMatch[1];
|
|
925
|
+
emittedUrl = false;
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
if (/^\[/.test(line)) {
|
|
929
|
+
currentRemote = null;
|
|
930
|
+
emittedUrl = false;
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
933
|
+
if (currentRemote && !emittedUrl) {
|
|
934
|
+
const urlMatch = /^\s+url\s*=\s*(.+)$/.exec(line);
|
|
935
|
+
if (urlMatch) {
|
|
936
|
+
lines.push(`${currentRemote} ${urlMatch[1].trim()} (fetch)`);
|
|
937
|
+
emittedUrl = true;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
return lines.join("\n");
|
|
942
|
+
}
|
|
887
943
|
function detectAzdoContext() {
|
|
888
|
-
let
|
|
944
|
+
let configContent;
|
|
889
945
|
try {
|
|
890
|
-
|
|
891
|
-
encoding: "utf-8",
|
|
892
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
893
|
-
}).trim();
|
|
946
|
+
configContent = readGitConfigContent();
|
|
894
947
|
} catch {
|
|
895
948
|
throw new Error("Not in a git repository. Provide --org and --project explicitly.");
|
|
896
949
|
}
|
|
897
|
-
const
|
|
950
|
+
const remoteLines = gitConfigToRemoteLines(configContent);
|
|
951
|
+
const candidates = parseAllAzdoRemotes(remoteLines);
|
|
898
952
|
const selected = selectRemote(candidates);
|
|
899
953
|
if (selected.hasEmbeddedSecret) {
|
|
900
954
|
noticeCredentialBearingRemote(selected.remoteName);
|
|
@@ -4571,18 +4625,18 @@ function createDownloadAttachmentCommand() {
|
|
|
4571
4625
|
}
|
|
4572
4626
|
|
|
4573
4627
|
// src/services/update-check.ts
|
|
4574
|
-
import
|
|
4575
|
-
import
|
|
4628
|
+
import fs2 from "fs";
|
|
4629
|
+
import path2 from "path";
|
|
4576
4630
|
import os from "os";
|
|
4577
4631
|
var THROTTLE_MS = 10 * 60 * 1e3;
|
|
4578
4632
|
var FETCH_TIMEOUT_MS = 1500;
|
|
4579
4633
|
var REGISTRY_URL = "https://registry.npmjs.org/azdo-cli/latest";
|
|
4580
4634
|
function getCachePath() {
|
|
4581
|
-
return
|
|
4635
|
+
return path2.join(os.homedir(), ".azdo", "update-check.json");
|
|
4582
4636
|
}
|
|
4583
4637
|
function defaultReadCache() {
|
|
4584
4638
|
try {
|
|
4585
|
-
return
|
|
4639
|
+
return fs2.readFileSync(getCachePath(), "utf-8");
|
|
4586
4640
|
} catch {
|
|
4587
4641
|
return null;
|
|
4588
4642
|
}
|
|
@@ -4590,8 +4644,8 @@ function defaultReadCache() {
|
|
|
4590
4644
|
function defaultWriteCache(data) {
|
|
4591
4645
|
try {
|
|
4592
4646
|
const cachePath = getCachePath();
|
|
4593
|
-
|
|
4594
|
-
|
|
4647
|
+
fs2.mkdirSync(path2.dirname(cachePath), { recursive: true });
|
|
4648
|
+
fs2.writeFileSync(cachePath, data);
|
|
4595
4649
|
} catch {
|
|
4596
4650
|
}
|
|
4597
4651
|
}
|