@lumy-pack/line-lore 0.0.3 → 0.0.4

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.mjs CHANGED
@@ -21,7 +21,14 @@ var __copyProps = (to, from, except, desc) => {
21
21
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
22
 
23
23
  // src/cache/sharded-cache.ts
24
- import { mkdir, readFile, readdir, rename, rm, writeFile } from "fs/promises";
24
+ import {
25
+ mkdir,
26
+ readFile,
27
+ readdir,
28
+ rename,
29
+ rm,
30
+ writeFile
31
+ } from "fs/promises";
25
32
  import { homedir } from "os";
26
33
  import { join } from "path";
27
34
  function getShardPrefix(key) {
@@ -148,9 +155,7 @@ var init_sharded_cache = __esm({
148
155
  data[key] = { key, value, createdAt: Date.now() };
149
156
  const keys = Object.keys(data);
150
157
  if (keys.length > this.maxEntriesPerShard) {
151
- const sorted = keys.sort(
152
- (a, b) => data[a].createdAt - data[b].createdAt
153
- );
158
+ const sorted = keys.sort((a, b) => data[a].createdAt - data[b].createdAt);
154
159
  const toRemove = sorted.slice(0, keys.length - this.maxEntriesPerShard);
155
160
  for (const k of toRemove) {
156
161
  delete data[k];
@@ -400,7 +405,9 @@ function getCache(repoId, noCache) {
400
405
  if (noCache) {
401
406
  return new ShardedCache("patch-id", { repoId, enabled: false });
402
407
  }
403
- const key = repoKey(repoId ?? { host: "_local", owner: "_", repo: "_default" });
408
+ const key = repoKey(
409
+ repoId ?? { host: "_local", owner: "_", repo: "_default" }
410
+ );
404
411
  let cache = cacheRegistry.get(key);
405
412
  if (!cache) {
406
413
  cache = new ShardedCache("patch-id", { repoId });
@@ -488,7 +495,9 @@ function getCache2(repoId, noCache) {
488
495
  if (noCache) {
489
496
  return new ShardedCache("pr", { repoId, enabled: false });
490
497
  }
491
- const key = repoKey2(repoId ?? { host: "_local", owner: "_", repo: "_default" });
498
+ const key = repoKey2(
499
+ repoId ?? { host: "_local", owner: "_", repo: "_default" }
500
+ );
492
501
  let cache = cacheRegistry2.get(key);
493
502
  if (!cache) {
494
503
  cache = new ShardedCache("pr", { repoId });
@@ -584,7 +593,7 @@ var VERSION;
584
593
  var init_version = __esm({
585
594
  "src/version.ts"() {
586
595
  "use strict";
587
- VERSION = "0.0.3";
596
+ VERSION = "0.0.4";
588
597
  }
589
598
  });
590
599
 
@@ -680,9 +689,8 @@ function respondError(command, code, message, startTime, version2, details) {
680
689
  import { Command } from "commander";
681
690
 
682
691
  // src/core/core.ts
683
- init_cache();
684
- import { map as map8 } from "@winglet/common-utils";
685
692
  import { createHash as createHash2 } from "crypto";
693
+ import { map as map8 } from "@winglet/common-utils";
686
694
 
687
695
  // src/ast/parser.ts
688
696
  import { isNil } from "@winglet/common-utils";
@@ -889,7 +897,9 @@ function findPythonBlockEnd(lines, startIdx) {
889
897
  }
890
898
 
891
899
  // src/core/core.ts
900
+ init_cache();
892
901
  init_errors();
902
+ init_executor();
893
903
 
894
904
  // src/git/health.ts
895
905
  init_executor();
@@ -937,9 +947,6 @@ async function checkGitHealth(options) {
937
947
  return { commitGraph, bloomFilter, gitVersion, hints };
938
948
  }
939
949
 
940
- // src/core/core.ts
941
- init_executor();
942
-
943
950
  // src/git/remote.ts
944
951
  init_errors();
945
952
  init_executor();
@@ -1004,10 +1011,12 @@ var GitHubAdapter = class {
1004
1011
  hostname;
1005
1012
  defaultBranchCache = null;
1006
1013
  remoteName;
1014
+ cwd;
1007
1015
  constructor(options) {
1008
1016
  this.hostname = options?.hostname ?? "github.com";
1009
1017
  this.scheduler = options?.scheduler ?? new RequestScheduler();
1010
1018
  this.remoteName = options?.remoteName ?? "origin";
1019
+ this.cwd = options?.cwd;
1011
1020
  }
1012
1021
  async checkAuth() {
1013
1022
  try {
@@ -1015,6 +1024,7 @@ var GitHubAdapter = class {
1015
1024
  "gh",
1016
1025
  ["auth", "token", "--hostname", this.hostname],
1017
1026
  {
1027
+ cwd: this.cwd,
1018
1028
  allowExitCodes: [1]
1019
1029
  }
1020
1030
  );
@@ -1030,14 +1040,18 @@ var GitHubAdapter = class {
1030
1040
  async getPRForCommit(sha) {
1031
1041
  if (this.scheduler.isRateLimited()) return null;
1032
1042
  try {
1033
- const result = await shellExec("gh", [
1034
- "api",
1035
- `repos/{owner}/{repo}/commits/${sha}/pulls`,
1036
- "--hostname",
1037
- this.hostname,
1038
- "--jq",
1039
- "[.[] | select(.merged_at != null) | {number, title, user: .user.login, html_url, merge_commit_sha, base: .base.ref, merged_at}] | sort_by(.merged_at)"
1040
- ]);
1043
+ const result = await shellExec(
1044
+ "gh",
1045
+ [
1046
+ "api",
1047
+ `repos/{owner}/{repo}/commits/${sha}/pulls`,
1048
+ "--hostname",
1049
+ this.hostname,
1050
+ "--jq",
1051
+ "[.[] | select(.merged_at != null) | {number, title, user: .user.login, html_url, merge_commit_sha, base: .base.ref, merged_at}] | sort_by(.merged_at)"
1052
+ ],
1053
+ { cwd: this.cwd }
1054
+ );
1041
1055
  const prs = JSON.parse(result.stdout);
1042
1056
  if (!isArray(prs) || prs.length === 0) return null;
1043
1057
  const defaultBranch = await this.detectDefaultBranch();
@@ -1063,7 +1077,7 @@ var GitHubAdapter = class {
1063
1077
  try {
1064
1078
  const result = await gitExec(
1065
1079
  ["symbolic-ref", `refs/remotes/${this.remoteName}/HEAD`],
1066
- {}
1080
+ { cwd: this.cwd }
1067
1081
  );
1068
1082
  const ref = result.stdout.trim();
1069
1083
  this.defaultBranchCache = ref.replace(`refs/remotes/${this.remoteName}/`, "") || "main";
@@ -1074,14 +1088,18 @@ var GitHubAdapter = class {
1074
1088
  }
1075
1089
  async getPRCommits(prNumber) {
1076
1090
  try {
1077
- const result = await shellExec("gh", [
1078
- "api",
1079
- `repos/{owner}/{repo}/pulls/${prNumber}/commits`,
1080
- "--hostname",
1081
- this.hostname,
1082
- "--jq",
1083
- ".[].sha"
1084
- ]);
1091
+ const result = await shellExec(
1092
+ "gh",
1093
+ [
1094
+ "api",
1095
+ `repos/{owner}/{repo}/pulls/${prNumber}/commits`,
1096
+ "--hostname",
1097
+ this.hostname,
1098
+ "--jq",
1099
+ ".[].sha"
1100
+ ],
1101
+ { cwd: this.cwd }
1102
+ );
1085
1103
  return filter(result.stdout.trim().split("\n"), isTruthy);
1086
1104
  } catch {
1087
1105
  return [];
@@ -1089,16 +1107,20 @@ var GitHubAdapter = class {
1089
1107
  }
1090
1108
  async getLinkedIssues(prNumber) {
1091
1109
  try {
1092
- const result = await shellExec("gh", [
1093
- "api",
1094
- "graphql",
1095
- "--hostname",
1096
- this.hostname,
1097
- "-f",
1098
- `query=query { repository(owner: "{owner}", name: "{repo}") { pullRequest(number: ${prNumber}) { closingIssuesReferences(first: 10) { nodes { number title url state labels(first: 5) { nodes { name } } } } } } }`,
1099
- "--jq",
1100
- ".data.repository.pullRequest.closingIssuesReferences.nodes"
1101
- ]);
1110
+ const result = await shellExec(
1111
+ "gh",
1112
+ [
1113
+ "api",
1114
+ "graphql",
1115
+ "--hostname",
1116
+ this.hostname,
1117
+ "-f",
1118
+ `query=query { repository(owner: "{owner}", name: "{repo}") { pullRequest(number: ${prNumber}) { closingIssuesReferences(first: 10) { nodes { number title url state labels(first: 5) { nodes { name } } } } } } }`,
1119
+ "--jq",
1120
+ ".data.repository.pullRequest.closingIssuesReferences.nodes"
1121
+ ],
1122
+ { cwd: this.cwd }
1123
+ );
1102
1124
  const nodes = JSON.parse(result.stdout);
1103
1125
  if (!isArray(nodes)) return [];
1104
1126
  return map2(nodes, (node) => ({
@@ -1117,14 +1139,18 @@ var GitHubAdapter = class {
1117
1139
  }
1118
1140
  async getLinkedPRs(issueNumber) {
1119
1141
  try {
1120
- const result = await shellExec("gh", [
1121
- "api",
1122
- `repos/{owner}/{repo}/issues/${issueNumber}/timeline`,
1123
- "--hostname",
1124
- this.hostname,
1125
- "--jq",
1126
- "[.[] | select(.source.issue.pull_request) | .source.issue] | map({number, title, user: .user.login, html_url, merge_commit_sha: .pull_request.merge_commit_sha, merged_at: .pull_request.merged_at})"
1127
- ]);
1142
+ const result = await shellExec(
1143
+ "gh",
1144
+ [
1145
+ "api",
1146
+ `repos/{owner}/{repo}/issues/${issueNumber}/timeline`,
1147
+ "--hostname",
1148
+ this.hostname,
1149
+ "--jq",
1150
+ "[.[] | select(.source.issue.pull_request) | .source.issue] | map({number, title, user: .user.login, html_url, merge_commit_sha: .pull_request.merge_commit_sha, merged_at: .pull_request.merged_at})"
1151
+ ],
1152
+ { cwd: this.cwd }
1153
+ );
1128
1154
  const prs = JSON.parse(result.stdout);
1129
1155
  if (!isArray(prs)) return [];
1130
1156
  const defaultBranch = await this.detectDefaultBranch();
@@ -1143,14 +1169,18 @@ var GitHubAdapter = class {
1143
1169
  }
1144
1170
  async getRateLimit() {
1145
1171
  try {
1146
- const result = await shellExec("gh", [
1147
- "api",
1148
- "rate_limit",
1149
- "--hostname",
1150
- this.hostname,
1151
- "--jq",
1152
- ".rate | {limit, remaining, reset}"
1153
- ]);
1172
+ const result = await shellExec(
1173
+ "gh",
1174
+ [
1175
+ "api",
1176
+ "rate_limit",
1177
+ "--hostname",
1178
+ this.hostname,
1179
+ "--jq",
1180
+ ".rate | {limit, remaining, reset}"
1181
+ ],
1182
+ { cwd: this.cwd }
1183
+ );
1154
1184
  const data = JSON.parse(result.stdout);
1155
1185
  const info = {
1156
1186
  limit: data.limit ?? 5e3,
@@ -1172,7 +1202,8 @@ var GitHubEnterpriseAdapter = class extends GitHubAdapter {
1172
1202
  super({
1173
1203
  hostname,
1174
1204
  scheduler: options?.scheduler,
1175
- remoteName: options?.remoteName
1205
+ remoteName: options?.remoteName,
1206
+ cwd: options?.cwd
1176
1207
  });
1177
1208
  }
1178
1209
  };
@@ -1186,10 +1217,12 @@ var GitLabAdapter = class {
1186
1217
  hostname;
1187
1218
  defaultBranchCache = null;
1188
1219
  remoteName;
1220
+ cwd;
1189
1221
  constructor(options) {
1190
1222
  this.hostname = options?.hostname ?? "gitlab.com";
1191
1223
  this.scheduler = options?.scheduler ?? new RequestScheduler();
1192
1224
  this.remoteName = options?.remoteName ?? "origin";
1225
+ this.cwd = options?.cwd;
1193
1226
  }
1194
1227
  async checkAuth() {
1195
1228
  if (process.env.GITLAB_TOKEN) {
@@ -1199,7 +1232,7 @@ var GitLabAdapter = class {
1199
1232
  const result = await shellExec(
1200
1233
  "glab",
1201
1234
  ["auth", "status", "--hostname", this.hostname],
1202
- { allowExitCodes: [1] }
1235
+ { cwd: this.cwd, allowExitCodes: [1] }
1203
1236
  );
1204
1237
  return {
1205
1238
  authenticated: result.exitCode === 0,
@@ -1212,12 +1245,16 @@ var GitLabAdapter = class {
1212
1245
  async getPRForCommit(sha) {
1213
1246
  if (this.scheduler.isRateLimited()) return null;
1214
1247
  try {
1215
- const result = await shellExec("glab", [
1216
- "api",
1217
- `projects/:id/repository/commits/${sha}/merge_requests`,
1218
- "--hostname",
1219
- this.hostname
1220
- ]);
1248
+ const result = await shellExec(
1249
+ "glab",
1250
+ [
1251
+ "api",
1252
+ `projects/:id/repository/commits/${sha}/merge_requests`,
1253
+ "--hostname",
1254
+ this.hostname
1255
+ ],
1256
+ { cwd: this.cwd }
1257
+ );
1221
1258
  const mrs = JSON.parse(result.stdout);
1222
1259
  if (!isArray2(mrs) || mrs.length === 0) return null;
1223
1260
  const mergedMRs = filter2(
@@ -1252,7 +1289,7 @@ var GitLabAdapter = class {
1252
1289
  try {
1253
1290
  const result = await gitExec(
1254
1291
  ["symbolic-ref", `refs/remotes/${this.remoteName}/HEAD`],
1255
- {}
1292
+ { cwd: this.cwd }
1256
1293
  );
1257
1294
  const ref = result.stdout.trim();
1258
1295
  this.defaultBranchCache = ref.replace(`refs/remotes/${this.remoteName}/`, "") || "main";
@@ -1263,12 +1300,16 @@ var GitLabAdapter = class {
1263
1300
  }
1264
1301
  async getPRCommits(prNumber) {
1265
1302
  try {
1266
- const result = await shellExec("glab", [
1267
- "api",
1268
- `projects/:id/merge_requests/${prNumber}/commits`,
1269
- "--hostname",
1270
- this.hostname
1271
- ]);
1303
+ const result = await shellExec(
1304
+ "glab",
1305
+ [
1306
+ "api",
1307
+ `projects/:id/merge_requests/${prNumber}/commits`,
1308
+ "--hostname",
1309
+ this.hostname
1310
+ ],
1311
+ { cwd: this.cwd }
1312
+ );
1272
1313
  const commits = JSON.parse(result.stdout);
1273
1314
  if (!isArray2(commits)) return [];
1274
1315
  return map3(commits, (c) => c.id);
@@ -1278,12 +1319,16 @@ var GitLabAdapter = class {
1278
1319
  }
1279
1320
  async getLinkedIssues(prNumber) {
1280
1321
  try {
1281
- const result = await shellExec("glab", [
1282
- "api",
1283
- `projects/:id/merge_requests/${prNumber}/closes_issues`,
1284
- "--hostname",
1285
- this.hostname
1286
- ]);
1322
+ const result = await shellExec(
1323
+ "glab",
1324
+ [
1325
+ "api",
1326
+ `projects/:id/merge_requests/${prNumber}/closes_issues`,
1327
+ "--hostname",
1328
+ this.hostname
1329
+ ],
1330
+ { cwd: this.cwd }
1331
+ );
1287
1332
  const issues = JSON.parse(result.stdout);
1288
1333
  if (!isArray2(issues)) return [];
1289
1334
  return map3(issues, (issue) => ({
@@ -1299,12 +1344,16 @@ var GitLabAdapter = class {
1299
1344
  }
1300
1345
  async getLinkedPRs(issueNumber) {
1301
1346
  try {
1302
- const result = await shellExec("glab", [
1303
- "api",
1304
- `projects/:id/issues/${issueNumber}/related_merge_requests`,
1305
- "--hostname",
1306
- this.hostname
1307
- ]);
1347
+ const result = await shellExec(
1348
+ "glab",
1349
+ [
1350
+ "api",
1351
+ `projects/:id/issues/${issueNumber}/related_merge_requests`,
1352
+ "--hostname",
1353
+ this.hostname
1354
+ ],
1355
+ { cwd: this.cwd }
1356
+ );
1308
1357
  const mrs = JSON.parse(result.stdout);
1309
1358
  if (!isArray2(mrs)) return [];
1310
1359
  const defaultBranch = await this.detectDefaultBranch();
@@ -1333,7 +1382,8 @@ var GitLabSelfHostedAdapter = class extends GitLabAdapter {
1333
1382
  super({
1334
1383
  hostname,
1335
1384
  scheduler: options?.scheduler,
1336
- remoteName: options?.remoteName
1385
+ remoteName: options?.remoteName,
1386
+ cwd: options?.cwd
1337
1387
  });
1338
1388
  }
1339
1389
  };
@@ -1343,21 +1393,21 @@ async function detectPlatformAdapter(options) {
1343
1393
  const remote = await getRemoteInfo(options?.remoteName, {
1344
1394
  cwd: options?.cwd
1345
1395
  });
1346
- const adapter = createAdapter(remote, options?.remoteName);
1396
+ const adapter = createAdapter(remote, options?.remoteName, options?.cwd);
1347
1397
  return { adapter, remote };
1348
1398
  }
1349
- function createAdapter(remote, remoteName) {
1399
+ function createAdapter(remote, remoteName, cwd) {
1350
1400
  switch (remote.platform) {
1351
1401
  case "github":
1352
- return new GitHubAdapter({ hostname: remote.host, remoteName });
1402
+ return new GitHubAdapter({ hostname: remote.host, remoteName, cwd });
1353
1403
  case "github-enterprise":
1354
- return new GitHubEnterpriseAdapter(remote.host, { remoteName });
1404
+ return new GitHubEnterpriseAdapter(remote.host, { remoteName, cwd });
1355
1405
  case "gitlab":
1356
- return new GitLabAdapter({ hostname: remote.host, remoteName });
1406
+ return new GitLabAdapter({ hostname: remote.host, remoteName, cwd });
1357
1407
  case "gitlab-self-hosted":
1358
- return new GitLabSelfHostedAdapter(remote.host, { remoteName });
1408
+ return new GitLabSelfHostedAdapter(remote.host, { remoteName, cwd });
1359
1409
  case "unknown":
1360
- return new GitHubEnterpriseAdapter(remote.host, { remoteName });
1410
+ return new GitHubEnterpriseAdapter(remote.host, { remoteName, cwd });
1361
1411
  }
1362
1412
  }
1363
1413
 
package/dist/index.cjs CHANGED
@@ -218,9 +218,7 @@ var init_sharded_cache = __esm({
218
218
  data[key] = { key, value, createdAt: Date.now() };
219
219
  const keys = Object.keys(data);
220
220
  if (keys.length > this.maxEntriesPerShard) {
221
- const sorted = keys.sort(
222
- (a, b) => data[a].createdAt - data[b].createdAt
223
- );
221
+ const sorted = keys.sort((a, b) => data[a].createdAt - data[b].createdAt);
224
222
  const toRemove = sorted.slice(0, keys.length - this.maxEntriesPerShard);
225
223
  for (const k of toRemove) {
226
224
  delete data[k];
@@ -424,7 +422,9 @@ function getCache(repoId, noCache) {
424
422
  if (noCache) {
425
423
  return new ShardedCache("patch-id", { repoId, enabled: false });
426
424
  }
427
- const key = repoKey(repoId ?? { host: "_local", owner: "_", repo: "_default" });
425
+ const key = repoKey(
426
+ repoId ?? { host: "_local", owner: "_", repo: "_default" }
427
+ );
428
428
  let cache = cacheRegistry.get(key);
429
429
  if (!cache) {
430
430
  cache = new ShardedCache("patch-id", { repoId });
@@ -515,7 +515,9 @@ function getCache2(repoId, noCache) {
515
515
  if (noCache) {
516
516
  return new ShardedCache("pr", { repoId, enabled: false });
517
517
  }
518
- const key = repoKey2(repoId ?? { host: "_local", owner: "_", repo: "_default" });
518
+ const key = repoKey2(
519
+ repoId ?? { host: "_local", owner: "_", repo: "_default" }
520
+ );
519
521
  let cache = cacheRegistry2.get(key);
520
522
  if (!cache) {
521
523
  cache = new ShardedCache("pr", { repoId });
@@ -625,9 +627,8 @@ init_errors();
625
627
 
626
628
  // src/core/core.ts
627
629
  init_cjs_shims();
628
- var import_common_utils11 = require("@winglet/common-utils");
629
630
  var import_node_crypto2 = require("crypto");
630
- init_cache();
631
+ var import_common_utils11 = require("@winglet/common-utils");
631
632
 
632
633
  // src/ast/index.ts
633
634
  init_cjs_shims();
@@ -838,7 +839,9 @@ function findPythonBlockEnd(lines, startIdx) {
838
839
  }
839
840
 
840
841
  // src/core/core.ts
842
+ init_cache();
841
843
  init_errors();
844
+ init_executor();
842
845
 
843
846
  // src/git/health.ts
844
847
  init_cjs_shims();
@@ -887,9 +890,6 @@ async function checkGitHealth(options) {
887
890
  return { commitGraph, bloomFilter, gitVersion, hints };
888
891
  }
889
892
 
890
- // src/core/core.ts
891
- init_executor();
892
-
893
893
  // src/platform/index.ts
894
894
  init_cjs_shims();
895
895
 
@@ -969,10 +969,12 @@ var GitHubAdapter = class {
969
969
  hostname;
970
970
  defaultBranchCache = null;
971
971
  remoteName;
972
+ cwd;
972
973
  constructor(options) {
973
974
  this.hostname = options?.hostname ?? "github.com";
974
975
  this.scheduler = options?.scheduler ?? new RequestScheduler();
975
976
  this.remoteName = options?.remoteName ?? "origin";
977
+ this.cwd = options?.cwd;
976
978
  }
977
979
  async checkAuth() {
978
980
  try {
@@ -980,6 +982,7 @@ var GitHubAdapter = class {
980
982
  "gh",
981
983
  ["auth", "token", "--hostname", this.hostname],
982
984
  {
985
+ cwd: this.cwd,
983
986
  allowExitCodes: [1]
984
987
  }
985
988
  );
@@ -995,14 +998,18 @@ var GitHubAdapter = class {
995
998
  async getPRForCommit(sha) {
996
999
  if (this.scheduler.isRateLimited()) return null;
997
1000
  try {
998
- const result = await shellExec("gh", [
999
- "api",
1000
- `repos/{owner}/{repo}/commits/${sha}/pulls`,
1001
- "--hostname",
1002
- this.hostname,
1003
- "--jq",
1004
- "[.[] | select(.merged_at != null) | {number, title, user: .user.login, html_url, merge_commit_sha, base: .base.ref, merged_at}] | sort_by(.merged_at)"
1005
- ]);
1001
+ const result = await shellExec(
1002
+ "gh",
1003
+ [
1004
+ "api",
1005
+ `repos/{owner}/{repo}/commits/${sha}/pulls`,
1006
+ "--hostname",
1007
+ this.hostname,
1008
+ "--jq",
1009
+ "[.[] | select(.merged_at != null) | {number, title, user: .user.login, html_url, merge_commit_sha, base: .base.ref, merged_at}] | sort_by(.merged_at)"
1010
+ ],
1011
+ { cwd: this.cwd }
1012
+ );
1006
1013
  const prs = JSON.parse(result.stdout);
1007
1014
  if (!(0, import_common_utils3.isArray)(prs) || prs.length === 0) return null;
1008
1015
  const defaultBranch = await this.detectDefaultBranch();
@@ -1028,7 +1035,7 @@ var GitHubAdapter = class {
1028
1035
  try {
1029
1036
  const result = await gitExec(
1030
1037
  ["symbolic-ref", `refs/remotes/${this.remoteName}/HEAD`],
1031
- {}
1038
+ { cwd: this.cwd }
1032
1039
  );
1033
1040
  const ref = result.stdout.trim();
1034
1041
  this.defaultBranchCache = ref.replace(`refs/remotes/${this.remoteName}/`, "") || "main";
@@ -1039,14 +1046,18 @@ var GitHubAdapter = class {
1039
1046
  }
1040
1047
  async getPRCommits(prNumber) {
1041
1048
  try {
1042
- const result = await shellExec("gh", [
1043
- "api",
1044
- `repos/{owner}/{repo}/pulls/${prNumber}/commits`,
1045
- "--hostname",
1046
- this.hostname,
1047
- "--jq",
1048
- ".[].sha"
1049
- ]);
1049
+ const result = await shellExec(
1050
+ "gh",
1051
+ [
1052
+ "api",
1053
+ `repos/{owner}/{repo}/pulls/${prNumber}/commits`,
1054
+ "--hostname",
1055
+ this.hostname,
1056
+ "--jq",
1057
+ ".[].sha"
1058
+ ],
1059
+ { cwd: this.cwd }
1060
+ );
1050
1061
  return (0, import_common_utils3.filter)(result.stdout.trim().split("\n"), import_common_utils3.isTruthy);
1051
1062
  } catch {
1052
1063
  return [];
@@ -1054,16 +1065,20 @@ var GitHubAdapter = class {
1054
1065
  }
1055
1066
  async getLinkedIssues(prNumber) {
1056
1067
  try {
1057
- const result = await shellExec("gh", [
1058
- "api",
1059
- "graphql",
1060
- "--hostname",
1061
- this.hostname,
1062
- "-f",
1063
- `query=query { repository(owner: "{owner}", name: "{repo}") { pullRequest(number: ${prNumber}) { closingIssuesReferences(first: 10) { nodes { number title url state labels(first: 5) { nodes { name } } } } } } }`,
1064
- "--jq",
1065
- ".data.repository.pullRequest.closingIssuesReferences.nodes"
1066
- ]);
1068
+ const result = await shellExec(
1069
+ "gh",
1070
+ [
1071
+ "api",
1072
+ "graphql",
1073
+ "--hostname",
1074
+ this.hostname,
1075
+ "-f",
1076
+ `query=query { repository(owner: "{owner}", name: "{repo}") { pullRequest(number: ${prNumber}) { closingIssuesReferences(first: 10) { nodes { number title url state labels(first: 5) { nodes { name } } } } } } }`,
1077
+ "--jq",
1078
+ ".data.repository.pullRequest.closingIssuesReferences.nodes"
1079
+ ],
1080
+ { cwd: this.cwd }
1081
+ );
1067
1082
  const nodes = JSON.parse(result.stdout);
1068
1083
  if (!(0, import_common_utils3.isArray)(nodes)) return [];
1069
1084
  return (0, import_common_utils3.map)(nodes, (node) => ({
@@ -1082,14 +1097,18 @@ var GitHubAdapter = class {
1082
1097
  }
1083
1098
  async getLinkedPRs(issueNumber) {
1084
1099
  try {
1085
- const result = await shellExec("gh", [
1086
- "api",
1087
- `repos/{owner}/{repo}/issues/${issueNumber}/timeline`,
1088
- "--hostname",
1089
- this.hostname,
1090
- "--jq",
1091
- "[.[] | select(.source.issue.pull_request) | .source.issue] | map({number, title, user: .user.login, html_url, merge_commit_sha: .pull_request.merge_commit_sha, merged_at: .pull_request.merged_at})"
1092
- ]);
1100
+ const result = await shellExec(
1101
+ "gh",
1102
+ [
1103
+ "api",
1104
+ `repos/{owner}/{repo}/issues/${issueNumber}/timeline`,
1105
+ "--hostname",
1106
+ this.hostname,
1107
+ "--jq",
1108
+ "[.[] | select(.source.issue.pull_request) | .source.issue] | map({number, title, user: .user.login, html_url, merge_commit_sha: .pull_request.merge_commit_sha, merged_at: .pull_request.merged_at})"
1109
+ ],
1110
+ { cwd: this.cwd }
1111
+ );
1093
1112
  const prs = JSON.parse(result.stdout);
1094
1113
  if (!(0, import_common_utils3.isArray)(prs)) return [];
1095
1114
  const defaultBranch = await this.detectDefaultBranch();
@@ -1108,14 +1127,18 @@ var GitHubAdapter = class {
1108
1127
  }
1109
1128
  async getRateLimit() {
1110
1129
  try {
1111
- const result = await shellExec("gh", [
1112
- "api",
1113
- "rate_limit",
1114
- "--hostname",
1115
- this.hostname,
1116
- "--jq",
1117
- ".rate | {limit, remaining, reset}"
1118
- ]);
1130
+ const result = await shellExec(
1131
+ "gh",
1132
+ [
1133
+ "api",
1134
+ "rate_limit",
1135
+ "--hostname",
1136
+ this.hostname,
1137
+ "--jq",
1138
+ ".rate | {limit, remaining, reset}"
1139
+ ],
1140
+ { cwd: this.cwd }
1141
+ );
1119
1142
  const data = JSON.parse(result.stdout);
1120
1143
  const info = {
1121
1144
  limit: data.limit ?? 5e3,
@@ -1138,7 +1161,8 @@ var GitHubEnterpriseAdapter = class extends GitHubAdapter {
1138
1161
  super({
1139
1162
  hostname,
1140
1163
  scheduler: options?.scheduler,
1141
- remoteName: options?.remoteName
1164
+ remoteName: options?.remoteName,
1165
+ cwd: options?.cwd
1142
1166
  });
1143
1167
  }
1144
1168
  };
@@ -1156,10 +1180,12 @@ var GitLabAdapter = class {
1156
1180
  hostname;
1157
1181
  defaultBranchCache = null;
1158
1182
  remoteName;
1183
+ cwd;
1159
1184
  constructor(options) {
1160
1185
  this.hostname = options?.hostname ?? "gitlab.com";
1161
1186
  this.scheduler = options?.scheduler ?? new RequestScheduler();
1162
1187
  this.remoteName = options?.remoteName ?? "origin";
1188
+ this.cwd = options?.cwd;
1163
1189
  }
1164
1190
  async checkAuth() {
1165
1191
  if (process.env.GITLAB_TOKEN) {
@@ -1169,7 +1195,7 @@ var GitLabAdapter = class {
1169
1195
  const result = await shellExec(
1170
1196
  "glab",
1171
1197
  ["auth", "status", "--hostname", this.hostname],
1172
- { allowExitCodes: [1] }
1198
+ { cwd: this.cwd, allowExitCodes: [1] }
1173
1199
  );
1174
1200
  return {
1175
1201
  authenticated: result.exitCode === 0,
@@ -1182,12 +1208,16 @@ var GitLabAdapter = class {
1182
1208
  async getPRForCommit(sha) {
1183
1209
  if (this.scheduler.isRateLimited()) return null;
1184
1210
  try {
1185
- const result = await shellExec("glab", [
1186
- "api",
1187
- `projects/:id/repository/commits/${sha}/merge_requests`,
1188
- "--hostname",
1189
- this.hostname
1190
- ]);
1211
+ const result = await shellExec(
1212
+ "glab",
1213
+ [
1214
+ "api",
1215
+ `projects/:id/repository/commits/${sha}/merge_requests`,
1216
+ "--hostname",
1217
+ this.hostname
1218
+ ],
1219
+ { cwd: this.cwd }
1220
+ );
1191
1221
  const mrs = JSON.parse(result.stdout);
1192
1222
  if (!(0, import_common_utils4.isArray)(mrs) || mrs.length === 0) return null;
1193
1223
  const mergedMRs = (0, import_common_utils4.filter)(
@@ -1222,7 +1252,7 @@ var GitLabAdapter = class {
1222
1252
  try {
1223
1253
  const result = await gitExec(
1224
1254
  ["symbolic-ref", `refs/remotes/${this.remoteName}/HEAD`],
1225
- {}
1255
+ { cwd: this.cwd }
1226
1256
  );
1227
1257
  const ref = result.stdout.trim();
1228
1258
  this.defaultBranchCache = ref.replace(`refs/remotes/${this.remoteName}/`, "") || "main";
@@ -1233,12 +1263,16 @@ var GitLabAdapter = class {
1233
1263
  }
1234
1264
  async getPRCommits(prNumber) {
1235
1265
  try {
1236
- const result = await shellExec("glab", [
1237
- "api",
1238
- `projects/:id/merge_requests/${prNumber}/commits`,
1239
- "--hostname",
1240
- this.hostname
1241
- ]);
1266
+ const result = await shellExec(
1267
+ "glab",
1268
+ [
1269
+ "api",
1270
+ `projects/:id/merge_requests/${prNumber}/commits`,
1271
+ "--hostname",
1272
+ this.hostname
1273
+ ],
1274
+ { cwd: this.cwd }
1275
+ );
1242
1276
  const commits = JSON.parse(result.stdout);
1243
1277
  if (!(0, import_common_utils4.isArray)(commits)) return [];
1244
1278
  return (0, import_common_utils4.map)(commits, (c) => c.id);
@@ -1248,12 +1282,16 @@ var GitLabAdapter = class {
1248
1282
  }
1249
1283
  async getLinkedIssues(prNumber) {
1250
1284
  try {
1251
- const result = await shellExec("glab", [
1252
- "api",
1253
- `projects/:id/merge_requests/${prNumber}/closes_issues`,
1254
- "--hostname",
1255
- this.hostname
1256
- ]);
1285
+ const result = await shellExec(
1286
+ "glab",
1287
+ [
1288
+ "api",
1289
+ `projects/:id/merge_requests/${prNumber}/closes_issues`,
1290
+ "--hostname",
1291
+ this.hostname
1292
+ ],
1293
+ { cwd: this.cwd }
1294
+ );
1257
1295
  const issues = JSON.parse(result.stdout);
1258
1296
  if (!(0, import_common_utils4.isArray)(issues)) return [];
1259
1297
  return (0, import_common_utils4.map)(issues, (issue) => ({
@@ -1269,12 +1307,16 @@ var GitLabAdapter = class {
1269
1307
  }
1270
1308
  async getLinkedPRs(issueNumber) {
1271
1309
  try {
1272
- const result = await shellExec("glab", [
1273
- "api",
1274
- `projects/:id/issues/${issueNumber}/related_merge_requests`,
1275
- "--hostname",
1276
- this.hostname
1277
- ]);
1310
+ const result = await shellExec(
1311
+ "glab",
1312
+ [
1313
+ "api",
1314
+ `projects/:id/issues/${issueNumber}/related_merge_requests`,
1315
+ "--hostname",
1316
+ this.hostname
1317
+ ],
1318
+ { cwd: this.cwd }
1319
+ );
1278
1320
  const mrs = JSON.parse(result.stdout);
1279
1321
  if (!(0, import_common_utils4.isArray)(mrs)) return [];
1280
1322
  const defaultBranch = await this.detectDefaultBranch();
@@ -1304,7 +1346,8 @@ var GitLabSelfHostedAdapter = class extends GitLabAdapter {
1304
1346
  super({
1305
1347
  hostname,
1306
1348
  scheduler: options?.scheduler,
1307
- remoteName: options?.remoteName
1349
+ remoteName: options?.remoteName,
1350
+ cwd: options?.cwd
1308
1351
  });
1309
1352
  }
1310
1353
  };
@@ -1314,21 +1357,21 @@ async function detectPlatformAdapter(options) {
1314
1357
  const remote = await getRemoteInfo(options?.remoteName, {
1315
1358
  cwd: options?.cwd
1316
1359
  });
1317
- const adapter = createAdapter(remote, options?.remoteName);
1360
+ const adapter = createAdapter(remote, options?.remoteName, options?.cwd);
1318
1361
  return { adapter, remote };
1319
1362
  }
1320
- function createAdapter(remote, remoteName) {
1363
+ function createAdapter(remote, remoteName, cwd) {
1321
1364
  switch (remote.platform) {
1322
1365
  case "github":
1323
- return new GitHubAdapter({ hostname: remote.host, remoteName });
1366
+ return new GitHubAdapter({ hostname: remote.host, remoteName, cwd });
1324
1367
  case "github-enterprise":
1325
- return new GitHubEnterpriseAdapter(remote.host, { remoteName });
1368
+ return new GitHubEnterpriseAdapter(remote.host, { remoteName, cwd });
1326
1369
  case "gitlab":
1327
- return new GitLabAdapter({ hostname: remote.host, remoteName });
1370
+ return new GitLabAdapter({ hostname: remote.host, remoteName, cwd });
1328
1371
  case "gitlab-self-hosted":
1329
- return new GitLabSelfHostedAdapter(remote.host, { remoteName });
1372
+ return new GitLabSelfHostedAdapter(remote.host, { remoteName, cwd });
1330
1373
  case "unknown":
1331
- return new GitHubEnterpriseAdapter(remote.host, { remoteName });
1374
+ return new GitHubEnterpriseAdapter(remote.host, { remoteName, cwd });
1332
1375
  }
1333
1376
  }
1334
1377
 
package/dist/index.mjs CHANGED
@@ -70,7 +70,14 @@ var init_errors = __esm({
70
70
  });
71
71
 
72
72
  // src/cache/sharded-cache.ts
73
- import { mkdir, readFile, readdir, rename, rm, writeFile } from "fs/promises";
73
+ import {
74
+ mkdir,
75
+ readFile,
76
+ readdir,
77
+ rename,
78
+ rm,
79
+ writeFile
80
+ } from "fs/promises";
74
81
  import { homedir } from "os";
75
82
  import { join } from "path";
76
83
  function getShardPrefix(key) {
@@ -198,9 +205,7 @@ var init_sharded_cache = __esm({
198
205
  data[key] = { key, value, createdAt: Date.now() };
199
206
  const keys = Object.keys(data);
200
207
  if (keys.length > this.maxEntriesPerShard) {
201
- const sorted = keys.sort(
202
- (a, b) => data[a].createdAt - data[b].createdAt
203
- );
208
+ const sorted = keys.sort((a, b) => data[a].createdAt - data[b].createdAt);
204
209
  const toRemove = sorted.slice(0, keys.length - this.maxEntriesPerShard);
205
210
  for (const k of toRemove) {
206
211
  delete data[k];
@@ -403,7 +408,9 @@ function getCache(repoId, noCache) {
403
408
  if (noCache) {
404
409
  return new ShardedCache("patch-id", { repoId, enabled: false });
405
410
  }
406
- const key = repoKey(repoId ?? { host: "_local", owner: "_", repo: "_default" });
411
+ const key = repoKey(
412
+ repoId ?? { host: "_local", owner: "_", repo: "_default" }
413
+ );
407
414
  let cache = cacheRegistry.get(key);
408
415
  if (!cache) {
409
416
  cache = new ShardedCache("patch-id", { repoId });
@@ -493,7 +500,9 @@ function getCache2(repoId, noCache) {
493
500
  if (noCache) {
494
501
  return new ShardedCache("pr", { repoId, enabled: false });
495
502
  }
496
- const key = repoKey2(repoId ?? { host: "_local", owner: "_", repo: "_default" });
503
+ const key = repoKey2(
504
+ repoId ?? { host: "_local", owner: "_", repo: "_default" }
505
+ );
497
506
  let cache = cacheRegistry2.get(key);
498
507
  if (!cache) {
499
508
  cache = new ShardedCache("pr", { repoId });
@@ -592,9 +601,8 @@ init_errors();
592
601
 
593
602
  // src/core/core.ts
594
603
  init_esm_shims();
595
- init_cache();
596
- import { map as map8 } from "@winglet/common-utils";
597
604
  import { createHash as createHash2 } from "crypto";
605
+ import { map as map8 } from "@winglet/common-utils";
598
606
 
599
607
  // src/ast/index.ts
600
608
  init_esm_shims();
@@ -805,7 +813,9 @@ function findPythonBlockEnd(lines, startIdx) {
805
813
  }
806
814
 
807
815
  // src/core/core.ts
816
+ init_cache();
808
817
  init_errors();
818
+ init_executor();
809
819
 
810
820
  // src/git/health.ts
811
821
  init_esm_shims();
@@ -854,9 +864,6 @@ async function checkGitHealth(options) {
854
864
  return { commitGraph, bloomFilter, gitVersion, hints };
855
865
  }
856
866
 
857
- // src/core/core.ts
858
- init_executor();
859
-
860
867
  // src/platform/index.ts
861
868
  init_esm_shims();
862
869
 
@@ -936,10 +943,12 @@ var GitHubAdapter = class {
936
943
  hostname;
937
944
  defaultBranchCache = null;
938
945
  remoteName;
946
+ cwd;
939
947
  constructor(options) {
940
948
  this.hostname = options?.hostname ?? "github.com";
941
949
  this.scheduler = options?.scheduler ?? new RequestScheduler();
942
950
  this.remoteName = options?.remoteName ?? "origin";
951
+ this.cwd = options?.cwd;
943
952
  }
944
953
  async checkAuth() {
945
954
  try {
@@ -947,6 +956,7 @@ var GitHubAdapter = class {
947
956
  "gh",
948
957
  ["auth", "token", "--hostname", this.hostname],
949
958
  {
959
+ cwd: this.cwd,
950
960
  allowExitCodes: [1]
951
961
  }
952
962
  );
@@ -962,14 +972,18 @@ var GitHubAdapter = class {
962
972
  async getPRForCommit(sha) {
963
973
  if (this.scheduler.isRateLimited()) return null;
964
974
  try {
965
- const result = await shellExec("gh", [
966
- "api",
967
- `repos/{owner}/{repo}/commits/${sha}/pulls`,
968
- "--hostname",
969
- this.hostname,
970
- "--jq",
971
- "[.[] | select(.merged_at != null) | {number, title, user: .user.login, html_url, merge_commit_sha, base: .base.ref, merged_at}] | sort_by(.merged_at)"
972
- ]);
975
+ const result = await shellExec(
976
+ "gh",
977
+ [
978
+ "api",
979
+ `repos/{owner}/{repo}/commits/${sha}/pulls`,
980
+ "--hostname",
981
+ this.hostname,
982
+ "--jq",
983
+ "[.[] | select(.merged_at != null) | {number, title, user: .user.login, html_url, merge_commit_sha, base: .base.ref, merged_at}] | sort_by(.merged_at)"
984
+ ],
985
+ { cwd: this.cwd }
986
+ );
973
987
  const prs = JSON.parse(result.stdout);
974
988
  if (!isArray(prs) || prs.length === 0) return null;
975
989
  const defaultBranch = await this.detectDefaultBranch();
@@ -995,7 +1009,7 @@ var GitHubAdapter = class {
995
1009
  try {
996
1010
  const result = await gitExec(
997
1011
  ["symbolic-ref", `refs/remotes/${this.remoteName}/HEAD`],
998
- {}
1012
+ { cwd: this.cwd }
999
1013
  );
1000
1014
  const ref = result.stdout.trim();
1001
1015
  this.defaultBranchCache = ref.replace(`refs/remotes/${this.remoteName}/`, "") || "main";
@@ -1006,14 +1020,18 @@ var GitHubAdapter = class {
1006
1020
  }
1007
1021
  async getPRCommits(prNumber) {
1008
1022
  try {
1009
- const result = await shellExec("gh", [
1010
- "api",
1011
- `repos/{owner}/{repo}/pulls/${prNumber}/commits`,
1012
- "--hostname",
1013
- this.hostname,
1014
- "--jq",
1015
- ".[].sha"
1016
- ]);
1023
+ const result = await shellExec(
1024
+ "gh",
1025
+ [
1026
+ "api",
1027
+ `repos/{owner}/{repo}/pulls/${prNumber}/commits`,
1028
+ "--hostname",
1029
+ this.hostname,
1030
+ "--jq",
1031
+ ".[].sha"
1032
+ ],
1033
+ { cwd: this.cwd }
1034
+ );
1017
1035
  return filter(result.stdout.trim().split("\n"), isTruthy);
1018
1036
  } catch {
1019
1037
  return [];
@@ -1021,16 +1039,20 @@ var GitHubAdapter = class {
1021
1039
  }
1022
1040
  async getLinkedIssues(prNumber) {
1023
1041
  try {
1024
- const result = await shellExec("gh", [
1025
- "api",
1026
- "graphql",
1027
- "--hostname",
1028
- this.hostname,
1029
- "-f",
1030
- `query=query { repository(owner: "{owner}", name: "{repo}") { pullRequest(number: ${prNumber}) { closingIssuesReferences(first: 10) { nodes { number title url state labels(first: 5) { nodes { name } } } } } } }`,
1031
- "--jq",
1032
- ".data.repository.pullRequest.closingIssuesReferences.nodes"
1033
- ]);
1042
+ const result = await shellExec(
1043
+ "gh",
1044
+ [
1045
+ "api",
1046
+ "graphql",
1047
+ "--hostname",
1048
+ this.hostname,
1049
+ "-f",
1050
+ `query=query { repository(owner: "{owner}", name: "{repo}") { pullRequest(number: ${prNumber}) { closingIssuesReferences(first: 10) { nodes { number title url state labels(first: 5) { nodes { name } } } } } } }`,
1051
+ "--jq",
1052
+ ".data.repository.pullRequest.closingIssuesReferences.nodes"
1053
+ ],
1054
+ { cwd: this.cwd }
1055
+ );
1034
1056
  const nodes = JSON.parse(result.stdout);
1035
1057
  if (!isArray(nodes)) return [];
1036
1058
  return map2(nodes, (node) => ({
@@ -1049,14 +1071,18 @@ var GitHubAdapter = class {
1049
1071
  }
1050
1072
  async getLinkedPRs(issueNumber) {
1051
1073
  try {
1052
- const result = await shellExec("gh", [
1053
- "api",
1054
- `repos/{owner}/{repo}/issues/${issueNumber}/timeline`,
1055
- "--hostname",
1056
- this.hostname,
1057
- "--jq",
1058
- "[.[] | select(.source.issue.pull_request) | .source.issue] | map({number, title, user: .user.login, html_url, merge_commit_sha: .pull_request.merge_commit_sha, merged_at: .pull_request.merged_at})"
1059
- ]);
1074
+ const result = await shellExec(
1075
+ "gh",
1076
+ [
1077
+ "api",
1078
+ `repos/{owner}/{repo}/issues/${issueNumber}/timeline`,
1079
+ "--hostname",
1080
+ this.hostname,
1081
+ "--jq",
1082
+ "[.[] | select(.source.issue.pull_request) | .source.issue] | map({number, title, user: .user.login, html_url, merge_commit_sha: .pull_request.merge_commit_sha, merged_at: .pull_request.merged_at})"
1083
+ ],
1084
+ { cwd: this.cwd }
1085
+ );
1060
1086
  const prs = JSON.parse(result.stdout);
1061
1087
  if (!isArray(prs)) return [];
1062
1088
  const defaultBranch = await this.detectDefaultBranch();
@@ -1075,14 +1101,18 @@ var GitHubAdapter = class {
1075
1101
  }
1076
1102
  async getRateLimit() {
1077
1103
  try {
1078
- const result = await shellExec("gh", [
1079
- "api",
1080
- "rate_limit",
1081
- "--hostname",
1082
- this.hostname,
1083
- "--jq",
1084
- ".rate | {limit, remaining, reset}"
1085
- ]);
1104
+ const result = await shellExec(
1105
+ "gh",
1106
+ [
1107
+ "api",
1108
+ "rate_limit",
1109
+ "--hostname",
1110
+ this.hostname,
1111
+ "--jq",
1112
+ ".rate | {limit, remaining, reset}"
1113
+ ],
1114
+ { cwd: this.cwd }
1115
+ );
1086
1116
  const data = JSON.parse(result.stdout);
1087
1117
  const info = {
1088
1118
  limit: data.limit ?? 5e3,
@@ -1105,7 +1135,8 @@ var GitHubEnterpriseAdapter = class extends GitHubAdapter {
1105
1135
  super({
1106
1136
  hostname,
1107
1137
  scheduler: options?.scheduler,
1108
- remoteName: options?.remoteName
1138
+ remoteName: options?.remoteName,
1139
+ cwd: options?.cwd
1109
1140
  });
1110
1141
  }
1111
1142
  };
@@ -1123,10 +1154,12 @@ var GitLabAdapter = class {
1123
1154
  hostname;
1124
1155
  defaultBranchCache = null;
1125
1156
  remoteName;
1157
+ cwd;
1126
1158
  constructor(options) {
1127
1159
  this.hostname = options?.hostname ?? "gitlab.com";
1128
1160
  this.scheduler = options?.scheduler ?? new RequestScheduler();
1129
1161
  this.remoteName = options?.remoteName ?? "origin";
1162
+ this.cwd = options?.cwd;
1130
1163
  }
1131
1164
  async checkAuth() {
1132
1165
  if (process.env.GITLAB_TOKEN) {
@@ -1136,7 +1169,7 @@ var GitLabAdapter = class {
1136
1169
  const result = await shellExec(
1137
1170
  "glab",
1138
1171
  ["auth", "status", "--hostname", this.hostname],
1139
- { allowExitCodes: [1] }
1172
+ { cwd: this.cwd, allowExitCodes: [1] }
1140
1173
  );
1141
1174
  return {
1142
1175
  authenticated: result.exitCode === 0,
@@ -1149,12 +1182,16 @@ var GitLabAdapter = class {
1149
1182
  async getPRForCommit(sha) {
1150
1183
  if (this.scheduler.isRateLimited()) return null;
1151
1184
  try {
1152
- const result = await shellExec("glab", [
1153
- "api",
1154
- `projects/:id/repository/commits/${sha}/merge_requests`,
1155
- "--hostname",
1156
- this.hostname
1157
- ]);
1185
+ const result = await shellExec(
1186
+ "glab",
1187
+ [
1188
+ "api",
1189
+ `projects/:id/repository/commits/${sha}/merge_requests`,
1190
+ "--hostname",
1191
+ this.hostname
1192
+ ],
1193
+ { cwd: this.cwd }
1194
+ );
1158
1195
  const mrs = JSON.parse(result.stdout);
1159
1196
  if (!isArray2(mrs) || mrs.length === 0) return null;
1160
1197
  const mergedMRs = filter2(
@@ -1189,7 +1226,7 @@ var GitLabAdapter = class {
1189
1226
  try {
1190
1227
  const result = await gitExec(
1191
1228
  ["symbolic-ref", `refs/remotes/${this.remoteName}/HEAD`],
1192
- {}
1229
+ { cwd: this.cwd }
1193
1230
  );
1194
1231
  const ref = result.stdout.trim();
1195
1232
  this.defaultBranchCache = ref.replace(`refs/remotes/${this.remoteName}/`, "") || "main";
@@ -1200,12 +1237,16 @@ var GitLabAdapter = class {
1200
1237
  }
1201
1238
  async getPRCommits(prNumber) {
1202
1239
  try {
1203
- const result = await shellExec("glab", [
1204
- "api",
1205
- `projects/:id/merge_requests/${prNumber}/commits`,
1206
- "--hostname",
1207
- this.hostname
1208
- ]);
1240
+ const result = await shellExec(
1241
+ "glab",
1242
+ [
1243
+ "api",
1244
+ `projects/:id/merge_requests/${prNumber}/commits`,
1245
+ "--hostname",
1246
+ this.hostname
1247
+ ],
1248
+ { cwd: this.cwd }
1249
+ );
1209
1250
  const commits = JSON.parse(result.stdout);
1210
1251
  if (!isArray2(commits)) return [];
1211
1252
  return map3(commits, (c) => c.id);
@@ -1215,12 +1256,16 @@ var GitLabAdapter = class {
1215
1256
  }
1216
1257
  async getLinkedIssues(prNumber) {
1217
1258
  try {
1218
- const result = await shellExec("glab", [
1219
- "api",
1220
- `projects/:id/merge_requests/${prNumber}/closes_issues`,
1221
- "--hostname",
1222
- this.hostname
1223
- ]);
1259
+ const result = await shellExec(
1260
+ "glab",
1261
+ [
1262
+ "api",
1263
+ `projects/:id/merge_requests/${prNumber}/closes_issues`,
1264
+ "--hostname",
1265
+ this.hostname
1266
+ ],
1267
+ { cwd: this.cwd }
1268
+ );
1224
1269
  const issues = JSON.parse(result.stdout);
1225
1270
  if (!isArray2(issues)) return [];
1226
1271
  return map3(issues, (issue) => ({
@@ -1236,12 +1281,16 @@ var GitLabAdapter = class {
1236
1281
  }
1237
1282
  async getLinkedPRs(issueNumber) {
1238
1283
  try {
1239
- const result = await shellExec("glab", [
1240
- "api",
1241
- `projects/:id/issues/${issueNumber}/related_merge_requests`,
1242
- "--hostname",
1243
- this.hostname
1244
- ]);
1284
+ const result = await shellExec(
1285
+ "glab",
1286
+ [
1287
+ "api",
1288
+ `projects/:id/issues/${issueNumber}/related_merge_requests`,
1289
+ "--hostname",
1290
+ this.hostname
1291
+ ],
1292
+ { cwd: this.cwd }
1293
+ );
1245
1294
  const mrs = JSON.parse(result.stdout);
1246
1295
  if (!isArray2(mrs)) return [];
1247
1296
  const defaultBranch = await this.detectDefaultBranch();
@@ -1271,7 +1320,8 @@ var GitLabSelfHostedAdapter = class extends GitLabAdapter {
1271
1320
  super({
1272
1321
  hostname,
1273
1322
  scheduler: options?.scheduler,
1274
- remoteName: options?.remoteName
1323
+ remoteName: options?.remoteName,
1324
+ cwd: options?.cwd
1275
1325
  });
1276
1326
  }
1277
1327
  };
@@ -1281,21 +1331,21 @@ async function detectPlatformAdapter(options) {
1281
1331
  const remote = await getRemoteInfo(options?.remoteName, {
1282
1332
  cwd: options?.cwd
1283
1333
  });
1284
- const adapter = createAdapter(remote, options?.remoteName);
1334
+ const adapter = createAdapter(remote, options?.remoteName, options?.cwd);
1285
1335
  return { adapter, remote };
1286
1336
  }
1287
- function createAdapter(remote, remoteName) {
1337
+ function createAdapter(remote, remoteName, cwd) {
1288
1338
  switch (remote.platform) {
1289
1339
  case "github":
1290
- return new GitHubAdapter({ hostname: remote.host, remoteName });
1340
+ return new GitHubAdapter({ hostname: remote.host, remoteName, cwd });
1291
1341
  case "github-enterprise":
1292
- return new GitHubEnterpriseAdapter(remote.host, { remoteName });
1342
+ return new GitHubEnterpriseAdapter(remote.host, { remoteName, cwd });
1293
1343
  case "gitlab":
1294
- return new GitLabAdapter({ hostname: remote.host, remoteName });
1344
+ return new GitLabAdapter({ hostname: remote.host, remoteName, cwd });
1295
1345
  case "gitlab-self-hosted":
1296
- return new GitLabSelfHostedAdapter(remote.host, { remoteName });
1346
+ return new GitLabSelfHostedAdapter(remote.host, { remoteName, cwd });
1297
1347
  case "unknown":
1298
- return new GitHubEnterpriseAdapter(remote.host, { remoteName });
1348
+ return new GitHubEnterpriseAdapter(remote.host, { remoteName, cwd });
1299
1349
  }
1300
1350
  }
1301
1351
 
@@ -6,10 +6,12 @@ export declare class GitHubAdapter implements PlatformAdapter {
6
6
  private readonly hostname;
7
7
  private defaultBranchCache;
8
8
  private readonly remoteName;
9
+ protected readonly cwd: string | undefined;
9
10
  constructor(options?: {
10
11
  hostname?: string;
11
12
  scheduler?: RequestScheduler;
12
13
  remoteName?: string;
14
+ cwd?: string;
13
15
  });
14
16
  checkAuth(): Promise<AuthStatus>;
15
17
  getPRForCommit(sha: string): Promise<PRInfo | null>;
@@ -5,5 +5,6 @@ export declare class GitHubEnterpriseAdapter extends GitHubAdapter {
5
5
  constructor(hostname: string, options?: {
6
6
  scheduler?: RequestScheduler;
7
7
  remoteName?: string;
8
+ cwd?: string;
8
9
  });
9
10
  }
@@ -6,10 +6,12 @@ export declare class GitLabAdapter implements PlatformAdapter {
6
6
  private readonly hostname;
7
7
  private defaultBranchCache;
8
8
  private readonly remoteName;
9
+ protected readonly cwd: string | undefined;
9
10
  constructor(options?: {
10
11
  hostname?: string;
11
12
  scheduler?: RequestScheduler;
12
13
  remoteName?: string;
14
+ cwd?: string;
13
15
  });
14
16
  checkAuth(): Promise<AuthStatus>;
15
17
  getPRForCommit(sha: string): Promise<PRInfo | null>;
@@ -5,5 +5,6 @@ export declare class GitLabSelfHostedAdapter extends GitLabAdapter {
5
5
  constructor(hostname: string, options?: {
6
6
  scheduler?: RequestScheduler;
7
7
  remoteName?: string;
8
+ cwd?: string;
8
9
  });
9
10
  }
@@ -6,4 +6,4 @@ export declare function detectPlatformAdapter(options?: {
6
6
  adapter: PlatformAdapter;
7
7
  remote: RemoteInfo;
8
8
  }>;
9
- export declare function createAdapter(remote: RemoteInfo, remoteName?: string): PlatformAdapter;
9
+ export declare function createAdapter(remote: RemoteInfo, remoteName?: string, cwd?: string): PlatformAdapter;
package/dist/version.d.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  * Current package version from package.json
3
3
  * Automatically synchronized during build process
4
4
  */
5
- export declare const VERSION = "0.0.3";
5
+ export declare const VERSION = "0.0.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumy-pack/line-lore",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "CLI tool for tracing code lines to their originating Pull Requests via git blame",
5
5
  "keywords": [
6
6
  "cli",
@@ -55,7 +55,6 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@winglet/common-utils": "^0.11.2",
58
- "@winglet/react-utils": "^0.11.2",
59
58
  "commander": "^12.1.0",
60
59
  "execa": "^9.5.0",
61
60
  "ink": "^5.0.0",