hyouji 0.0.12 → 0.0.13

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.
Files changed (2) hide show
  1. package/dist/index.js +77 -52
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1280,6 +1280,13 @@ const getTargetLabel = async () => {
1280
1280
  };
1281
1281
  const GIT_COMMAND_TIMEOUT_MS = 5e3;
1282
1282
  const _GitRepositoryDetector = class _GitRepositoryDetector {
1283
+ /**
1284
+ * Overrides the internal execAsync function for testing purposes.
1285
+ * @param mock - The mock function to use for execAsync.
1286
+ */
1287
+ static overrideExecAsync(mock) {
1288
+ this.execAsyncInternal = mock;
1289
+ }
1283
1290
  /**
1284
1291
  * Detects Git repository information from the current working directory
1285
1292
  * @param cwd - Current working directory (defaults to process.cwd())
@@ -1287,58 +1294,64 @@ const _GitRepositoryDetector = class _GitRepositoryDetector {
1287
1294
  */
1288
1295
  static async detectRepository(cwd) {
1289
1296
  const workingDir = cwd || process.cwd();
1297
+ let gitRoot;
1290
1298
  try {
1291
- const gitRoot = await this.findGitRoot(workingDir);
1292
- if (!gitRoot) {
1293
- return {
1294
- isGitRepository: false,
1295
- error: "Not a Git repository"
1296
- };
1297
- }
1298
- const remotes = await this.getAllRemotes(gitRoot);
1299
- if (remotes.length === 0) {
1300
- return {
1301
- isGitRepository: true,
1302
- error: "No remotes configured"
1303
- };
1304
- }
1305
- let remoteUrl = null;
1306
- let detectionMethod = "origin";
1307
- if (remotes.includes("origin")) {
1308
- remoteUrl = await this.getRemoteUrl(gitRoot, "origin");
1309
- }
1310
- if (!remoteUrl && remotes.length > 0) {
1311
- remoteUrl = await this.getRemoteUrl(gitRoot, remotes[0]);
1312
- detectionMethod = "first-remote";
1313
- }
1314
- if (!remoteUrl) {
1315
- return {
1316
- isGitRepository: true,
1317
- error: "Could not retrieve remote URL"
1318
- };
1319
- }
1320
- const parsedUrl = this.parseGitUrl(remoteUrl);
1321
- if (!parsedUrl) {
1322
- return {
1323
- isGitRepository: true,
1324
- error: "Could not parse remote URL"
1325
- };
1326
- }
1299
+ gitRoot = await this.findGitRoot(workingDir);
1300
+ } catch (err) {
1301
+ const error = err;
1327
1302
  return {
1328
- isGitRepository: true,
1329
- repositoryInfo: {
1330
- owner: parsedUrl.owner,
1331
- repo: parsedUrl.repo,
1332
- remoteUrl,
1333
- detectionMethod
1334
- }
1303
+ isGitRepository: false,
1304
+ error: error instanceof Error ? error.message : "Unknown error occurred"
1335
1305
  };
1336
- } catch (err) {
1306
+ }
1307
+ if (!gitRoot) {
1337
1308
  return {
1338
1309
  isGitRepository: false,
1339
- error: err instanceof Error ? err.message : "Unknown error occurred"
1310
+ error: "Not a Git repository"
1311
+ };
1312
+ }
1313
+ const remotesResult = await this.getAllRemotes(gitRoot);
1314
+ if ("error" in remotesResult) {
1315
+ return { isGitRepository: false, error: remotesResult.error };
1316
+ }
1317
+ const remotes = remotesResult.remotes;
1318
+ if (remotes.length === 0) {
1319
+ return {
1320
+ isGitRepository: true,
1321
+ error: "No remotes configured"
1322
+ };
1323
+ }
1324
+ let remoteUrl = null;
1325
+ let detectionMethod = "origin";
1326
+ if (remotes.includes("origin")) {
1327
+ remoteUrl = await this.getRemoteUrl(gitRoot, "origin");
1328
+ }
1329
+ if (!remoteUrl && remotes.length > 0) {
1330
+ remoteUrl = await this.getRemoteUrl(gitRoot, remotes[0]);
1331
+ detectionMethod = "first-remote";
1332
+ }
1333
+ if (!remoteUrl) {
1334
+ return {
1335
+ isGitRepository: true,
1336
+ error: "Could not retrieve remote URL"
1337
+ };
1338
+ }
1339
+ const parsedUrl = this.parseGitUrl(remoteUrl);
1340
+ if (!parsedUrl) {
1341
+ return {
1342
+ isGitRepository: true,
1343
+ error: "Could not parse remote URL"
1340
1344
  };
1341
1345
  }
1346
+ return {
1347
+ isGitRepository: true,
1348
+ repositoryInfo: {
1349
+ owner: parsedUrl.owner,
1350
+ repo: parsedUrl.repo,
1351
+ remoteUrl,
1352
+ detectionMethod
1353
+ }
1354
+ };
1342
1355
  }
1343
1356
  /**
1344
1357
  * Finds the Git root directory by traversing up the directory tree
@@ -1354,6 +1367,9 @@ const _GitRepositoryDetector = class _GitRepositoryDetector {
1354
1367
  }
1355
1368
  currentPath = dirname(currentPath);
1356
1369
  }
1370
+ if (existsSync(join(currentPath, ".git"))) {
1371
+ return currentPath;
1372
+ }
1357
1373
  return null;
1358
1374
  }
1359
1375
  /**
@@ -1364,7 +1380,7 @@ const _GitRepositoryDetector = class _GitRepositoryDetector {
1364
1380
  */
1365
1381
  static async getRemoteUrl(gitRoot, remoteName) {
1366
1382
  try {
1367
- const { stdout } = await _GitRepositoryDetector.execAsync(
1383
+ const { stdout } = await this.execAsyncInternal(
1368
1384
  `git remote get-url ${remoteName}`,
1369
1385
  {
1370
1386
  cwd: gitRoot,
@@ -1437,21 +1453,30 @@ const _GitRepositoryDetector = class _GitRepositoryDetector {
1437
1453
  /**
1438
1454
  * Gets all configured Git remotes
1439
1455
  * @param gitRoot - Git repository root directory
1440
- * @returns Promise<string[]> - Array of remote names
1456
+ * @returns Promise with remotes array or error object
1441
1457
  */
1442
1458
  static async getAllRemotes(gitRoot) {
1443
1459
  try {
1444
- const { stdout } = await _GitRepositoryDetector.execAsync("git remote", {
1460
+ const { stdout } = await this.execAsyncInternal("git remote", {
1445
1461
  cwd: gitRoot,
1446
1462
  timeout: GIT_COMMAND_TIMEOUT_MS
1447
1463
  });
1448
- return stdout.trim().split("\n").filter((remote) => remote.length > 0);
1449
- } catch {
1450
- return [];
1464
+ return {
1465
+ remotes: stdout.trim().split("\n").filter((remote) => remote.length > 0)
1466
+ };
1467
+ } catch (err) {
1468
+ const error = err;
1469
+ if (error.code === "ENOENT") {
1470
+ return { error: "Git command not available" };
1471
+ }
1472
+ if (error instanceof Error && (error.message.includes("not a git repository") || error.message.includes("Not a git repository"))) {
1473
+ return { error: "Not a Git repository" };
1474
+ }
1475
+ return { remotes: [] };
1451
1476
  }
1452
1477
  }
1453
1478
  };
1454
- _GitRepositoryDetector.execAsync = promisify(exec);
1479
+ _GitRepositoryDetector.execAsyncInternal = promisify(exec);
1455
1480
  let GitRepositoryDetector = _GitRepositoryDetector;
1456
1481
  const getGitHubConfigs = async () => {
1457
1482
  var _a, _b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyouji",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Hyouji (表示) — A command-line tool for organizing and displaying GitHub labels with clarity and harmony.",
5
5
  "main": "dist/index.js",
6
6
  "author": "koji <baxin1919@gmail.com>",