@ycodium-ai/plugin-pull-requests 0.2.5004 → 0.2.5100

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 (3) hide show
  1. package/assets/ui.js +21 -21
  2. package/dist/index.js +261 -313
  3. package/package.json +4 -2
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { definePlugin } from "@ycodium-ai/plugin-api";
3
3
 
4
4
  // ../../packages/plugin-api/src/version.ts
5
- var PLUGIN_API_VERSION = 142;
5
+ var PLUGIN_API_VERSION = 148;
6
6
 
7
7
  // src/hostProject.ts
8
8
  var providerOf = (provider) => provider === "github" || provider === "gitlab" ? provider : "unknown";
@@ -79,18 +79,29 @@ var createBackoff = (options) => {
79
79
  var isPaused = (result) => "retryAt" in result;
80
80
 
81
81
  // src/service/cache.ts
82
+ var createTimedEntries = (capacity, now) => {
83
+ const entries = /* @__PURE__ */ new Map();
84
+ return {
85
+ get: (key) => entries.get(key),
86
+ delete: (key) => entries.delete(key),
87
+ clear: () => entries.clear(),
88
+ get size() {
89
+ return entries.size;
90
+ },
91
+ record: (key, value) => {
92
+ entries.delete(key);
93
+ if (entries.size >= capacity) {
94
+ const oldest = entries.keys().next().value;
95
+ if (oldest !== void 0) entries.delete(oldest);
96
+ }
97
+ entries.set(key, { at: now(), value });
98
+ }
99
+ };
100
+ };
82
101
  var createCache = (options) => {
83
102
  const now = options.now ?? Date.now;
84
- const held = /* @__PURE__ */ new Map();
103
+ const held = createTimedEntries(options.capacity, now);
85
104
  const inFlight = /* @__PURE__ */ new Map();
86
- const record = (key, value) => {
87
- held.delete(key);
88
- if (held.size >= options.capacity) {
89
- const oldest = held.keys().next().value;
90
- if (oldest !== void 0) held.delete(oldest);
91
- }
92
- held.set(key, { at: now(), value });
93
- };
94
105
  return {
95
106
  get: (key, load) => {
96
107
  const snapshot = held.get(key);
@@ -103,7 +114,7 @@ var createCache = (options) => {
103
114
  const started = load().then(
104
115
  (value) => {
105
116
  inFlight.delete(key);
106
- record(key, value);
117
+ held.record(key, value);
107
118
  return value;
108
119
  },
109
120
  (error) => {
@@ -122,19 +133,11 @@ var createCache = (options) => {
122
133
  };
123
134
  var createStaleWindow = (options) => {
124
135
  const now = options.now ?? Date.now;
125
- const held = /* @__PURE__ */ new Map();
126
- const record = (key, value) => {
127
- held.delete(key);
128
- if (held.size >= options.capacity) {
129
- const oldest = held.keys().next().value;
130
- if (oldest !== void 0) held.delete(oldest);
131
- }
132
- held.set(key, { at: now(), value });
133
- };
136
+ const held = createTimedEntries(options.capacity, now);
134
137
  return {
135
138
  get: (key, read) => {
136
139
  const recorded = () => read().then((value) => {
137
- record(key, value);
140
+ held.record(key, value);
138
141
  return value;
139
142
  });
140
143
  const snapshot = held.get(key);
@@ -238,30 +241,12 @@ var withoutAlreadySent = (cursor, items) => cursor === void 0 ? items : items.fi
238
241
  (item) => item.updatedAt !== cursor.updatedBefore || !cursor.seenAt.includes(item.number)
239
242
  );
240
243
 
241
- // src/githubHttp.ts
244
+ // src/forgeHttp.ts
242
245
  var DEFAULT_TIMEOUT_MS = 3e4;
243
246
  var DEFAULT_MAX_BYTES = 1024 * 1024;
244
- var DEFAULT_HOST = "github.com";
245
- var RESERVE_RATIO = 0.1;
246
- var CARD = "Settings \u2192 Plugins \u2192 Pull requests";
247
- var GitHubError = class extends Error {
248
- code;
249
- /** 只有限流会带:`{ retryAt: epoch ms }`。宿主原样透传给 port。 */
250
- data;
251
- constructor(input) {
252
- super(`GitHub API failed in ${input.operation}: ${input.detail}`);
253
- this.name = "GitHubError";
254
- this.code = input.code;
255
- if (input.data !== void 0) this.data = input.data;
256
- }
257
- };
258
- var text = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
247
+ var SETTINGS_CARD = "Settings \u2192 Plugins \u2192 Pull requests";
248
+ var configText = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
259
249
  var normalizeHost = (value) => value.trim().replace(/^https?:\/\//i, "").replace(/\/+$/, "").toLowerCase();
260
- var configuredHost = (ctx) => normalizeHost(text(ctx.config["githubHost"]) ?? DEFAULT_HOST);
261
- var configuredToken = (ctx) => text(ctx.config["githubToken"]);
262
- var restBase = (host) => host === DEFAULT_HOST ? "https://api.github.com" : `https://${host}/api/v3`;
263
- var graphQlUrl = (host) => host === DEFAULT_HOST ? "https://api.github.com/graphql" : `https://${host}/api/graphql`;
264
- var RATE_LIMIT_SELECTION = "rateLimit { cost limit remaining resetAt }";
265
250
  var readBody = async (response, maxBytes) => {
266
251
  const stream = response.body;
267
252
  if (stream === null) return { body: "", truncated: false };
@@ -284,6 +269,75 @@ var readBody = async (response, maxBytes) => {
284
269
  }
285
270
  return { body: body + decoder.decode(), truncated: false };
286
271
  };
272
+ var requestError = (request, error) => {
273
+ const name = error instanceof Error ? error.name : "";
274
+ if (name === "TimeoutError" || name === "AbortError") {
275
+ return request.fail("failed", `${request.vendor} did not answer before the timeout.`);
276
+ }
277
+ return request.fail("failed", error instanceof Error ? error.message : String(error));
278
+ };
279
+ var sendForgeHttp = async (ctx, request) => {
280
+ const asked = request.askedHost === void 0 ? null : normalizeHost(request.askedHost);
281
+ if (asked !== null && asked.length > 0 && asked !== request.host) {
282
+ throw request.fail(
283
+ "unauthenticated",
284
+ `This repository lives on ${asked}, but ${SETTINGS_CARD} is configured for ${request.host}.`
285
+ );
286
+ }
287
+ const token = request.token;
288
+ if (token === null) {
289
+ throw request.fail(
290
+ "missing-tool",
291
+ `No ${request.vendor} token is configured. Add a personal access token ${request.tokenScopeHint} in ${SETTINGS_CARD}.`
292
+ );
293
+ }
294
+ let response;
295
+ try {
296
+ response = await ctx.http(request.url, {
297
+ method: request.method ?? "GET",
298
+ headers: request.headers(token),
299
+ ...request.body === void 0 ? {} : { body: request.body },
300
+ signal: AbortSignal.timeout(request.timeoutMs ?? DEFAULT_TIMEOUT_MS)
301
+ });
302
+ } catch (error) {
303
+ throw requestError(request, error);
304
+ }
305
+ if (!response.ok) {
306
+ await response.body?.cancel();
307
+ throw request.statusError(response.status, response.headers);
308
+ }
309
+ const rejected = request.okError?.(response.headers) ?? null;
310
+ if (rejected !== null) {
311
+ await response.body?.cancel();
312
+ throw rejected;
313
+ }
314
+ try {
315
+ const read = await readBody(response, request.maxBytes ?? DEFAULT_MAX_BYTES);
316
+ return { ...read, headers: response.headers };
317
+ } catch (error) {
318
+ throw requestError(request, error);
319
+ }
320
+ };
321
+
322
+ // src/githubHttp.ts
323
+ var DEFAULT_HOST = "github.com";
324
+ var RESERVE_RATIO = 0.1;
325
+ var GitHubError = class extends Error {
326
+ code;
327
+ /** 只有限流会带:`{ retryAt: epoch ms }`。宿主原样透传给 port。 */
328
+ data;
329
+ constructor(input) {
330
+ super(`GitHub API failed in ${input.operation}: ${input.detail}`);
331
+ this.name = "GitHubError";
332
+ this.code = input.code;
333
+ if (input.data !== void 0) this.data = input.data;
334
+ }
335
+ };
336
+ var configuredHost = (ctx) => normalizeHost(configText(ctx.config["githubHost"]) ?? DEFAULT_HOST);
337
+ var configuredToken = (ctx) => configText(ctx.config["githubToken"]);
338
+ var restBase = (host) => host === DEFAULT_HOST ? "https://api.github.com" : `https://${host}/api/v3`;
339
+ var graphQlUrl = (host) => host === DEFAULT_HOST ? "https://api.github.com/graphql" : `https://${host}/api/graphql`;
340
+ var RATE_LIMIT_SELECTION = "rateLimit { cost limit remaining resetAt }";
287
341
  var number = (value) => {
288
342
  if (value === null) return null;
289
343
  const parsed = Number(value.trim());
@@ -318,7 +372,7 @@ var statusError = (input) => {
318
372
  return new GitHubError({
319
373
  code: "unauthenticated",
320
374
  operation: input.operation,
321
- detail: `GitHub refused the token (HTTP ${input.status}). Check the token and its \`repo\` scope in ${CARD}.`
375
+ detail: `GitHub refused the token (HTTP ${input.status}). Check the token and its \`repo\` scope in ${SETTINGS_CARD}.`
322
376
  });
323
377
  }
324
378
  return new GitHubError({
@@ -338,74 +392,30 @@ var restBudgetError = (operation, headers) => {
338
392
  retryAt: retryAtFrom(headers)
339
393
  });
340
394
  };
341
- var requestError = (operation, error) => {
342
- const name = error instanceof Error ? error.name : "";
343
- if (name === "TimeoutError" || name === "AbortError") {
344
- return new GitHubError({
345
- code: "failed",
346
- operation,
347
- detail: "GitHub did not answer before the timeout."
348
- });
349
- }
350
- return new GitHubError({
351
- code: "failed",
352
- operation,
353
- detail: error instanceof Error ? error.message : String(error)
354
- });
355
- };
356
- var send = async (ctx, input) => {
395
+ var send = (ctx, input) => {
357
396
  const host = configuredHost(ctx);
358
- const asked = input.host === void 0 ? null : normalizeHost(input.host);
359
- if (asked !== null && asked.length > 0 && asked !== host) {
360
- throw new GitHubError({
361
- code: "unauthenticated",
362
- operation: input.operation,
363
- detail: `This repository lives on ${asked}, but ${CARD} is configured for ${host}.`
364
- });
365
- }
366
- const token = configuredToken(ctx);
367
- if (token === null) {
368
- throw new GitHubError({
369
- code: "missing-tool",
370
- operation: input.operation,
371
- detail: `No GitHub token is configured. Add a personal access token with the \`repo\` scope in ${CARD}.`
372
- });
373
- }
374
- let response;
375
- try {
376
- response = await ctx.http(input.url(host), {
377
- method: input.method ?? "GET",
378
- headers: {
379
- Authorization: `Bearer ${token}`,
380
- Accept: input.accept ?? "application/vnd.github+json",
381
- "X-GitHub-Api-Version": "2022-11-28",
382
- "Content-Type": "application/json"
383
- },
384
- ...input.body === void 0 ? {} : { body: input.body },
385
- signal: AbortSignal.timeout(input.timeoutMs ?? DEFAULT_TIMEOUT_MS)
386
- });
387
- } catch (error) {
388
- throw requestError(input.operation, error);
389
- }
390
- if (!response.ok) {
391
- await response.body?.cancel();
392
- throw statusError({
393
- operation: input.operation,
394
- status: response.status,
395
- headers: response.headers
396
- });
397
- }
398
- const budget = restBudgetError(input.operation, response.headers);
399
- if (budget !== null) {
400
- await response.body?.cancel();
401
- throw budget;
402
- }
403
- try {
404
- const read = await readBody(response, input.maxBytes ?? DEFAULT_MAX_BYTES);
405
- return { ...read, headers: response.headers };
406
- } catch (error) {
407
- throw requestError(input.operation, error);
408
- }
397
+ return sendForgeHttp(ctx, {
398
+ vendor: "GitHub",
399
+ operation: input.operation,
400
+ host,
401
+ askedHost: input.host,
402
+ token: configuredToken(ctx),
403
+ tokenScopeHint: "with the `repo` scope",
404
+ url: input.url(host),
405
+ method: input.method,
406
+ body: input.body,
407
+ headers: (token) => ({
408
+ Authorization: `Bearer ${token}`,
409
+ Accept: input.accept ?? "application/vnd.github+json",
410
+ "X-GitHub-Api-Version": "2022-11-28",
411
+ "Content-Type": "application/json"
412
+ }),
413
+ timeoutMs: input.timeoutMs,
414
+ maxBytes: input.maxBytes,
415
+ fail: (code, detail) => new GitHubError({ code, operation: input.operation, detail }),
416
+ statusError: (status, headers) => statusError({ operation: input.operation, status, headers }),
417
+ okError: (headers) => restBudgetError(input.operation, headers)
418
+ });
409
419
  };
410
420
  var callGitHubApi = (ctx, input) => send(ctx, { ...input, url: (host) => `${restBase(host)}/${input.path}` });
411
421
  var ORG_SCOPES = /* @__PURE__ */ new Set(["read:org", "admin:org", "read:discussion", "admin:discussion"]);
@@ -470,14 +480,14 @@ var graphQlBudgetError = (operation, data) => {
470
480
  });
471
481
  };
472
482
  var INSUFFICIENT_SCOPES = "INSUFFICIENT_SCOPES";
473
- var errorTypes = (errors) => errors.map((entry) => text(asObject(entry)?.["type"])?.toUpperCase() ?? "");
483
+ var errorTypes = (errors) => errors.map((entry) => configText(asObject(entry)?.["type"])?.toUpperCase() ?? "");
474
484
  var errorPaths = (errors) => errors.flatMap((entry) => {
475
485
  const path2 = asObject(entry)?.["path"];
476
486
  return Array.isArray(path2) ? [path2.map((part) => String(part)).join(".")] : [];
477
487
  });
478
488
  var graphQlError = (operation, errors) => {
479
489
  const types = errorTypes(errors);
480
- const message = text(asObject(errors[0])?.["message"]) ?? "GitHub rejected the query.";
490
+ const message = configText(asObject(errors[0])?.["message"]) ?? "GitHub rejected the query.";
481
491
  if (types.includes("RATE_LIMITED")) {
482
492
  return rateLimited({ operation, detail: message, retryAt: null });
483
493
  }
@@ -485,7 +495,7 @@ var graphQlError = (operation, errors) => {
485
495
  return new GitHubError({
486
496
  code: "unauthenticated",
487
497
  operation,
488
- detail: `${message} Check the token and its scopes in ${CARD}.`
498
+ detail: `${message} Check the token and its scopes in ${SETTINGS_CARD}.`
489
499
  });
490
500
  }
491
501
  return new GitHubError({ code: "failed", operation, detail: message });
@@ -521,7 +531,7 @@ var callGitHubGraphQl = async (ctx, input) => {
521
531
  // src/githubValues.ts
522
532
  var asObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
523
533
  var asArray = (value) => Array.isArray(value) ? value : [];
524
- var text2 = (value) => {
534
+ var text = (value) => {
525
535
  if (typeof value !== "string") return null;
526
536
  const trimmed = value.trim();
527
537
  return trimmed.length > 0 ? trimmed : null;
@@ -537,7 +547,7 @@ var at = (value, ...keys) => {
537
547
  return current;
538
548
  };
539
549
  var nodes = (value) => asArray(at(value, "nodes"));
540
- var nextCursorOf = (value) => at(value, "pageInfo", "hasNextPage") === true ? text2(at(value, "pageInfo", "endCursor")) : null;
550
+ var nextCursorOf = (value) => at(value, "pageInfo", "hasNextPage") === true ? text(at(value, "pageInfo", "endCursor")) : null;
541
551
  var REACTION_BY_GITHUB = {
542
552
  THUMBS_UP: "thumbs-up",
543
553
  THUMBS_DOWN: "thumbs-down",
@@ -575,8 +585,8 @@ var gitHubReviewPosition = (position) => {
575
585
  }
576
586
  };
577
587
  var toState = (raw) => {
578
- if (text2(raw["mergedAt"]) !== null) return "merged";
579
- switch (text2(raw["state"])?.toUpperCase()) {
588
+ if (text(raw["mergedAt"]) !== null) return "merged";
589
+ switch (text(raw["state"])?.toUpperCase()) {
580
590
  case "MERGED":
581
591
  return "merged";
582
592
  case "CLOSED":
@@ -586,7 +596,7 @@ var toState = (raw) => {
586
596
  }
587
597
  };
588
598
  var toMergeability = (value) => {
589
- switch (text2(value)?.toUpperCase()) {
599
+ switch (text(value)?.toUpperCase()) {
590
600
  case "MERGEABLE":
591
601
  return "mergeable";
592
602
  case "CONFLICTING":
@@ -596,7 +606,7 @@ var toMergeability = (value) => {
596
606
  }
597
607
  };
598
608
  var toReviewDecision = (value) => {
599
- switch (text2(value)?.toUpperCase()) {
609
+ switch (text(value)?.toUpperCase()) {
600
610
  case "APPROVED":
601
611
  return "approved";
602
612
  case "CHANGES_REQUESTED":
@@ -608,9 +618,9 @@ var toReviewDecision = (value) => {
608
618
  }
609
619
  };
610
620
  var toCheckStatus = (raw) => {
611
- const status = text2(raw["status"])?.toUpperCase();
621
+ const status = text(raw["status"])?.toUpperCase();
612
622
  if (status !== void 0 && status !== "COMPLETED") return "pending";
613
- switch (text2(raw["conclusion"] ?? raw["state"])?.toUpperCase()) {
623
+ switch (text(raw["conclusion"] ?? raw["state"])?.toUpperCase()) {
614
624
  case "SUCCESS":
615
625
  return "success";
616
626
  case "FAILURE":
@@ -633,7 +643,7 @@ var toCheckStatus = (raw) => {
633
643
  };
634
644
  var UNSET_TIMESTAMP = "0001-01-01T00:00:00Z";
635
645
  var realTimestamp = (value) => {
636
- const stamp = text2(value);
646
+ const stamp = text(value);
637
647
  return stamp === null || stamp === UNSET_TIMESTAMP ? null : stamp;
638
648
  };
639
649
  var isAtLeastAsNew = (candidate, kept) => candidate === null ? kept === null : kept === null || candidate >= kept;
@@ -658,24 +668,24 @@ var toChecks = (contexts) => dedupeChecks(
658
668
  contexts.flatMap((entry) => {
659
669
  const raw = asObject2(entry);
660
670
  if (raw === null) return [];
661
- const name = text2(raw["name"]) ?? text2(raw["context"]);
671
+ const name = text(raw["name"]) ?? text(raw["context"]);
662
672
  if (name === null) return [];
663
673
  return [
664
674
  {
665
675
  check: {
666
676
  name,
667
677
  status: toCheckStatus(raw),
668
- description: text2(raw["description"]) ?? text2(raw["title"]),
669
- url: text2(raw["detailsUrl"]) ?? text2(raw["targetUrl"])
678
+ description: text(raw["description"]) ?? text(raw["title"]),
679
+ url: text(raw["detailsUrl"]) ?? text(raw["targetUrl"])
670
680
  },
671
- workflowName: text2(at(raw, "checkSuite", "workflowRun", "workflow", "name")),
681
+ workflowName: text(at(raw, "checkSuite", "workflowRun", "workflow", "name")),
672
682
  at: realTimestamp(raw["completedAt"]) ?? realTimestamp(raw["startedAt"])
673
683
  }
674
684
  ];
675
685
  })
676
686
  );
677
687
  var toChecksState = (value) => {
678
- switch (text2(value)?.toUpperCase()) {
688
+ switch (text(value)?.toUpperCase()) {
679
689
  case "FAILURE":
680
690
  case "ERROR":
681
691
  return "failing";
@@ -697,17 +707,17 @@ var checksStateFromChecks = (checks) => {
697
707
  };
698
708
  var toActor = (value) => {
699
709
  const raw = asObject2(value);
700
- const login = text2(raw?.["login"]);
701
- return login === null ? null : { login, name: text2(raw?.["name"]), avatarUrl: text2(raw?.["avatarUrl"]) };
710
+ const login = text(raw?.["login"]);
711
+ return login === null ? null : { login, name: text(raw?.["name"]), avatarUrl: text(raw?.["avatarUrl"]) };
702
712
  };
703
713
  var toCommitActor = (value) => {
704
714
  const raw = asObject2(value);
705
- const login = text2(at(raw, "user", "login")) ?? text2(raw?.["name"]);
706
- return login === null ? null : { login, name: text2(raw?.["name"]), avatarUrl: text2(raw?.["avatarUrl"]) };
715
+ const login = text(at(raw, "user", "login")) ?? text(raw?.["name"]);
716
+ return login === null ? null : { login, name: text(raw?.["name"]), avatarUrl: text(raw?.["avatarUrl"]) };
707
717
  };
708
718
  var toLabels = (value) => nodes(value).flatMap((entry) => {
709
- const name = text2(asObject2(entry)?.["name"]);
710
- return name === null ? [] : [{ name, color: text2(asObject2(entry)?.["color"]) }];
719
+ const name = text(asObject2(entry)?.["name"]);
720
+ return name === null ? [] : [{ name, color: text(asObject2(entry)?.["color"]) }];
711
721
  });
712
722
  var REACTORS_PER_GROUP = 10;
713
723
  var toReactions = (value, viewer) => {
@@ -716,10 +726,10 @@ var toReactions = (value, viewer) => {
716
726
  for (const entry of asArray(value)) {
717
727
  const group = asObject2(entry);
718
728
  if (group === null) continue;
719
- const content = REACTION_BY_GITHUB[text2(group["content"])?.toUpperCase() ?? ""];
729
+ const content = REACTION_BY_GITHUB[text(group["content"])?.toUpperCase() ?? ""];
720
730
  if (content === void 0) continue;
721
731
  const logins = nodes(group["reactors"]).flatMap(
722
- (node) => text2(asObject2(node)?.["login"]) ?? []
732
+ (node) => text(asObject2(node)?.["login"]) ?? []
723
733
  );
724
734
  const count = Math.max(
725
735
  int(at(group, "reactors", "totalCount")) ?? logins.length,
@@ -994,10 +1004,10 @@ var decodeFiles = (value) => {
994
1004
  let truncated = false;
995
1005
  for (const entry of value) {
996
1006
  const raw = asObject2(entry);
997
- const filename = text2(raw?.["filename"]);
1007
+ const filename = text(raw?.["filename"]);
998
1008
  if (filename === null) continue;
999
1009
  const hunks = typeof raw?.["patch"] === "string" ? raw["patch"] : "";
1000
- const status = text2(raw?.["status"])?.toLowerCase();
1010
+ const status = text(raw?.["status"])?.toLowerCase();
1001
1011
  if (hunks.length === 0) {
1002
1012
  const additions = int(raw?.["additions"]) ?? 0;
1003
1013
  const deletions = int(raw?.["deletions"]) ?? 0;
@@ -1006,7 +1016,7 @@ var decodeFiles = (value) => {
1006
1016
  omittedFileStats.push({ path: filename, additions, deletions });
1007
1017
  }
1008
1018
  }
1009
- const oldPath = status === "renamed" ? text2(raw?.["previous_filename"]) ?? filename : filename;
1019
+ const oldPath = status === "renamed" ? text(raw?.["previous_filename"]) ?? filename : filename;
1010
1020
  const header = [
1011
1021
  `diff --git a/${oldPath} b/${filename}`,
1012
1022
  // files 端点不报文件模式,用寻常那个顶上:查看器读这两行是"新增"和"删除",不是读模式。
@@ -1025,20 +1035,20 @@ ${hunks.replace(/\n?$/, "\n")}`);
1025
1035
  var decodeRevisions = (value, kind) => {
1026
1036
  const raw = asObject2(value);
1027
1037
  if (raw === null) return null;
1028
- return kind === "pull-request" ? { baseRef: text2(at(raw, "base", "sha")), headRef: text2(at(raw, "head", "sha")) } : { baseRef: text2(at(asArray(raw["parents"])[0], "sha")), headRef: text2(raw["sha"]) };
1038
+ return kind === "pull-request" ? { baseRef: text(at(raw, "base", "sha")), headRef: text(at(raw, "head", "sha")) } : { baseRef: text(at(asArray(raw["parents"])[0], "sha")), headRef: text(raw["sha"]) };
1029
1039
  };
1030
1040
 
1031
1041
  // src/githubMapping.ts
1032
- var decodeViewerLogin = (value) => text2(asObject2(value)?.["login"]);
1033
- var toReviewRequestLogins = (value) => nodes(value).flatMap((node) => text2(at(node, "requestedReviewer", "login")) ?? []);
1042
+ var decodeViewerLogin = (value) => text(asObject2(value)?.["login"]);
1043
+ var toReviewRequestLogins = (value) => nodes(value).flatMap((node) => text(at(node, "requestedReviewer", "login")) ?? []);
1034
1044
  var toRow = (raw) => {
1035
1045
  const number2 = int(raw["number"]);
1036
- const title = text2(raw["title"]);
1037
- const url = text2(raw["url"]);
1038
- const headBranch = text2(raw["headRefName"]);
1039
- const baseBranch = text2(raw["baseRefName"]);
1040
- const createdAt = text2(raw["createdAt"]);
1041
- const updatedAt = text2(raw["updatedAt"]);
1046
+ const title = text(raw["title"]);
1047
+ const url = text(raw["url"]);
1048
+ const headBranch = text(raw["headRefName"]);
1049
+ const baseBranch = text(raw["baseRefName"]);
1050
+ const createdAt = text(raw["createdAt"]);
1051
+ const updatedAt = text(raw["updatedAt"]);
1042
1052
  if (number2 === null || title === null || url === null || headBranch === null || baseBranch === null || createdAt === null || updatedAt === null) {
1043
1053
  return null;
1044
1054
  }
@@ -1074,7 +1084,7 @@ var decodeSearch = (value) => {
1074
1084
  if (node === null) continue;
1075
1085
  const row = toRow(node);
1076
1086
  if (row === null) continue;
1077
- items.push({ ...row, repository: text2(at(node, "repository", "nameWithOwner")) });
1087
+ items.push({ ...row, repository: text(at(node, "repository", "nameWithOwner")) });
1078
1088
  }
1079
1089
  return {
1080
1090
  items,
@@ -1089,22 +1099,22 @@ var decodeRestPullList = (value) => {
1089
1099
  const raw = asObject2(entry);
1090
1100
  if (raw === null) continue;
1091
1101
  const number2 = int(raw["number"]);
1092
- const title = text2(raw["title"]);
1093
- const url = text2(raw["html_url"]);
1094
- const headBranch = text2(at(raw, "head", "ref"));
1095
- const baseBranch = text2(at(raw, "base", "ref"));
1096
- const createdAt = text2(raw["created_at"]);
1097
- const updatedAt = text2(raw["updated_at"]);
1102
+ const title = text(raw["title"]);
1103
+ const url = text(raw["html_url"]);
1104
+ const headBranch = text(at(raw, "head", "ref"));
1105
+ const baseBranch = text(at(raw, "base", "ref"));
1106
+ const createdAt = text(raw["created_at"]);
1107
+ const updatedAt = text(raw["updated_at"]);
1098
1108
  if (number2 === null || title === null || url === null || headBranch === null || baseBranch === null || createdAt === null || updatedAt === null) {
1099
1109
  continue;
1100
1110
  }
1101
1111
  const author = asObject2(raw["user"]);
1102
- const login = text2(author?.["login"]);
1112
+ const login = text(author?.["login"]);
1103
1113
  items.push({
1104
1114
  number: number2,
1105
1115
  title,
1106
1116
  url,
1107
- author: login === null ? null : { login, name: null, avatarUrl: text2(author?.["avatar_url"]) },
1117
+ author: login === null ? null : { login, name: null, avatarUrl: text(author?.["avatar_url"]) },
1108
1118
  headBranch,
1109
1119
  baseBranch,
1110
1120
  state: toState({ state: raw["state"], mergedAt: raw["merged_at"] }),
@@ -1116,11 +1126,11 @@ var decodeRestPullList = (value) => {
1116
1126
  createdAt,
1117
1127
  updatedAt,
1118
1128
  reviewRequestLogins: asArray(raw["requested_reviewers"]).flatMap(
1119
- (reviewer) => text2(asObject2(reviewer)?.["login"]) ?? []
1129
+ (reviewer) => text(asObject2(reviewer)?.["login"]) ?? []
1120
1130
  ),
1121
1131
  labels: asArray(raw["labels"]).flatMap((label) => {
1122
- const name = text2(asObject2(label)?.["name"]);
1123
- return name === null ? [] : [{ name, color: text2(asObject2(label)?.["color"]) }];
1132
+ const name = text(asObject2(label)?.["name"]);
1133
+ return name === null ? [] : [{ name, color: text(asObject2(label)?.["color"]) }];
1124
1134
  }),
1125
1135
  checksState: null,
1126
1136
  hasTeamReviewRequest: asArray(raw["requested_teams"]).length > 0
@@ -1129,7 +1139,7 @@ var decodeRestPullList = (value) => {
1129
1139
  return { items, rawCount: value.length };
1130
1140
  };
1131
1141
  var toCanWrite = (value) => {
1132
- switch (text2(value)?.toUpperCase()) {
1142
+ switch (text(value)?.toUpperCase()) {
1133
1143
  case "ADMIN":
1134
1144
  case "MAINTAIN":
1135
1145
  case "WRITE":
@@ -1156,14 +1166,14 @@ var decodeDetail = (value) => {
1156
1166
  ...row,
1157
1167
  // 明细上有逐条检查,汇总就按它自己算,一个字和它下面那张表不会互相打脸。
1158
1168
  checksState: checksStateFromChecks(checks) ?? row.checksState,
1159
- body: text2(raw["body"]) === null ? "" : String(raw["body"]),
1169
+ body: text(raw["body"]) === null ? "" : String(raw["body"]),
1160
1170
  changedFiles: int(raw["changedFiles"]) ?? 0,
1161
- mergedAt: text2(raw["mergedAt"]),
1162
- closedAt: text2(raw["closedAt"]),
1171
+ mergedAt: text(raw["mergedAt"]),
1172
+ closedAt: text(raw["closedAt"]),
1163
1173
  reviewers: nodes(raw["reviewRequests"]).flatMap((node) => {
1164
1174
  const reviewer = asObject2(at(node, "requestedReviewer"));
1165
- const login = text2(reviewer?.["login"]) ?? text2(reviewer?.["slug"]);
1166
- return login === null ? [] : [{ login, name: text2(reviewer?.["name"]), avatarUrl: text2(reviewer?.["avatarUrl"]) }];
1175
+ const login = text(reviewer?.["login"]) ?? text(reviewer?.["slug"]);
1176
+ return login === null ? [] : [{ login, name: text(reviewer?.["name"]), avatarUrl: text(reviewer?.["avatarUrl"]) }];
1167
1177
  }),
1168
1178
  checks,
1169
1179
  autoMergeEnabled: asObject2(raw["autoMergeRequest"]) !== null
@@ -1178,7 +1188,7 @@ var decodeDetail = (value) => {
1178
1188
  ...toViewerFields(raw),
1179
1189
  canUpdateBranch: raw["viewerCanUpdateBranch"] === true
1180
1190
  },
1181
- headRepositoryOwner: text2(at(raw, "headRepositoryOwner", "login"))
1191
+ headRepositoryOwner: text(at(raw, "headRepositoryOwner", "login"))
1182
1192
  };
1183
1193
  };
1184
1194
  var decodeViewerAccess = (value) => {
@@ -1228,29 +1238,29 @@ var isReviewVerdict = (state) => {
1228
1238
  var rendersEmpty = (body) => body.replace(/<!--[\s\S]*?-->/g, "").trim().length === 0;
1229
1239
  var toThreadComment = (value, viewer) => {
1230
1240
  const raw = asObject2(value);
1231
- const id = text2(raw?.["id"]);
1232
- const createdAt = text2(raw?.["createdAt"]);
1241
+ const id = text(raw?.["id"]);
1242
+ const createdAt = text(raw?.["createdAt"]);
1233
1243
  if (id === null || createdAt === null) return null;
1234
1244
  return {
1235
1245
  id,
1236
1246
  author: toActor(raw?.["author"]),
1237
1247
  body: typeof raw?.["body"] === "string" ? raw["body"] : "",
1238
1248
  createdAt,
1239
- url: text2(raw?.["url"]),
1249
+ url: text(raw?.["url"]),
1240
1250
  reactions: toReactions(raw?.["reactionGroups"], viewer)
1241
1251
  };
1242
1252
  };
1243
1253
  var decodeActivity = (value) => {
1244
1254
  const raw = asObject2(at(value, "repository", "pullRequest"));
1245
1255
  if (raw === null) return null;
1246
- const viewer = text2(at(value, "viewer", "login"));
1256
+ const viewer = text(at(value, "viewer", "login"));
1247
1257
  const threadPage = raw["reviewThreads"];
1248
1258
  let threadsTruncated = false;
1249
1259
  const reviewThreads = [];
1250
1260
  for (const entry of nodes(threadPage)) {
1251
1261
  const thread = asObject2(entry);
1252
- const id = text2(thread?.["id"]);
1253
- const path2 = text2(thread?.["path"]);
1262
+ const id = text(thread?.["id"]);
1263
+ const path2 = text(thread?.["path"]);
1254
1264
  const comments2 = nodes(thread?.["comments"]).flatMap(
1255
1265
  (comment3) => toThreadComment(comment3, viewer) ?? []
1256
1266
  );
@@ -1263,7 +1273,7 @@ var decodeActivity = (value) => {
1263
1273
  // 线程那一行离开 diff 之后 GitHub 就报 null,那正是它 outdated 的时候。这种线程照列,
1264
1274
  // 但不再钉在一条它已经没有的行上。
1265
1275
  line: line !== null && line > 0 ? line : null,
1266
- side: text2(thread?.["diffSide"])?.toUpperCase() === "LEFT" ? "left" : "right",
1276
+ side: text(thread?.["diffSide"])?.toUpperCase() === "LEFT" ? "left" : "right",
1267
1277
  isResolved: thread?.["isResolved"] === true,
1268
1278
  isOutdated: thread?.["isOutdated"] === true,
1269
1279
  comments: comments2
@@ -1271,8 +1281,8 @@ var decodeActivity = (value) => {
1271
1281
  }
1272
1282
  const dismissals = /* @__PURE__ */ new Map();
1273
1283
  for (const entry of nodes(raw["reviewDismissals"])) {
1274
- const reviewId = text2(at(entry, "review", "id"));
1275
- const message = text2(asObject2(entry)?.["dismissalMessage"]);
1284
+ const reviewId = text(at(entry, "review", "id"));
1285
+ const message = text(asObject2(entry)?.["dismissalMessage"]);
1276
1286
  if (reviewId !== null && message !== null) dismissals.set(reviewId, message);
1277
1287
  }
1278
1288
  const issueComments = nodes(raw["comments"]).flatMap(
@@ -1283,9 +1293,9 @@ var decodeActivity = (value) => {
1283
1293
  );
1284
1294
  const reviews = nodes(raw["reviews"]).flatMap((entry) => {
1285
1295
  const review = asObject2(entry);
1286
- const id = text2(review?.["id"]);
1287
- const submittedAt = text2(review?.["submittedAt"]);
1288
- const reviewState = text2(review?.["state"]);
1296
+ const id = text(review?.["id"]);
1297
+ const submittedAt = text(review?.["submittedAt"]);
1298
+ const reviewState = text(review?.["state"]);
1289
1299
  const body = typeof review?.["body"] === "string" ? review["body"] : "";
1290
1300
  if (id === null || submittedAt === null) return [];
1291
1301
  if (body.trim().length === 0 && !isReviewVerdict(reviewState)) return [];
@@ -1299,7 +1309,7 @@ var decodeActivity = (value) => {
1299
1309
  // 出来什么都没有。
1300
1310
  body: reviewState?.toUpperCase() === "DISMISSED" && rendersEmpty(body) ? dismissals.get(id) ?? body : body,
1301
1311
  createdAt: submittedAt,
1302
- url: text2(review?.["url"]),
1312
+ url: text(review?.["url"]),
1303
1313
  path: null,
1304
1314
  reviewState,
1305
1315
  reactions: toReactions(review?.["reactionGroups"], viewer)
@@ -1331,15 +1341,15 @@ var decodeActivity = (value) => {
1331
1341
  }
1332
1342
  const commits = nodes(raw["commits"]).flatMap((entry) => {
1333
1343
  const commit = asObject2(at(entry, "commit"));
1334
- const oid = text2(commit?.["oid"]);
1335
- const committedDate = text2(commit?.["committedDate"]);
1344
+ const oid = text(commit?.["oid"]);
1345
+ const committedDate = text(commit?.["committedDate"]);
1336
1346
  if (oid === null || committedDate === null) return [];
1337
1347
  const additions = int(commit?.["additions"]);
1338
1348
  const deletions = int(commit?.["deletions"]);
1339
1349
  return [
1340
1350
  {
1341
1351
  oid,
1342
- messageHeadline: text2(commit?.["messageHeadline"]) ?? "",
1352
+ messageHeadline: text(commit?.["messageHeadline"]) ?? "",
1343
1353
  committedDate,
1344
1354
  ...additions === null ? {} : { additions: Math.max(0, additions) },
1345
1355
  ...deletions === null ? {} : { deletions: Math.max(0, deletions) },
@@ -1367,9 +1377,9 @@ var decodeActivity = (value) => {
1367
1377
  var decodeThreadComments = (value) => {
1368
1378
  const data = asObject2(value);
1369
1379
  if (data === null) return null;
1370
- const viewer = text2(at(data, "viewer", "login"));
1371
- const expected = text2(at(data, "repository", "pullRequest", "id"));
1372
- const actual = text2(at(data, "node", "pullRequest", "id"));
1380
+ const viewer = text(at(data, "viewer", "login"));
1381
+ const expected = text(at(data, "repository", "pullRequest", "id"));
1382
+ const actual = text(at(data, "node", "pullRequest", "id"));
1373
1383
  const comments = at(data, "node", "comments");
1374
1384
  return {
1375
1385
  belongsToPullRequest: expected !== null && actual !== null && expected === actual,
@@ -1377,43 +1387,43 @@ var decodeThreadComments = (value) => {
1377
1387
  nextCursor: nextCursorOf(comments)
1378
1388
  };
1379
1389
  };
1380
- var decodeNodeId = (value) => text2(at(value, "repository", "pullRequest", "id"));
1390
+ var decodeNodeId = (value) => text(at(value, "repository", "pullRequest", "id"));
1381
1391
  var decodeSubjectScope = (value) => {
1382
- const expected = text2(at(value, "repository", "pullRequest", "id"));
1392
+ const expected = text(at(value, "repository", "pullRequest", "id"));
1383
1393
  const node = asObject2(at(value, "node"));
1384
- const actual = node === null ? null : text2(at(node, "pullRequest", "id")) ?? text2(node["id"]);
1394
+ const actual = node === null ? null : text(at(node, "pullRequest", "id")) ?? text(node["id"]);
1385
1395
  return expected !== null && actual !== null && expected === actual;
1386
1396
  };
1387
1397
  var decodeReviewerCandidates = (value) => {
1388
1398
  const repository = asObject2(at(value, "repository"));
1389
1399
  if (repository === null) return null;
1390
1400
  const pullRequest = repository["pullRequest"];
1391
- const author = text2(at(pullRequest, "author", "login"));
1401
+ const author = text(at(pullRequest, "author", "login"));
1392
1402
  const candidates = /* @__PURE__ */ new Map();
1393
1403
  for (const entry of nodes(at(pullRequest, "reviewRequests"))) {
1394
1404
  const raw = asObject2(at(entry, "requestedReviewer"));
1395
1405
  const isTeam = raw?.["__typename"] === "Team";
1396
- const id = isTeam ? text2(raw?.["slug"]) : text2(raw?.["login"]);
1406
+ const id = isTeam ? text(raw?.["slug"]) : text(raw?.["login"]);
1397
1407
  if (id === null) continue;
1398
1408
  candidates.set(`${isTeam ? "team" : "user"} ${id}`, {
1399
1409
  id,
1400
1410
  kind: isTeam ? "team" : "user",
1401
1411
  login: id,
1402
- name: text2(raw?.["name"]),
1403
- avatarUrl: text2(raw?.["avatarUrl"]),
1412
+ name: text(raw?.["name"]),
1413
+ avatarUrl: text(raw?.["avatarUrl"]),
1404
1414
  isRequested: true
1405
1415
  });
1406
1416
  }
1407
1417
  const assignable = repository["assignableUsers"];
1408
1418
  for (const entry of nodes(assignable)) {
1409
- const login = text2(asObject2(entry)?.["login"]);
1419
+ const login = text(asObject2(entry)?.["login"]);
1410
1420
  if (login === null || login === author || candidates.has(`user ${login}`)) continue;
1411
1421
  candidates.set(`user ${login}`, {
1412
1422
  id: login,
1413
1423
  kind: "user",
1414
1424
  login,
1415
- name: text2(asObject2(entry)?.["name"]),
1416
- avatarUrl: text2(asObject2(entry)?.["avatarUrl"]),
1425
+ name: text(asObject2(entry)?.["name"]),
1426
+ avatarUrl: text(asObject2(entry)?.["avatarUrl"]),
1417
1427
  isRequested: false
1418
1428
  });
1419
1429
  }
@@ -2110,10 +2120,7 @@ var setReaction = async (ctx, input) => {
2110
2120
  };
2111
2121
 
2112
2122
  // src/gitlabHttp.ts
2113
- var DEFAULT_TIMEOUT_MS2 = 3e4;
2114
- var DEFAULT_MAX_BYTES2 = 1024 * 1024;
2115
2123
  var DEFAULT_HOST2 = "gitlab.com";
2116
- var CARD2 = "Settings \u2192 Plugins \u2192 Pull requests";
2117
2124
  var GitLabError = class extends Error {
2118
2125
  code;
2119
2126
  constructor(input) {
@@ -2122,38 +2129,14 @@ var GitLabError = class extends Error {
2122
2129
  this.code = input.code;
2123
2130
  }
2124
2131
  };
2125
- var text3 = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
2126
- var normalizeHost2 = (value) => value.trim().replace(/^https?:\/\//i, "").replace(/\/+$/, "").toLowerCase();
2127
- var configuredHost2 = (ctx) => normalizeHost2(text3(ctx.config["gitlabHost"]) ?? DEFAULT_HOST2);
2128
- var configuredToken2 = (ctx) => text3(ctx.config["gitlabToken"]);
2129
- var readBody2 = async (response, maxBytes) => {
2130
- const stream = response.body;
2131
- if (stream === null) return { body: "", truncated: false };
2132
- const reader = stream.getReader();
2133
- const decoder = new TextDecoder();
2134
- let body = "";
2135
- let read = 0;
2136
- for (; ; ) {
2137
- const chunk = await reader.read();
2138
- if (chunk.done) break;
2139
- const value = chunk.value;
2140
- if (value === void 0) continue;
2141
- if (read + value.byteLength > maxBytes) {
2142
- body += decoder.decode(value.subarray(0, maxBytes - read), { stream: true });
2143
- await reader.cancel();
2144
- return { body, truncated: true };
2145
- }
2146
- read += value.byteLength;
2147
- body += decoder.decode(value, { stream: true });
2148
- }
2149
- return { body: body + decoder.decode(), truncated: false };
2150
- };
2132
+ var configuredHost2 = (ctx) => normalizeHost(configText(ctx.config["gitlabHost"]) ?? DEFAULT_HOST2);
2133
+ var configuredToken2 = (ctx) => configText(ctx.config["gitlabToken"]);
2151
2134
  var statusError2 = (input) => {
2152
2135
  if (input.status === 401 || input.status === 403) {
2153
2136
  return new GitLabError({
2154
2137
  code: "unauthenticated",
2155
2138
  operation: input.operation,
2156
- detail: `GitLab refused the token (HTTP ${input.status}). Check the token and its \`api\` scope in ${CARD2}.`
2139
+ detail: `GitLab refused the token (HTTP ${input.status}). Check the token and its \`api\` scope in ${SETTINGS_CARD}.`
2157
2140
  });
2158
2141
  }
2159
2142
  if (input.status === 429) {
@@ -2169,63 +2152,28 @@ var statusError2 = (input) => {
2169
2152
  detail: `GitLab answered HTTP ${input.status}.`
2170
2153
  });
2171
2154
  };
2172
- var requestError2 = (operation, error) => {
2173
- const name = error instanceof Error ? error.name : "";
2174
- if (name === "TimeoutError" || name === "AbortError") {
2175
- return new GitLabError({
2176
- code: "failed",
2177
- operation,
2178
- detail: "GitLab did not answer before the timeout."
2179
- });
2180
- }
2181
- return new GitLabError({
2182
- code: "failed",
2183
- operation,
2184
- detail: error instanceof Error ? error.message : String(error)
2185
- });
2186
- };
2187
- var send2 = async (ctx, input) => {
2155
+ var send2 = (ctx, input) => {
2188
2156
  const host = configuredHost2(ctx);
2189
- const asked = input.host === void 0 ? null : normalizeHost2(input.host);
2190
- if (asked !== null && asked.length > 0 && asked !== host) {
2191
- throw new GitLabError({
2192
- code: "unauthenticated",
2193
- operation: input.operation,
2194
- detail: `This repository lives on ${asked}, but ${CARD2} is configured for ${host}.`
2195
- });
2196
- }
2197
- const token = configuredToken2(ctx);
2198
- if (token === null) {
2199
- throw new GitLabError({
2200
- code: "missing-tool",
2201
- operation: input.operation,
2202
- detail: `No GitLab token is configured. Add a personal access token with the \`api\` scope in ${CARD2}.`
2203
- });
2204
- }
2205
- let response;
2206
- try {
2207
- response = await ctx.http(input.url(`https://${host}`), {
2208
- method: input.method ?? "GET",
2209
- headers: { "PRIVATE-TOKEN": token, "Content-Type": "application/json" },
2210
- ...input.body === void 0 ? {} : { body: input.body },
2211
- signal: AbortSignal.timeout(input.timeoutMs ?? DEFAULT_TIMEOUT_MS2)
2212
- });
2213
- } catch (error) {
2214
- throw requestError2(input.operation, error);
2215
- }
2216
- if (!response.ok) {
2217
- await response.body?.cancel();
2218
- throw statusError2({
2157
+ return sendForgeHttp(ctx, {
2158
+ vendor: "GitLab",
2159
+ operation: input.operation,
2160
+ host,
2161
+ askedHost: input.host,
2162
+ token: configuredToken2(ctx),
2163
+ tokenScopeHint: "with the `api` scope",
2164
+ url: input.url(`https://${host}`),
2165
+ method: input.method,
2166
+ body: input.body,
2167
+ headers: (token) => ({ "PRIVATE-TOKEN": token, "Content-Type": "application/json" }),
2168
+ timeoutMs: input.timeoutMs,
2169
+ maxBytes: input.maxBytes,
2170
+ fail: (code, detail) => new GitLabError({ code, operation: input.operation, detail }),
2171
+ statusError: (status, headers) => statusError2({
2219
2172
  operation: input.operation,
2220
- status: response.status,
2221
- retryAfter: response.headers.get("Retry-After")
2222
- });
2223
- }
2224
- try {
2225
- return await readBody2(response, input.maxBytes ?? DEFAULT_MAX_BYTES2);
2226
- } catch (error) {
2227
- throw requestError2(input.operation, error);
2228
- }
2173
+ status,
2174
+ retryAfter: headers.get("Retry-After")
2175
+ })
2176
+ });
2229
2177
  };
2230
2178
  var callGitLabApi = (ctx, input) => send2(ctx, { ...input, url: (base) => `${base}/api/v4/${input.path}` });
2231
2179
  var callGitLabGraphQl = (ctx, input) => send2(ctx, { ...input, url: (base) => `${base}/api/graphql`, method: "POST" });
@@ -2238,7 +2186,7 @@ var readError2 = (operation, what) => new GitLabError({
2238
2186
  // src/gitlabMapping.ts
2239
2187
  var asObject3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
2240
2188
  var asArray2 = (value) => Array.isArray(value) ? value : null;
2241
- var text4 = (value) => {
2189
+ var text2 = (value) => {
2242
2190
  if (typeof value !== "string") return null;
2243
2191
  const trimmed = value.trim();
2244
2192
  return trimmed.length > 0 ? trimmed : null;
@@ -2255,15 +2203,15 @@ var parseJson = (raw) => {
2255
2203
  };
2256
2204
  var toActor2 = (value) => {
2257
2205
  const raw = asObject3(value);
2258
- const login = text4(raw?.username);
2259
- return login === null ? null : { login, name: text4(raw?.name), avatarUrl: text4(raw?.avatar_url) };
2206
+ const login = text2(raw?.username);
2207
+ return login === null ? null : { login, name: text2(raw?.name), avatarUrl: text2(raw?.avatar_url) };
2260
2208
  };
2261
2209
  var toLabels2 = (value) => (asArray2(value) ?? []).flatMap((entry) => {
2262
- const name = text4(entry);
2210
+ const name = text2(entry);
2263
2211
  return name === null ? [] : [{ name, color: null }];
2264
2212
  });
2265
2213
  var toPipelineStatus = (value) => {
2266
- switch (text4(value)?.toLowerCase()) {
2214
+ switch (text2(value)?.toLowerCase()) {
2267
2215
  case "success":
2268
2216
  return "success";
2269
2217
  case "failed":
@@ -2288,14 +2236,14 @@ var toChecks2 = (raw) => {
2288
2236
  {
2289
2237
  name: "Pipeline",
2290
2238
  status: toPipelineStatus(pipeline.status),
2291
- description: text4(pipeline.source),
2292
- url: text4(pipeline.web_url)
2239
+ description: text2(pipeline.source),
2240
+ url: text2(pipeline.web_url)
2293
2241
  }
2294
2242
  ];
2295
2243
  };
2296
2244
  var toState2 = (raw) => {
2297
- if (text4(raw.merged_at) !== null) return "merged";
2298
- switch (text4(raw.state)?.toLowerCase()) {
2245
+ if (text2(raw.merged_at) !== null) return "merged";
2246
+ switch (text2(raw.state)?.toLowerCase()) {
2299
2247
  case "merged":
2300
2248
  return "merged";
2301
2249
  case "closed":
@@ -2306,7 +2254,7 @@ var toState2 = (raw) => {
2306
2254
  };
2307
2255
  var toMergeability2 = (raw) => {
2308
2256
  if (bool(raw.has_conflicts) === true) return "conflicting";
2309
- switch (text4(raw.merge_status)?.toLowerCase()) {
2257
+ switch (text2(raw.merge_status)?.toLowerCase()) {
2310
2258
  case "can_be_merged":
2311
2259
  return "mergeable";
2312
2260
  case "cannot_be_merged":
@@ -2316,7 +2264,7 @@ var toMergeability2 = (raw) => {
2316
2264
  }
2317
2265
  };
2318
2266
  var toChangedFiles = (value) => {
2319
- const parsed = Number.parseInt(text4(value) ?? "", 10);
2267
+ const parsed = Number.parseInt(text2(value) ?? "", 10);
2320
2268
  return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
2321
2269
  };
2322
2270
  var toListItem = (value) => {
@@ -2347,7 +2295,7 @@ var toListItem = (value) => {
2347
2295
  createdAt,
2348
2296
  updatedAt,
2349
2297
  reviewRequestLogins: (asArray2(raw.reviewers) ?? []).flatMap((reviewer) => {
2350
- const login = text4(asObject3(reviewer)?.username);
2298
+ const login = text2(asObject3(reviewer)?.username);
2351
2299
  return login === null ? [] : [login];
2352
2300
  }),
2353
2301
  labels: toLabels2(raw.labels)
@@ -2367,8 +2315,8 @@ var decodeMergeRequestDetail = (raw) => {
2367
2315
  ...listItem,
2368
2316
  body: rawText(parsed.description) ?? "",
2369
2317
  changedFiles: toChangedFiles(parsed.changes_count),
2370
- mergedAt: text4(parsed.merged_at),
2371
- closedAt: text4(parsed.closed_at),
2318
+ mergedAt: text2(parsed.merged_at),
2319
+ closedAt: text2(parsed.closed_at),
2372
2320
  // 从 reviewer 对象本身建,头像才不会丢。
2373
2321
  reviewers: reviewers.flatMap((reviewer) => {
2374
2322
  const actor = toActor2(reviewer);
@@ -2399,7 +2347,7 @@ var decodeMergeRequestList = (raw) => {
2399
2347
  };
2400
2348
  var decodeViewer = (raw) => {
2401
2349
  const parsed = asObject3(parseJson(raw));
2402
- return parsed === null ? null : { username: text4(parsed.username) };
2350
+ return parsed === null ? null : { username: text2(parsed.username) };
2403
2351
  };
2404
2352
  var decodeProjectUsers = (raw) => {
2405
2353
  const entries = asArray2(parseJson(raw));
@@ -2417,8 +2365,8 @@ var decodeProjectUsers = (raw) => {
2417
2365
  var decodeProjectMergeCapabilities = (raw) => {
2418
2366
  const parsed = asObject3(parseJson(raw));
2419
2367
  if (parsed === null) return null;
2420
- const mergeMethod = text4(parsed.merge_method)?.toLowerCase();
2421
- const squashOption = text4(parsed.squash_option)?.toLowerCase();
2368
+ const mergeMethod = text2(parsed.merge_method)?.toLowerCase();
2369
+ const squashOption = text2(parsed.squash_option)?.toLowerCase();
2422
2370
  return {
2423
2371
  merge: mergeMethod === "merge",
2424
2372
  // 半线性与 fast-forward 两种历史都是把分支 rebase 到目标上得到的。
@@ -2441,12 +2389,12 @@ var decodeNotes = (raw) => {
2441
2389
  const position = asObject3(note.position);
2442
2390
  comments.push({
2443
2391
  id: String(id),
2444
- kind: text4(note.type) === "DiffNote" ? "review-comment" : "issue-comment",
2392
+ kind: text2(note.type) === "DiffNote" ? "review-comment" : "issue-comment",
2445
2393
  author: toActor2(note.author),
2446
2394
  body,
2447
2395
  createdAt,
2448
2396
  url: null,
2449
- path: text4(position?.new_path) ?? text4(position?.old_path),
2397
+ path: text2(position?.new_path) ?? text2(position?.old_path),
2450
2398
  reviewState: null
2451
2399
  });
2452
2400
  }
@@ -2458,7 +2406,7 @@ var decodeDiscussions = (raw) => {
2458
2406
  const threads = [];
2459
2407
  for (const entry of entries) {
2460
2408
  const discussion = asObject3(entry);
2461
- const id = text4(discussion?.id);
2409
+ const id = text2(discussion?.id);
2462
2410
  if (discussion === null || id === null) continue;
2463
2411
  const notes = (asArray2(discussion.notes) ?? []).flatMap((value) => {
2464
2412
  const note = asObject3(value);
@@ -2469,12 +2417,12 @@ var decodeDiscussions = (raw) => {
2469
2417
  });
2470
2418
  const root = notes[0];
2471
2419
  const position = asObject3(root?.note.position);
2472
- if (root === void 0 || position === null || text4(position.position_type) !== "text") {
2420
+ if (root === void 0 || position === null || text2(position.position_type) !== "text") {
2473
2421
  continue;
2474
2422
  }
2475
2423
  const newLine = int2(position.new_line);
2476
2424
  const side = newLine === null ? "left" : "right";
2477
- const path2 = text4(side === "left" ? position.old_path : position.new_path);
2425
+ const path2 = text2(side === "left" ? position.old_path : position.new_path);
2478
2426
  if (path2 === null) continue;
2479
2427
  const line = side === "left" ? int2(position.old_line) : newLine;
2480
2428
  threads.push({
@@ -2505,12 +2453,12 @@ var decodeCommits = (raw) => {
2505
2453
  const commits = [];
2506
2454
  for (const entry of entries) {
2507
2455
  const commit = asObject3(entry);
2508
- const oid = text4(commit?.id);
2456
+ const oid = text2(commit?.id);
2509
2457
  if (commit === null || oid === null) continue;
2510
- const committedDate = text4(commit.committed_date) ?? text4(commit.created_at);
2458
+ const committedDate = text2(commit.committed_date) ?? text2(commit.created_at);
2511
2459
  if (committedDate === null) continue;
2512
2460
  const stats = asObject3(commit.stats);
2513
- const login = text4(commit.author_name) ?? text4(commit.author_email);
2461
+ const login = text2(commit.author_name) ?? text2(commit.author_email);
2514
2462
  commits.push({
2515
2463
  oid,
2516
2464
  messageHeadline: rawText(commit.title) ?? "",
@@ -2519,7 +2467,7 @@ var decodeCommits = (raw) => {
2519
2467
  additions: Math.max(0, int2(stats.additions) ?? 0),
2520
2468
  deletions: Math.max(0, int2(stats.deletions) ?? 0)
2521
2469
  },
2522
- authors: login === null ? [] : [{ login, name: text4(commit.author_name), avatarUrl: null }]
2470
+ authors: login === null ? [] : [{ login, name: text2(commit.author_name), avatarUrl: null }]
2523
2471
  });
2524
2472
  }
2525
2473
  return commits.toReversed();
@@ -2594,9 +2542,9 @@ var toReactions2 = (value, viewer) => {
2594
2542
  const normalizedViewer = viewer?.toLowerCase() ?? null;
2595
2543
  const groups = /* @__PURE__ */ new Map();
2596
2544
  for (const node of asArray2(asObject3(value)?.nodes) ?? []) {
2597
- const content = CONTENT_BY_GITLAB_AWARD[text4(asObject3(node)?.name)?.toLowerCase() ?? ""];
2545
+ const content = CONTENT_BY_GITLAB_AWARD[text2(asObject3(node)?.name)?.toLowerCase() ?? ""];
2598
2546
  if (content === void 0) continue;
2599
- const username = text4(asObject3(asObject3(node)?.user)?.username);
2547
+ const username = text2(asObject3(asObject3(node)?.user)?.username);
2600
2548
  if (username === null) continue;
2601
2549
  const group = groups.get(content) ?? { count: 0, actors: [], viewer: false };
2602
2550
  group.count++;
@@ -2612,13 +2560,13 @@ var toReactions2 = (value, viewer) => {
2612
2560
  );
2613
2561
  };
2614
2562
  var noteIdOf = (value) => {
2615
- const id = text4(value)?.split("/").at(-1);
2563
+ const id = text2(value)?.split("/").at(-1);
2616
2564
  return id !== void 0 && /^\d+$/.test(id) ? id : null;
2617
2565
  };
2618
2566
  var decodeAwardEmoji = (raw) => {
2619
2567
  const data = asObject3(asObject3(parseJson(raw))?.data);
2620
2568
  if (data === null) return null;
2621
- const viewer = text4(asObject3(data.currentUser)?.username);
2569
+ const viewer = text2(asObject3(data.currentUser)?.username);
2622
2570
  const mergeRequest = asObject3(asObject3(data.project)?.mergeRequest);
2623
2571
  const notes = asObject3(mergeRequest?.notes);
2624
2572
  const reactionsByNoteId = /* @__PURE__ */ new Map();
@@ -2632,7 +2580,7 @@ var decodeAwardEmoji = (raw) => {
2632
2580
  return {
2633
2581
  reactions: toReactions2(mergeRequest?.awardEmoji, viewer),
2634
2582
  reactionsByNoteId,
2635
- nextCursor: bool(pageInfo?.hasNextPage) === true ? text4(pageInfo?.endCursor) : null
2583
+ nextCursor: bool(pageInfo?.hasNextPage) === true ? text2(pageInfo?.endCursor) : null
2636
2584
  };
2637
2585
  };
2638
2586
  var decodeOwnAwardId = (raw, input) => {
@@ -2643,8 +2591,8 @@ var decodeOwnAwardId = (raw, input) => {
2643
2591
  const award = asObject3(entry);
2644
2592
  const id = int2(award?.id);
2645
2593
  if (award === null || id === null) continue;
2646
- if (text4(award.name)?.toLowerCase() !== name) continue;
2647
- if (text4(asObject3(award.user)?.username) !== input.viewer) continue;
2594
+ if (text2(award.name)?.toLowerCase() !== name) continue;
2595
+ if (text2(asObject3(award.user)?.username) !== input.viewer) continue;
2648
2596
  return { awardId: id };
2649
2597
  }
2650
2598
  return { awardId: null };