@lumy-pack/line-lore 0.0.3 → 0.0.5
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 +211 -117
- package/dist/git/executor.d.ts +1 -0
- package/dist/git/index.d.ts +1 -1
- package/dist/index.cjs +202 -115
- package/dist/index.mjs +210 -116
- package/dist/platform/github/github-adapter.d.ts +2 -0
- package/dist/platform/github/github-enterprise-adapter.d.ts +1 -0
- package/dist/platform/gitlab/gitlab-adapter.d.ts +2 -0
- package/dist/platform/gitlab/gitlab-self-hosted-adapter.d.ts +1 -0
- package/dist/platform/platform.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -2
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 {
|
|
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];
|
|
@@ -300,6 +305,51 @@ async function gitExec(args, options) {
|
|
|
300
305
|
LineLoreErrorCode.GIT_COMMAND_FAILED
|
|
301
306
|
);
|
|
302
307
|
}
|
|
308
|
+
async function gitPipe(producerArgs, consumerArgs, options) {
|
|
309
|
+
const { cwd, timeout } = options ?? {};
|
|
310
|
+
const pipeArgs = [...producerArgs, "|", ...consumerArgs];
|
|
311
|
+
try {
|
|
312
|
+
const result = await execa("git", producerArgs, {
|
|
313
|
+
cwd,
|
|
314
|
+
timeout,
|
|
315
|
+
reject: false
|
|
316
|
+
}).pipe("git", consumerArgs, { cwd, timeout, reject: false });
|
|
317
|
+
const exitCode = result.exitCode ?? 0;
|
|
318
|
+
if (exitCode !== 0) {
|
|
319
|
+
throw new LineLoreError(
|
|
320
|
+
LineLoreErrorCode.GIT_COMMAND_FAILED,
|
|
321
|
+
`git pipe failed with exit code ${exitCode}: ${result.stderr}`,
|
|
322
|
+
{
|
|
323
|
+
command: "git",
|
|
324
|
+
args: pipeArgs,
|
|
325
|
+
exitCode,
|
|
326
|
+
stderr: result.stderr,
|
|
327
|
+
cwd
|
|
328
|
+
}
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
stdout: result.stdout,
|
|
333
|
+
stderr: result.stderr,
|
|
334
|
+
exitCode
|
|
335
|
+
};
|
|
336
|
+
} catch (error) {
|
|
337
|
+
if (error instanceof LineLoreError) throw error;
|
|
338
|
+
const isTimeout = error instanceof Error && "isTerminated" in error && error.timedOut === true;
|
|
339
|
+
if (isTimeout) {
|
|
340
|
+
throw new LineLoreError(
|
|
341
|
+
LineLoreErrorCode.GIT_TIMEOUT,
|
|
342
|
+
`git pipe timed out after ${timeout}ms`,
|
|
343
|
+
{ command: "git", args: pipeArgs, timeout, cwd }
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
throw new LineLoreError(
|
|
347
|
+
LineLoreErrorCode.GIT_COMMAND_FAILED,
|
|
348
|
+
`git pipe failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
349
|
+
{ command: "git", args: pipeArgs, cwd }
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
303
353
|
async function shellExec(command, args, options) {
|
|
304
354
|
return execCommand(
|
|
305
355
|
command,
|
|
@@ -400,7 +450,9 @@ function getCache(repoId, noCache) {
|
|
|
400
450
|
if (noCache) {
|
|
401
451
|
return new ShardedCache("patch-id", { repoId, enabled: false });
|
|
402
452
|
}
|
|
403
|
-
const key = repoKey(
|
|
453
|
+
const key = repoKey(
|
|
454
|
+
repoId ?? { host: "_local", owner: "_", repo: "_default" }
|
|
455
|
+
);
|
|
404
456
|
let cache = cacheRegistry.get(key);
|
|
405
457
|
if (!cache) {
|
|
406
458
|
cache = new ShardedCache("patch-id", { repoId });
|
|
@@ -413,14 +465,10 @@ async function computePatchId(commitSha, options) {
|
|
|
413
465
|
const cached = await cache.get(commitSha);
|
|
414
466
|
if (cached) return cached;
|
|
415
467
|
try {
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
"
|
|
419
|
-
|
|
420
|
-
"-c",
|
|
421
|
-
`git -C "${cwd}" diff "${commitSha}^..${commitSha}" | git patch-id --stable`
|
|
422
|
-
],
|
|
423
|
-
{ timeout: options?.timeout }
|
|
468
|
+
const result = await gitPipe(
|
|
469
|
+
["diff", `${commitSha}^..${commitSha}`],
|
|
470
|
+
["patch-id", "--stable"],
|
|
471
|
+
{ cwd: options?.cwd, timeout: options?.timeout }
|
|
424
472
|
);
|
|
425
473
|
const patchId = result.stdout.trim().split(/\s+/)[0];
|
|
426
474
|
if (!patchId) return null;
|
|
@@ -436,15 +484,18 @@ async function findPatchIdMatch(commitSha, options) {
|
|
|
436
484
|
const targetPatchId = await computePatchId(commitSha, options);
|
|
437
485
|
if (!targetPatchId) return null;
|
|
438
486
|
try {
|
|
439
|
-
const
|
|
440
|
-
["log",
|
|
441
|
-
|
|
487
|
+
const result = await gitPipe(
|
|
488
|
+
["log", `-${scanDepth}`, "-p", ref],
|
|
489
|
+
["patch-id", "--stable"],
|
|
490
|
+
{ cwd: options?.cwd, timeout: options?.timeout ?? 6e4 }
|
|
442
491
|
);
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
const
|
|
447
|
-
if (
|
|
492
|
+
const lines = filter5(result.stdout.trim().split("\n"), isTruthy5);
|
|
493
|
+
const cache = getCache(options?.repoId, options?.noCache);
|
|
494
|
+
for (const line of lines) {
|
|
495
|
+
const [patchId, candidateSha] = line.split(/\s+/);
|
|
496
|
+
if (!patchId || !candidateSha) continue;
|
|
497
|
+
await cache.set(candidateSha, patchId);
|
|
498
|
+
if (candidateSha !== commitSha && patchId === targetPatchId) {
|
|
448
499
|
return { matchedSha: candidateSha, patchId: targetPatchId };
|
|
449
500
|
}
|
|
450
501
|
}
|
|
@@ -488,7 +539,9 @@ function getCache2(repoId, noCache) {
|
|
|
488
539
|
if (noCache) {
|
|
489
540
|
return new ShardedCache("pr", { repoId, enabled: false });
|
|
490
541
|
}
|
|
491
|
-
const key = repoKey2(
|
|
542
|
+
const key = repoKey2(
|
|
543
|
+
repoId ?? { host: "_local", owner: "_", repo: "_default" }
|
|
544
|
+
);
|
|
492
545
|
let cache = cacheRegistry2.get(key);
|
|
493
546
|
if (!cache) {
|
|
494
547
|
cache = new ShardedCache("pr", { repoId });
|
|
@@ -527,17 +580,6 @@ async function lookupPR(commitSha, adapter, options) {
|
|
|
527
580
|
}
|
|
528
581
|
}
|
|
529
582
|
}
|
|
530
|
-
const patchIdMatch = await findPatchIdMatch(commitSha, {
|
|
531
|
-
...options,
|
|
532
|
-
scanDepth: options?.deep ? DEEP_SCAN_DEPTH : void 0
|
|
533
|
-
});
|
|
534
|
-
if (patchIdMatch) {
|
|
535
|
-
const result = await lookupPR(patchIdMatch.matchedSha, adapter, options);
|
|
536
|
-
if (result) {
|
|
537
|
-
await cache.set(commitSha, result);
|
|
538
|
-
return result;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
583
|
if (mergeBasedPR) {
|
|
542
584
|
await cache.set(commitSha, mergeBasedPR);
|
|
543
585
|
return mergeBasedPR;
|
|
@@ -549,6 +591,17 @@ async function lookupPR(commitSha, adapter, options) {
|
|
|
549
591
|
return prInfo;
|
|
550
592
|
}
|
|
551
593
|
}
|
|
594
|
+
const patchIdMatch = await findPatchIdMatch(commitSha, {
|
|
595
|
+
...options,
|
|
596
|
+
scanDepth: options?.deep ? DEEP_SCAN_DEPTH : void 0
|
|
597
|
+
});
|
|
598
|
+
if (patchIdMatch) {
|
|
599
|
+
const result = await lookupPR(patchIdMatch.matchedSha, adapter, options);
|
|
600
|
+
if (result) {
|
|
601
|
+
await cache.set(commitSha, result);
|
|
602
|
+
return result;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
552
605
|
return null;
|
|
553
606
|
}
|
|
554
607
|
function resetPRCache() {
|
|
@@ -584,7 +637,7 @@ var VERSION;
|
|
|
584
637
|
var init_version = __esm({
|
|
585
638
|
"src/version.ts"() {
|
|
586
639
|
"use strict";
|
|
587
|
-
VERSION = "0.0.
|
|
640
|
+
VERSION = "0.0.5";
|
|
588
641
|
}
|
|
589
642
|
});
|
|
590
643
|
|
|
@@ -680,9 +733,8 @@ function respondError(command, code, message, startTime, version2, details) {
|
|
|
680
733
|
import { Command } from "commander";
|
|
681
734
|
|
|
682
735
|
// src/core/core.ts
|
|
683
|
-
init_cache();
|
|
684
|
-
import { map as map8 } from "@winglet/common-utils";
|
|
685
736
|
import { createHash as createHash2 } from "crypto";
|
|
737
|
+
import { map as map8 } from "@winglet/common-utils";
|
|
686
738
|
|
|
687
739
|
// src/ast/parser.ts
|
|
688
740
|
import { isNil } from "@winglet/common-utils";
|
|
@@ -889,7 +941,9 @@ function findPythonBlockEnd(lines, startIdx) {
|
|
|
889
941
|
}
|
|
890
942
|
|
|
891
943
|
// src/core/core.ts
|
|
944
|
+
init_cache();
|
|
892
945
|
init_errors();
|
|
946
|
+
init_executor();
|
|
893
947
|
|
|
894
948
|
// src/git/health.ts
|
|
895
949
|
init_executor();
|
|
@@ -937,9 +991,6 @@ async function checkGitHealth(options) {
|
|
|
937
991
|
return { commitGraph, bloomFilter, gitVersion, hints };
|
|
938
992
|
}
|
|
939
993
|
|
|
940
|
-
// src/core/core.ts
|
|
941
|
-
init_executor();
|
|
942
|
-
|
|
943
994
|
// src/git/remote.ts
|
|
944
995
|
init_errors();
|
|
945
996
|
init_executor();
|
|
@@ -1004,10 +1055,12 @@ var GitHubAdapter = class {
|
|
|
1004
1055
|
hostname;
|
|
1005
1056
|
defaultBranchCache = null;
|
|
1006
1057
|
remoteName;
|
|
1058
|
+
cwd;
|
|
1007
1059
|
constructor(options) {
|
|
1008
1060
|
this.hostname = options?.hostname ?? "github.com";
|
|
1009
1061
|
this.scheduler = options?.scheduler ?? new RequestScheduler();
|
|
1010
1062
|
this.remoteName = options?.remoteName ?? "origin";
|
|
1063
|
+
this.cwd = options?.cwd;
|
|
1011
1064
|
}
|
|
1012
1065
|
async checkAuth() {
|
|
1013
1066
|
try {
|
|
@@ -1015,6 +1068,7 @@ var GitHubAdapter = class {
|
|
|
1015
1068
|
"gh",
|
|
1016
1069
|
["auth", "token", "--hostname", this.hostname],
|
|
1017
1070
|
{
|
|
1071
|
+
cwd: this.cwd,
|
|
1018
1072
|
allowExitCodes: [1]
|
|
1019
1073
|
}
|
|
1020
1074
|
);
|
|
@@ -1030,14 +1084,18 @@ var GitHubAdapter = class {
|
|
|
1030
1084
|
async getPRForCommit(sha) {
|
|
1031
1085
|
if (this.scheduler.isRateLimited()) return null;
|
|
1032
1086
|
try {
|
|
1033
|
-
const result = await shellExec(
|
|
1034
|
-
"
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1087
|
+
const result = await shellExec(
|
|
1088
|
+
"gh",
|
|
1089
|
+
[
|
|
1090
|
+
"api",
|
|
1091
|
+
`repos/{owner}/{repo}/commits/${sha}/pulls`,
|
|
1092
|
+
"--hostname",
|
|
1093
|
+
this.hostname,
|
|
1094
|
+
"--jq",
|
|
1095
|
+
"[.[] | select(.merged_at != null) | {number, title, user: .user.login, html_url, merge_commit_sha, base: .base.ref, merged_at}] | sort_by(.merged_at)"
|
|
1096
|
+
],
|
|
1097
|
+
{ cwd: this.cwd }
|
|
1098
|
+
);
|
|
1041
1099
|
const prs = JSON.parse(result.stdout);
|
|
1042
1100
|
if (!isArray(prs) || prs.length === 0) return null;
|
|
1043
1101
|
const defaultBranch = await this.detectDefaultBranch();
|
|
@@ -1063,7 +1121,7 @@ var GitHubAdapter = class {
|
|
|
1063
1121
|
try {
|
|
1064
1122
|
const result = await gitExec(
|
|
1065
1123
|
["symbolic-ref", `refs/remotes/${this.remoteName}/HEAD`],
|
|
1066
|
-
{}
|
|
1124
|
+
{ cwd: this.cwd }
|
|
1067
1125
|
);
|
|
1068
1126
|
const ref = result.stdout.trim();
|
|
1069
1127
|
this.defaultBranchCache = ref.replace(`refs/remotes/${this.remoteName}/`, "") || "main";
|
|
@@ -1074,14 +1132,18 @@ var GitHubAdapter = class {
|
|
|
1074
1132
|
}
|
|
1075
1133
|
async getPRCommits(prNumber) {
|
|
1076
1134
|
try {
|
|
1077
|
-
const result = await shellExec(
|
|
1078
|
-
"
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1135
|
+
const result = await shellExec(
|
|
1136
|
+
"gh",
|
|
1137
|
+
[
|
|
1138
|
+
"api",
|
|
1139
|
+
`repos/{owner}/{repo}/pulls/${prNumber}/commits`,
|
|
1140
|
+
"--hostname",
|
|
1141
|
+
this.hostname,
|
|
1142
|
+
"--jq",
|
|
1143
|
+
".[].sha"
|
|
1144
|
+
],
|
|
1145
|
+
{ cwd: this.cwd }
|
|
1146
|
+
);
|
|
1085
1147
|
return filter(result.stdout.trim().split("\n"), isTruthy);
|
|
1086
1148
|
} catch {
|
|
1087
1149
|
return [];
|
|
@@ -1089,16 +1151,20 @@ var GitHubAdapter = class {
|
|
|
1089
1151
|
}
|
|
1090
1152
|
async getLinkedIssues(prNumber) {
|
|
1091
1153
|
try {
|
|
1092
|
-
const result = await shellExec(
|
|
1093
|
-
"
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1154
|
+
const result = await shellExec(
|
|
1155
|
+
"gh",
|
|
1156
|
+
[
|
|
1157
|
+
"api",
|
|
1158
|
+
"graphql",
|
|
1159
|
+
"--hostname",
|
|
1160
|
+
this.hostname,
|
|
1161
|
+
"-f",
|
|
1162
|
+
`query=query { repository(owner: "{owner}", name: "{repo}") { pullRequest(number: ${prNumber}) { closingIssuesReferences(first: 10) { nodes { number title url state labels(first: 5) { nodes { name } } } } } } }`,
|
|
1163
|
+
"--jq",
|
|
1164
|
+
".data.repository.pullRequest.closingIssuesReferences.nodes"
|
|
1165
|
+
],
|
|
1166
|
+
{ cwd: this.cwd }
|
|
1167
|
+
);
|
|
1102
1168
|
const nodes = JSON.parse(result.stdout);
|
|
1103
1169
|
if (!isArray(nodes)) return [];
|
|
1104
1170
|
return map2(nodes, (node) => ({
|
|
@@ -1117,14 +1183,18 @@ var GitHubAdapter = class {
|
|
|
1117
1183
|
}
|
|
1118
1184
|
async getLinkedPRs(issueNumber) {
|
|
1119
1185
|
try {
|
|
1120
|
-
const result = await shellExec(
|
|
1121
|
-
"
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1186
|
+
const result = await shellExec(
|
|
1187
|
+
"gh",
|
|
1188
|
+
[
|
|
1189
|
+
"api",
|
|
1190
|
+
`repos/{owner}/{repo}/issues/${issueNumber}/timeline`,
|
|
1191
|
+
"--hostname",
|
|
1192
|
+
this.hostname,
|
|
1193
|
+
"--jq",
|
|
1194
|
+
"[.[] | 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})"
|
|
1195
|
+
],
|
|
1196
|
+
{ cwd: this.cwd }
|
|
1197
|
+
);
|
|
1128
1198
|
const prs = JSON.parse(result.stdout);
|
|
1129
1199
|
if (!isArray(prs)) return [];
|
|
1130
1200
|
const defaultBranch = await this.detectDefaultBranch();
|
|
@@ -1143,14 +1213,18 @@ var GitHubAdapter = class {
|
|
|
1143
1213
|
}
|
|
1144
1214
|
async getRateLimit() {
|
|
1145
1215
|
try {
|
|
1146
|
-
const result = await shellExec(
|
|
1147
|
-
"
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1216
|
+
const result = await shellExec(
|
|
1217
|
+
"gh",
|
|
1218
|
+
[
|
|
1219
|
+
"api",
|
|
1220
|
+
"rate_limit",
|
|
1221
|
+
"--hostname",
|
|
1222
|
+
this.hostname,
|
|
1223
|
+
"--jq",
|
|
1224
|
+
".rate | {limit, remaining, reset}"
|
|
1225
|
+
],
|
|
1226
|
+
{ cwd: this.cwd }
|
|
1227
|
+
);
|
|
1154
1228
|
const data = JSON.parse(result.stdout);
|
|
1155
1229
|
const info = {
|
|
1156
1230
|
limit: data.limit ?? 5e3,
|
|
@@ -1172,7 +1246,8 @@ var GitHubEnterpriseAdapter = class extends GitHubAdapter {
|
|
|
1172
1246
|
super({
|
|
1173
1247
|
hostname,
|
|
1174
1248
|
scheduler: options?.scheduler,
|
|
1175
|
-
remoteName: options?.remoteName
|
|
1249
|
+
remoteName: options?.remoteName,
|
|
1250
|
+
cwd: options?.cwd
|
|
1176
1251
|
});
|
|
1177
1252
|
}
|
|
1178
1253
|
};
|
|
@@ -1186,10 +1261,12 @@ var GitLabAdapter = class {
|
|
|
1186
1261
|
hostname;
|
|
1187
1262
|
defaultBranchCache = null;
|
|
1188
1263
|
remoteName;
|
|
1264
|
+
cwd;
|
|
1189
1265
|
constructor(options) {
|
|
1190
1266
|
this.hostname = options?.hostname ?? "gitlab.com";
|
|
1191
1267
|
this.scheduler = options?.scheduler ?? new RequestScheduler();
|
|
1192
1268
|
this.remoteName = options?.remoteName ?? "origin";
|
|
1269
|
+
this.cwd = options?.cwd;
|
|
1193
1270
|
}
|
|
1194
1271
|
async checkAuth() {
|
|
1195
1272
|
if (process.env.GITLAB_TOKEN) {
|
|
@@ -1199,7 +1276,7 @@ var GitLabAdapter = class {
|
|
|
1199
1276
|
const result = await shellExec(
|
|
1200
1277
|
"glab",
|
|
1201
1278
|
["auth", "status", "--hostname", this.hostname],
|
|
1202
|
-
{ allowExitCodes: [1] }
|
|
1279
|
+
{ cwd: this.cwd, allowExitCodes: [1] }
|
|
1203
1280
|
);
|
|
1204
1281
|
return {
|
|
1205
1282
|
authenticated: result.exitCode === 0,
|
|
@@ -1212,12 +1289,16 @@ var GitLabAdapter = class {
|
|
|
1212
1289
|
async getPRForCommit(sha) {
|
|
1213
1290
|
if (this.scheduler.isRateLimited()) return null;
|
|
1214
1291
|
try {
|
|
1215
|
-
const result = await shellExec(
|
|
1216
|
-
"
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1292
|
+
const result = await shellExec(
|
|
1293
|
+
"glab",
|
|
1294
|
+
[
|
|
1295
|
+
"api",
|
|
1296
|
+
`projects/:id/repository/commits/${sha}/merge_requests`,
|
|
1297
|
+
"--hostname",
|
|
1298
|
+
this.hostname
|
|
1299
|
+
],
|
|
1300
|
+
{ cwd: this.cwd }
|
|
1301
|
+
);
|
|
1221
1302
|
const mrs = JSON.parse(result.stdout);
|
|
1222
1303
|
if (!isArray2(mrs) || mrs.length === 0) return null;
|
|
1223
1304
|
const mergedMRs = filter2(
|
|
@@ -1252,7 +1333,7 @@ var GitLabAdapter = class {
|
|
|
1252
1333
|
try {
|
|
1253
1334
|
const result = await gitExec(
|
|
1254
1335
|
["symbolic-ref", `refs/remotes/${this.remoteName}/HEAD`],
|
|
1255
|
-
{}
|
|
1336
|
+
{ cwd: this.cwd }
|
|
1256
1337
|
);
|
|
1257
1338
|
const ref = result.stdout.trim();
|
|
1258
1339
|
this.defaultBranchCache = ref.replace(`refs/remotes/${this.remoteName}/`, "") || "main";
|
|
@@ -1263,12 +1344,16 @@ var GitLabAdapter = class {
|
|
|
1263
1344
|
}
|
|
1264
1345
|
async getPRCommits(prNumber) {
|
|
1265
1346
|
try {
|
|
1266
|
-
const result = await shellExec(
|
|
1267
|
-
"
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1347
|
+
const result = await shellExec(
|
|
1348
|
+
"glab",
|
|
1349
|
+
[
|
|
1350
|
+
"api",
|
|
1351
|
+
`projects/:id/merge_requests/${prNumber}/commits`,
|
|
1352
|
+
"--hostname",
|
|
1353
|
+
this.hostname
|
|
1354
|
+
],
|
|
1355
|
+
{ cwd: this.cwd }
|
|
1356
|
+
);
|
|
1272
1357
|
const commits = JSON.parse(result.stdout);
|
|
1273
1358
|
if (!isArray2(commits)) return [];
|
|
1274
1359
|
return map3(commits, (c) => c.id);
|
|
@@ -1278,12 +1363,16 @@ var GitLabAdapter = class {
|
|
|
1278
1363
|
}
|
|
1279
1364
|
async getLinkedIssues(prNumber) {
|
|
1280
1365
|
try {
|
|
1281
|
-
const result = await shellExec(
|
|
1282
|
-
"
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1366
|
+
const result = await shellExec(
|
|
1367
|
+
"glab",
|
|
1368
|
+
[
|
|
1369
|
+
"api",
|
|
1370
|
+
`projects/:id/merge_requests/${prNumber}/closes_issues`,
|
|
1371
|
+
"--hostname",
|
|
1372
|
+
this.hostname
|
|
1373
|
+
],
|
|
1374
|
+
{ cwd: this.cwd }
|
|
1375
|
+
);
|
|
1287
1376
|
const issues = JSON.parse(result.stdout);
|
|
1288
1377
|
if (!isArray2(issues)) return [];
|
|
1289
1378
|
return map3(issues, (issue) => ({
|
|
@@ -1299,12 +1388,16 @@ var GitLabAdapter = class {
|
|
|
1299
1388
|
}
|
|
1300
1389
|
async getLinkedPRs(issueNumber) {
|
|
1301
1390
|
try {
|
|
1302
|
-
const result = await shellExec(
|
|
1303
|
-
"
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1391
|
+
const result = await shellExec(
|
|
1392
|
+
"glab",
|
|
1393
|
+
[
|
|
1394
|
+
"api",
|
|
1395
|
+
`projects/:id/issues/${issueNumber}/related_merge_requests`,
|
|
1396
|
+
"--hostname",
|
|
1397
|
+
this.hostname
|
|
1398
|
+
],
|
|
1399
|
+
{ cwd: this.cwd }
|
|
1400
|
+
);
|
|
1308
1401
|
const mrs = JSON.parse(result.stdout);
|
|
1309
1402
|
if (!isArray2(mrs)) return [];
|
|
1310
1403
|
const defaultBranch = await this.detectDefaultBranch();
|
|
@@ -1333,7 +1426,8 @@ var GitLabSelfHostedAdapter = class extends GitLabAdapter {
|
|
|
1333
1426
|
super({
|
|
1334
1427
|
hostname,
|
|
1335
1428
|
scheduler: options?.scheduler,
|
|
1336
|
-
remoteName: options?.remoteName
|
|
1429
|
+
remoteName: options?.remoteName,
|
|
1430
|
+
cwd: options?.cwd
|
|
1337
1431
|
});
|
|
1338
1432
|
}
|
|
1339
1433
|
};
|
|
@@ -1343,21 +1437,21 @@ async function detectPlatformAdapter(options) {
|
|
|
1343
1437
|
const remote = await getRemoteInfo(options?.remoteName, {
|
|
1344
1438
|
cwd: options?.cwd
|
|
1345
1439
|
});
|
|
1346
|
-
const adapter = createAdapter(remote, options?.remoteName);
|
|
1440
|
+
const adapter = createAdapter(remote, options?.remoteName, options?.cwd);
|
|
1347
1441
|
return { adapter, remote };
|
|
1348
1442
|
}
|
|
1349
|
-
function createAdapter(remote, remoteName) {
|
|
1443
|
+
function createAdapter(remote, remoteName, cwd) {
|
|
1350
1444
|
switch (remote.platform) {
|
|
1351
1445
|
case "github":
|
|
1352
|
-
return new GitHubAdapter({ hostname: remote.host, remoteName });
|
|
1446
|
+
return new GitHubAdapter({ hostname: remote.host, remoteName, cwd });
|
|
1353
1447
|
case "github-enterprise":
|
|
1354
|
-
return new GitHubEnterpriseAdapter(remote.host, { remoteName });
|
|
1448
|
+
return new GitHubEnterpriseAdapter(remote.host, { remoteName, cwd });
|
|
1355
1449
|
case "gitlab":
|
|
1356
|
-
return new GitLabAdapter({ hostname: remote.host, remoteName });
|
|
1450
|
+
return new GitLabAdapter({ hostname: remote.host, remoteName, cwd });
|
|
1357
1451
|
case "gitlab-self-hosted":
|
|
1358
|
-
return new GitLabSelfHostedAdapter(remote.host, { remoteName });
|
|
1452
|
+
return new GitLabSelfHostedAdapter(remote.host, { remoteName, cwd });
|
|
1359
1453
|
case "unknown":
|
|
1360
|
-
return new GitHubEnterpriseAdapter(remote.host, { remoteName });
|
|
1454
|
+
return new GitHubEnterpriseAdapter(remote.host, { remoteName, cwd });
|
|
1361
1455
|
}
|
|
1362
1456
|
}
|
|
1363
1457
|
|
package/dist/git/executor.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { GitExecOptions, GitExecResult } from '../types/index.js';
|
|
2
2
|
export declare function gitExec(args: string[], options?: GitExecOptions): Promise<GitExecResult>;
|
|
3
|
+
export declare function gitPipe(producerArgs: string[], consumerArgs: string[], options?: GitExecOptions): Promise<GitExecResult>;
|
|
3
4
|
export declare function shellExec(command: string, args: string[], options?: GitExecOptions): Promise<GitExecResult>;
|
package/dist/git/index.d.ts
CHANGED