@brain-toolkit/issue-forge 0.1.0 → 0.1.1

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.
@@ -1,87 +1,10 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/feedback/index.ts
31
- var feedback_exports = {};
32
- __export(feedback_exports, {
33
- FEEDBACK_ISSUE_ASSETS_BRANCH: () => FEEDBACK_ISSUE_ASSETS_BRANCH,
34
- FEEDBACK_ISSUE_ASSETS_DIR: () => FEEDBACK_ISSUE_ASSETS_DIR,
35
- FEEDBACK_ISSUE_ASSETS_README: () => FEEDBACK_ISSUE_ASSETS_README,
36
- FEEDBACK_ISSUE_DEFAULT_TEMPLATE: () => FEEDBACK_ISSUE_DEFAULT_TEMPLATE,
37
- FEEDBACK_ISSUE_DEFAULT_TITLE: () => FEEDBACK_ISSUE_DEFAULT_TITLE,
38
- FEEDBACK_ISSUE_TEMPLATE_PATH: () => FEEDBACK_ISSUE_TEMPLATE_PATH,
39
- FeedbackIssueScreenshotSyncEngine: () => FeedbackIssueScreenshotSyncEngine,
40
- FeedbackIssueStatus: () => FeedbackIssueStatus,
41
- FeedbackIssueStatusResolver: () => FeedbackIssueStatusResolver,
42
- FeedbackIssueStatusSyncEngine: () => FeedbackIssueStatusSyncEngine,
43
- FeedbackIssueSyncEngine: () => FeedbackIssueSyncEngine,
44
- FeedbackIssueSyncStatus: () => FeedbackIssueSyncStatus,
45
- FeedbackIssueTemplateRenderer: () => FeedbackIssueTemplateRenderer,
46
- FeedbackIssueTemplateResolver: () => FeedbackIssueTemplateResolver,
47
- FeedbackIssueTemplateSource: () => FeedbackIssueTemplateSource,
48
- createGithubFeedbackIssueBundle: () => createGithubFeedbackIssueBundle
49
- });
50
- module.exports = __toCommonJS(feedback_exports);
51
-
52
- // src/feedback/types.ts
53
- var FeedbackIssueSyncStatus = {
54
- pending: "pending",
55
- synced: "synced",
56
- failed: "failed",
57
- skipped: "skipped"
58
- };
59
- var FeedbackIssueStatus = {
60
- open: "open",
61
- reviewing: "reviewing",
62
- resolved: "resolved",
63
- closed: "closed"
64
- };
65
-
66
- // src/feedback/FeedbackIssueTemplateConfig.ts
67
- var FeedbackIssueTemplateSource = Object.freeze({
68
- repo: "repo",
69
- builtin: "builtin"
70
- });
71
- var FEEDBACK_ISSUE_TEMPLATE_PATH = ".github/ISSUE_TEMPLATE/feedback.md";
72
- var FEEDBACK_ISSUE_TEMPLATE_CACHE_TTL_MS = 10 * 60 * 1e3;
73
- var FEEDBACK_ISSUE_TEMPLATE_FAILURE_TTL_MS = 60 * 1e3;
74
- var FEEDBACK_ISSUE_DEFAULT_TITLE = "[Feedback][{{category}}] {{summary}}";
75
- var FEEDBACK_ISSUE_ASSETS_BRANCH = "feedback-assets";
76
- var FEEDBACK_ISSUE_ASSETS_DIR = "feedback";
77
- var FEEDBACK_ISSUE_ASSETS_README = `# feedback-assets
1
+ "use strict";var H=Object.create;var w=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var V=(n,e)=>{for(var t in e)w(n,t,{get:e[t],enumerable:!0})},$=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of j(e))!W.call(n,r)&&r!==t&&w(n,r,{get:()=>e[r],enumerable:!(s=K(e,r))||s.enumerable});return n};var z=(n,e,t)=>(t=n!=null?H(q(n)):{},$(e||!n||!n.__esModule?w(t,"default",{value:n,enumerable:!0}):t,n)),J=n=>$(w({},"__esModule",{value:!0}),n);var ne={};V(ne,{FEEDBACK_ISSUE_ASSETS_BRANCH:()=>y,FEEDBACK_ISSUE_ASSETS_DIR:()=>R,FEEDBACK_ISSUE_ASSETS_README:()=>P,FEEDBACK_ISSUE_DEFAULT_TEMPLATE:()=>G,FEEDBACK_ISSUE_DEFAULT_TITLE:()=>_,FEEDBACK_ISSUE_TEMPLATE_PATH:()=>C,FeedbackIssueScreenshotSyncEngine:()=>F,FeedbackIssueStatus:()=>m,FeedbackIssueStatusResolver:()=>I,FeedbackIssueStatusSyncEngine:()=>S,FeedbackIssueSyncEngine:()=>T,FeedbackIssueSyncStatus:()=>c,FeedbackIssueTemplateRenderer:()=>g,FeedbackIssueTemplateResolver:()=>f,FeedbackIssueTemplateSource:()=>E,createGithubFeedbackIssueBundle:()=>D});module.exports=J(ne);var c={pending:"pending",synced:"synced",failed:"failed",skipped:"skipped"},m={open:"open",reviewing:"reviewing",resolved:"resolved",closed:"closed"};var E=Object.freeze({repo:"repo",builtin:"builtin"}),C=".github/ISSUE_TEMPLATE/feedback.md",L=600*1e3,O=60*1e3,_="[Feedback][{{category}}] {{summary}}",y="feedback-assets",R="feedback",P=`# feedback-assets
78
2
 
79
3
  Feedback screenshots uploaded by the app backend for Issue references.
80
4
 
81
5
  - Do not merge into main
82
6
  - May contain user screenshots; keep the branch private if needed
83
- `;
84
- var FEEDBACK_ISSUE_DEFAULT_TEMPLATE = `---
7
+ `,G=`---
85
8
  name: User feedback
86
9
  about: App user feedback (server also uses this template; placeholders replaced server-side)
87
10
  title: "[Feedback][{{category}}] {{summary}}"
@@ -116,796 +39,6 @@ labels: feedback
116
39
  {{screenshots}}
117
40
 
118
41
  {{user_agent}}
119
- `;
120
-
121
- // src/feedback/FeedbackIssueTemplateRenderer.ts
122
- var TITLE_MAX = 256;
123
- var PLACEHOLDER_PATTERN = /\{\{\s*([a-z_]+)\s*\}\}/g;
124
- var FeedbackIssueTemplateRenderer = class {
125
- render(template, variables) {
126
- return template.replace(PLACEHOLDER_PATTERN, (_m, key) => {
127
- return Object.prototype.hasOwnProperty.call(variables, key) ? variables[key] ?? "" : `{{${key}}}`;
128
- });
129
- }
130
- buildIssue(template, variables, extraLabels = []) {
131
- const titleTemplate = template.title.trim() || FEEDBACK_ISSUE_DEFAULT_TITLE;
132
- const title = Array.from(
133
- this.render(titleTemplate, variables).replace(/\s+/g, " ").trim()
134
- ).slice(0, TITLE_MAX).join("");
135
- return {
136
- title,
137
- body: this.render(template.body, variables).trim(),
138
- labels: [.../* @__PURE__ */ new Set([...template.labels, ...extraLabels])]
139
- };
140
- }
141
- };
142
-
143
- // src/github/GithubAppClient.ts
144
- var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
145
-
146
- // src/errors/IssueForgeError.ts
147
- var IssueForgeError = class extends Error {
148
- code = "ISSUE_FORGE_FAILED";
149
- /** HTTP 状态码;网络错误等无响应时为 null */
150
- status;
151
- constructor(message, status) {
152
- super(message);
153
- this.name = "IssueForgeError";
154
- this.status = status;
155
- }
156
- };
157
-
158
- // src/github/GithubAppClient.ts
159
- var APP_JWT_TTL_SEC = 9 * 60;
160
- var TOKEN_REFRESH_MARGIN_MS = 2 * 60 * 1e3;
161
-
162
- // src/github/GithubAppRepoContentGateway.ts
163
- var ACCEPT_RAW = "application/vnd.github.raw+json";
164
- var GithubAppRepoContentGateway = class {
165
- constructor(client, config) {
166
- this.client = client;
167
- this.config = config;
168
- }
169
- /**
170
- * @override
171
- */
172
- async readTextFile(path) {
173
- const response = await this.client.request(
174
- this.config,
175
- this.contentsPath(path),
176
- { method: "GET", accept: ACCEPT_RAW }
177
- );
178
- if (response.status === 404) {
179
- return null;
180
- }
181
- if (!response.ok) {
182
- throw await this.client.toError("read file", response);
183
- }
184
- return response.text();
185
- }
186
- /**
187
- * @override
188
- */
189
- async hasFile(path, branch) {
190
- const response = await this.client.request(
191
- this.config,
192
- `${this.contentsPath(path)}?ref=${encodeURIComponent(branch)}`,
193
- { method: "GET" }
194
- );
195
- if (response.status === 404) {
196
- return false;
197
- }
198
- if (!response.ok) {
199
- throw await this.client.toError("has file", response);
200
- }
201
- return true;
202
- }
203
- /**
204
- * @override
205
- */
206
- async ensureBranch(branch, initialFile) {
207
- const found = await this.client.request(
208
- this.config,
209
- `${this.repoPath()}/git/ref/heads/${this.encodePath(branch)}`,
210
- { method: "GET" }
211
- );
212
- if (found.ok) {
213
- return;
214
- }
215
- if (found.status !== 404) {
216
- throw await this.client.toError("get branch", found);
217
- }
218
- const treeSha = await this.postForSha("create tree", "/git/trees", {
219
- tree: [
220
- {
221
- path: initialFile.path,
222
- mode: "100644",
223
- type: "blob",
224
- content: initialFile.content
225
- }
226
- ]
227
- });
228
- const commitSha = await this.postForSha("create commit", "/git/commits", {
229
- message: `chore: \u521D\u59CB\u5316 ${branch} \u5206\u652F`,
230
- tree: treeSha,
231
- parents: []
232
- });
233
- const created = await this.client.request(
234
- this.config,
235
- `${this.repoPath()}/git/refs`,
236
- {
237
- method: "POST",
238
- body: { ref: `refs/heads/${branch}`, sha: commitSha }
239
- }
240
- );
241
- if (!created.ok && created.status !== 422) {
242
- throw await this.client.toError("create branch", created);
243
- }
244
- }
245
- /**
246
- * @override
247
- */
248
- async uploadFile(input) {
249
- const response = await this.client.request(
250
- this.config,
251
- this.contentsPath(input.path),
252
- {
253
- method: "PUT",
254
- body: {
255
- message: input.message,
256
- content: input.contentBase64,
257
- branch: input.branch
258
- }
259
- }
260
- );
261
- if (response.ok) {
262
- const json = await response.json();
263
- return { url: this.requireHtmlUrl(json.content?.html_url, response) };
264
- }
265
- if (response.status === 422) {
266
- return this.readExisting(input);
267
- }
268
- throw await this.client.toError("upload file", response);
269
- }
270
- async readExisting(input) {
271
- const response = await this.client.request(
272
- this.config,
273
- `${this.contentsPath(input.path)}?ref=${encodeURIComponent(input.branch)}`,
274
- { method: "GET" }
275
- );
276
- if (!response.ok) {
277
- throw await this.client.toError("upload file", response);
278
- }
279
- const json = await response.json();
280
- return { url: this.requireHtmlUrl(json.html_url, response) };
281
- }
282
- async postForSha(stage, path, body) {
283
- const response = await this.client.request(
284
- this.config,
285
- `${this.repoPath()}${path}`,
286
- { method: "POST", body }
287
- );
288
- if (!response.ok) {
289
- throw await this.client.toError(stage, response);
290
- }
291
- const json = await response.json();
292
- if (typeof json.sha !== "string" || !json.sha) {
293
- throw new IssueForgeError(
294
- `${stage}: unexpected response`,
295
- response.status
296
- );
297
- }
298
- return json.sha;
299
- }
300
- requireHtmlUrl(value, response) {
301
- if (typeof value !== "string" || !value) {
302
- throw new IssueForgeError(
303
- "upload file: unexpected response",
304
- response.status
305
- );
306
- }
307
- return value;
308
- }
309
- contentsPath(path) {
310
- return `${this.repoPath()}/contents/${this.encodePath(path)}`;
311
- }
312
- encodePath(path) {
313
- return path.split("/").filter((segment) => segment.length > 0).map((segment) => encodeURIComponent(segment)).join("/");
314
- }
315
- repoPath() {
316
- return `/repos/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}`;
317
- }
318
- };
319
-
320
- // src/github/GithubAppIssueForgeGateway.ts
321
- var COMMENTS_PAGE_SIZE = 100;
322
- var GithubAppIssueForgeGateway = class {
323
- constructor(client, config) {
324
- this.client = client;
325
- this.config = config;
326
- this.assets = new GithubAppRepoContentGateway(client, config);
327
- }
328
- assets;
329
- /**
330
- * @override
331
- */
332
- async createIssue(input) {
333
- const first = await this.postIssue(input, input.labels);
334
- if (first.ok) {
335
- return this.readCreated(first);
336
- }
337
- if (first.status === 422 && input.labels.length > 0) {
338
- const retry = await this.postIssue(input, []);
339
- if (retry.ok) {
340
- return this.readCreated(retry);
341
- }
342
- throw await this.client.toError("create issue", retry);
343
- }
344
- throw await this.client.toError("create issue", first);
345
- }
346
- /**
347
- * @override
348
- */
349
- async createComment(issue, body) {
350
- const response = await this.client.request(
351
- this.config,
352
- `${this.repoPath()}/issues/${String(issue.issueNumber)}/comments`,
353
- { method: "POST", body: { body } }
354
- );
355
- if (!response.ok) {
356
- throw await this.client.toError("create comment", response);
357
- }
358
- }
359
- /**
360
- * @override
361
- */
362
- async listComments(issue) {
363
- const comments = [];
364
- let page = 1;
365
- for (; ; ) {
366
- const response = await this.client.request(
367
- this.config,
368
- `${this.repoPath()}/issues/${String(issue.issueNumber)}/comments?per_page=${String(COMMENTS_PAGE_SIZE)}&page=${String(page)}`,
369
- { method: "GET" }
370
- );
371
- if (!response.ok) {
372
- throw await this.client.toError("list comments", response);
373
- }
374
- const json = await response.json();
375
- for (const item of json) {
376
- if (typeof item.body === "string") {
377
- comments.push({ body: item.body });
378
- }
379
- }
380
- if (json.length < COMMENTS_PAGE_SIZE) {
381
- break;
382
- }
383
- page += 1;
384
- }
385
- return comments;
386
- }
387
- /**
388
- * @override
389
- */
390
- async uploadAsset(input) {
391
- const branch = input.branch?.trim() || "feedback-assets";
392
- await this.assets.uploadFile({
393
- path: input.path,
394
- contentBase64: input.contentBase64,
395
- branch,
396
- message: input.message?.trim() || `chore(feedback): upload ${input.path}`
397
- });
398
- const encodedPath = input.path.split("/").filter((segment) => segment.length > 0).map((segment) => encodeURIComponent(segment)).join("/");
399
- return {
400
- url: `https://github.com/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}/raw/${encodeURIComponent(branch)}/${encodedPath}`
401
- };
402
- }
403
- postIssue(input, labels) {
404
- return this.client.request(this.config, `${this.repoPath()}/issues`, {
405
- method: "POST",
406
- body: {
407
- title: input.title,
408
- body: input.body,
409
- ...labels.length > 0 ? { labels: [...labels] } : {}
410
- }
411
- });
412
- }
413
- async readCreated(response) {
414
- const json = await response.json();
415
- if (typeof json.number !== "number" || typeof json.html_url !== "string") {
416
- throw new IssueForgeError(
417
- "create issue: unexpected response",
418
- response.status
419
- );
420
- }
421
- return {
422
- issueNumber: json.number,
423
- issueUrl: json.html_url,
424
- ...typeof json.node_id === "string" ? { resourceKey: json.node_id } : {}
425
- };
426
- }
427
- repoPath() {
428
- return `/repos/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}`;
429
- }
430
- };
431
-
432
- // src/github/createGithubAppForge.ts
433
- function createGithubAppIssueForge(client, config) {
434
- return new GithubAppIssueForgeGateway(client, config);
435
- }
436
- function createGithubAppRepoContent(client, config) {
437
- return new GithubAppRepoContentGateway(client, config);
438
- }
439
-
440
- // src/feedback/FeedbackIssueTemplateResolver.ts
441
- var FeedbackIssueTemplateResolver = class {
442
- client;
443
- cache;
444
- logger;
445
- defaultTemplate;
446
- constructor(options) {
447
- this.client = options.client;
448
- this.cache = options.cache;
449
- this.logger = options.logger;
450
- this.defaultTemplate = options.defaultTemplate ?? FEEDBACK_ISSUE_DEFAULT_TEMPLATE;
451
- }
452
- async resolve(config) {
453
- const raw = await this.loadRaw(config);
454
- if (raw) {
455
- const template = this.parse(raw, FeedbackIssueTemplateSource.repo);
456
- if (template.body) {
457
- return template;
458
- }
459
- }
460
- return this.parse(
461
- this.defaultTemplate,
462
- FeedbackIssueTemplateSource.builtin
463
- );
464
- }
465
- async loadRaw(config) {
466
- const cacheKey = `issue-forge:feedback:issue-template:${config.owner}/${config.repo}`;
467
- const cached = await this.cache.getItem(cacheKey);
468
- if (cached) {
469
- return cached.raw;
470
- }
471
- try {
472
- const content = createGithubAppRepoContent(this.client, config);
473
- const raw = await content.readTextFile(FEEDBACK_ISSUE_TEMPLATE_PATH);
474
- await this.cache.setItem(
475
- cacheKey,
476
- { raw },
477
- { ttlMs: FEEDBACK_ISSUE_TEMPLATE_CACHE_TTL_MS }
478
- );
479
- return raw;
480
- } catch (error) {
481
- this.logger?.warn("feedback issue template load failed", {
482
- message: error instanceof Error ? error.message : String(error)
483
- });
484
- await this.cache.setItem(
485
- cacheKey,
486
- { raw: null },
487
- { ttlMs: FEEDBACK_ISSUE_TEMPLATE_FAILURE_TTL_MS }
488
- );
489
- return null;
490
- }
491
- }
492
- parse(raw, source) {
493
- const trimmed = raw.replace(/^\uFEFF/, "").trim();
494
- if (!trimmed.startsWith("---")) {
495
- return { title: "", labels: ["feedback"], body: trimmed, source };
496
- }
497
- const end = trimmed.indexOf("\n---", 3);
498
- if (end < 0) {
499
- return { title: "", labels: ["feedback"], body: trimmed, source };
500
- }
501
- const front = trimmed.slice(3, end).trim();
502
- const body = trimmed.slice(end + 4).replace(/^\r?\n/, "");
503
- const meta = this.parseFrontMatter(front);
504
- const title = typeof meta.title === "string" ? meta.title : Array.isArray(meta.title) ? meta.title[0] ?? "" : "";
505
- const labelsRaw = meta.labels;
506
- const labels = Array.isArray(labelsRaw) ? labelsRaw.map(String) : typeof labelsRaw === "string" ? labelsRaw.split(",").map((s) => s.trim()).filter(Boolean) : ["feedback"];
507
- return { title, labels, body, source };
508
- }
509
- parseFrontMatter(front) {
510
- const out = {};
511
- for (const line of front.split(/\r?\n/)) {
512
- const idx = line.indexOf(":");
513
- if (idx < 0) continue;
514
- const key = line.slice(0, idx).trim();
515
- let value = line.slice(idx + 1).trim();
516
- if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
517
- value = value.slice(1, -1);
518
- }
519
- if (key === "labels" && value.includes(",")) {
520
- out[key] = value.split(",").map((s) => s.trim()).filter(Boolean);
521
- } else {
522
- out[key] = value;
523
- }
524
- }
525
- return out;
526
- }
527
- };
528
-
529
- // src/feedback/FeedbackIssueStatusResolver.ts
530
- var ISSUE_ACTION_CLOSED = "closed";
531
- var ISSUE_ACTION_REOPENED = "reopened";
532
- var REASON_NOT_PLANNED = "not_planned";
533
- var REASON_DUPLICATE = "duplicate";
534
- var FeedbackIssueStatusResolver = class {
535
- resolve(event) {
536
- if (event.action === ISSUE_ACTION_REOPENED) {
537
- return FeedbackIssueStatus.open;
538
- }
539
- if (event.action !== ISSUE_ACTION_CLOSED) {
540
- return null;
541
- }
542
- const reason = event.issue.state_reason ?? null;
543
- if (reason === REASON_NOT_PLANNED || reason === REASON_DUPLICATE) {
544
- return FeedbackIssueStatus.closed;
545
- }
546
- return FeedbackIssueStatus.resolved;
547
- }
548
- };
549
-
550
- // src/feedback/FeedbackIssueSyncEngine.ts
551
- var FeedbackIssueSyncEngine = class {
552
- host;
553
- client;
554
- templateResolver;
555
- renderer;
556
- screenshotSync;
557
- logger;
558
- constructor(options) {
559
- this.host = options.host;
560
- this.client = options.client;
561
- this.templateResolver = options.templateResolver;
562
- this.renderer = options.renderer;
563
- this.screenshotSync = options.screenshotSync;
564
- this.logger = options.logger;
565
- }
566
- async syncFeedback(feedbackId, options = {}) {
567
- const content = await this.host.resolveIssueContent(feedbackId);
568
- if (!content) {
569
- return FeedbackIssueSyncStatus.skipped;
570
- }
571
- if (content.issueNumber !== null) {
572
- await this.screenshotSync.syncScreenshots(feedbackId, options);
573
- return FeedbackIssueSyncStatus.synced;
574
- }
575
- const auth = await this.host.resolveForgeAuth(options);
576
- if (!auth) {
577
- await this.host.updateSync(feedbackId, {
578
- status: FeedbackIssueSyncStatus.skipped,
579
- issueNumber: null,
580
- issueUrl: null,
581
- error: null
582
- });
583
- return FeedbackIssueSyncStatus.skipped;
584
- }
585
- try {
586
- const template = await this.templateResolver.resolve(auth);
587
- const forge = createGithubAppIssueForge(this.client, auth);
588
- const created = await forge.createIssue(
589
- this.renderer.buildIssue(
590
- template,
591
- content.variables,
592
- content.labels ?? []
593
- )
594
- );
595
- await this.host.updateSync(feedbackId, {
596
- status: FeedbackIssueSyncStatus.synced,
597
- issueNumber: created.issueNumber,
598
- issueUrl: created.issueUrl,
599
- error: null
600
- });
601
- } catch (error) {
602
- const message = error instanceof Error ? error.message : String(error);
603
- this.logger?.error("feedback github sync failed", {
604
- feedbackId,
605
- message
606
- });
607
- await this.host.updateSync(feedbackId, {
608
- status: FeedbackIssueSyncStatus.failed,
609
- issueNumber: null,
610
- issueUrl: null,
611
- error: message
612
- });
613
- return FeedbackIssueSyncStatus.failed;
614
- }
615
- await this.screenshotSync.syncScreenshots(feedbackId, options);
616
- return FeedbackIssueSyncStatus.synced;
617
- }
618
- };
619
-
620
- // src/feedback/FeedbackIssueScreenshotSyncEngine.ts
621
- var ISSUE_NUMBER_RETRY_DELAYS_MS = [
622
- 200,
623
- 400,
624
- 800,
625
- 800,
626
- 800
627
- ];
628
- var SCREENSHOT_ERROR_PREFIX = "screenshot: ";
629
- var FeedbackIssueScreenshotSyncEngine = class _FeedbackIssueScreenshotSyncEngine {
630
- host;
631
- client;
632
- logger;
633
- sleep;
634
- constructor(options) {
635
- this.host = options.host;
636
- this.client = options.client;
637
- this.logger = options.logger;
638
- this.sleep = options.sleep ?? ((ms) => new Promise((resolve) => {
639
- setTimeout(resolve, ms);
640
- }));
641
- }
642
- /**
643
- * 本地已清理后:用落库的 GitHub raw URL 检查 Issue 评论,缺失则补发(不碰 Storage)。
644
- */
645
- async ensureGithubScreenshotComments(feedbackId, options = {}) {
646
- const state = await this.host.findScreenshotState(feedbackId);
647
- if (!state || state.issueNumber === null || state.githubUrls.length === 0) {
648
- return 0;
649
- }
650
- const auth = await this.host.resolveForgeAuth(options);
651
- if (!auth) {
652
- return 0;
653
- }
654
- const issueNumber = state.issueNumber;
655
- const urls = state.githubUrls;
656
- try {
657
- const forge = createGithubAppIssueForge(this.client, auth);
658
- const comments = await forge.listComments({ issueNumber });
659
- const alreadyPosted = urls.every(
660
- (url) => comments.some((comment) => comment.body.includes(url))
661
- );
662
- if (alreadyPosted) {
663
- return 0;
664
- }
665
- await forge.createComment(
666
- { issueNumber },
667
- this.host.formatScreenshotComment(urls, 0)
668
- );
669
- await this.host.updateSync(feedbackId, {
670
- status: FeedbackIssueSyncStatus.synced,
671
- issueNumber,
672
- issueUrl: state.issueUrl,
673
- error: null
674
- });
675
- return urls.length;
676
- } catch (error) {
677
- const message = error instanceof Error ? error.message : String(error);
678
- this.logger?.error("feedback screenshot comment ensure failed", {
679
- feedbackId,
680
- message
681
- });
682
- await this.host.updateSync(feedbackId, {
683
- status: FeedbackIssueSyncStatus.synced,
684
- issueNumber,
685
- issueUrl: state.issueUrl,
686
- error: `${SCREENSHOT_ERROR_PREFIX}${message}`
687
- }).catch(() => void 0);
688
- return 0;
689
- }
690
- }
691
- async syncScreenshots(feedbackId, options = {}) {
692
- let state = await this.host.findScreenshotState(feedbackId);
693
- if (!state || state.paths.length <= state.postedCount) {
694
- return 0;
695
- }
696
- if (state.issueNumber === null) {
697
- state = await this.waitForIssueNumber(feedbackId, state);
698
- if (!state || state.issueNumber === null || state.paths.length <= state.postedCount) {
699
- this.logger?.warn("feedback screenshot sync skipped: issue not ready", {
700
- feedbackId
701
- });
702
- return 0;
703
- }
704
- }
705
- const auth = await this.host.resolveForgeAuth(options);
706
- if (!auth) {
707
- return 0;
708
- }
709
- const issueNumber = state.issueNumber;
710
- const from = state.postedCount;
711
- const to = state.paths.length;
712
- const claimed = await this.host.compareAndSetScreenshotCount(
713
- feedbackId,
714
- from,
715
- to
716
- );
717
- if (!claimed) {
718
- return 0;
719
- }
720
- const localPaths = state.paths.slice(from);
721
- try {
722
- const urls = await this.uploadScreenshots(auth, feedbackId, localPaths);
723
- const forge = createGithubAppIssueForge(this.client, auth);
724
- const comments = await forge.listComments({ issueNumber });
725
- const alreadyPosted = urls.every(
726
- (url) => comments.some((comment) => comment.body.includes(url))
727
- );
728
- if (!alreadyPosted) {
729
- await forge.createComment(
730
- { issueNumber },
731
- this.host.formatScreenshotComment(urls, from)
732
- );
733
- }
734
- await this.host.updateSync(feedbackId, {
735
- status: FeedbackIssueSyncStatus.synced,
736
- issueNumber,
737
- issueUrl: state.issueUrl,
738
- error: null
739
- });
740
- await this.host.releaseLocalScreenshotsAfterGithub(feedbackId, urls, localPaths).catch((cleanupError) => {
741
- const message = cleanupError instanceof Error ? cleanupError.message : String(cleanupError);
742
- this.logger?.error("feedback screenshot local cleanup failed", {
743
- feedbackId,
744
- message
745
- });
746
- });
747
- return urls.length;
748
- } catch (error) {
749
- const message = error instanceof Error ? error.message : String(error);
750
- this.logger?.error("feedback screenshot sync failed", {
751
- feedbackId,
752
- message
753
- });
754
- await this.host.compareAndSetScreenshotCount(feedbackId, to, from).catch(() => false);
755
- await this.host.updateSync(feedbackId, {
756
- status: FeedbackIssueSyncStatus.synced,
757
- issueNumber,
758
- issueUrl: state.issueUrl,
759
- error: `${SCREENSHOT_ERROR_PREFIX}${message}`
760
- }).catch(() => void 0);
761
- return 0;
762
- }
763
- }
764
- /**
765
- * 私有仓 Issue Markdown 可渲染的 raw URL(同源 cookie,避免 raw.githubusercontent.com)。
766
- */
767
- static buildRawAssetUrl(auth, branch, path) {
768
- const encodedPath = path.split("/").filter((segment) => segment.length > 0).map((segment) => encodeURIComponent(segment)).join("/");
769
- return `https://github.com/${encodeURIComponent(auth.owner)}/${encodeURIComponent(auth.repo)}/raw/${encodeURIComponent(branch)}/${encodedPath}`;
770
- }
771
- async waitForIssueNumber(feedbackId, initial) {
772
- let latest = initial;
773
- for (const delayMs of ISSUE_NUMBER_RETRY_DELAYS_MS) {
774
- await this.sleep(delayMs);
775
- latest = await this.host.findScreenshotState(feedbackId);
776
- if (latest?.issueNumber !== null && latest?.issueNumber !== void 0) {
777
- return latest;
778
- }
779
- }
780
- return latest;
781
- }
782
- async uploadScreenshots(auth, feedbackId, objectPaths) {
783
- const content = createGithubAppRepoContent(this.client, auth);
784
- await content.ensureBranch(FEEDBACK_ISSUE_ASSETS_BRANCH, {
785
- path: "README.md",
786
- content: FEEDBACK_ISSUE_ASSETS_README
787
- });
788
- const urls = [];
789
- for (const [index, objectPath] of objectPaths.entries()) {
790
- const fileName = objectPath.split("/").pop() || `${String(index)}.jpg`;
791
- const repoPath = `${FEEDBACK_ISSUE_ASSETS_DIR}/${feedbackId}/${fileName}`;
792
- const alreadyOnBranch = await content.hasFile(
793
- repoPath,
794
- FEEDBACK_ISSUE_ASSETS_BRANCH
795
- );
796
- if (!alreadyOnBranch) {
797
- const bytes = await this.host.downloadScreenshot(objectPath);
798
- await content.uploadFile({
799
- branch: FEEDBACK_ISSUE_ASSETS_BRANCH,
800
- path: repoPath,
801
- contentBase64: bytes.toString("base64"),
802
- message: `chore(feedback): feedback ${feedbackId} screenshot`
803
- });
804
- }
805
- urls.push(
806
- _FeedbackIssueScreenshotSyncEngine.buildRawAssetUrl(
807
- auth,
808
- FEEDBACK_ISSUE_ASSETS_BRANCH,
809
- repoPath
810
- )
811
- );
812
- }
813
- return urls;
814
- }
815
- };
816
-
817
- // src/feedback/FeedbackIssueStatusSyncEngine.ts
818
- var FeedbackIssueStatusSyncEngine = class {
819
- host;
820
- statusResolver;
821
- logger;
822
- constructor(options) {
823
- this.host = options.host;
824
- this.statusResolver = options.statusResolver ?? new FeedbackIssueStatusResolver();
825
- this.logger = options.logger;
826
- }
827
- async applyIssueEvent(event) {
828
- const status = this.statusResolver.resolve(event);
829
- if (status === null) {
830
- return 0;
831
- }
832
- if (!await this.isFeedbackRepo(event.repository.full_name)) {
833
- this.logger?.warn("feedback status sync skipped: repo mismatch", {
834
- repo: event.repository.full_name
835
- });
836
- return 0;
837
- }
838
- const updated = await this.host.updateStatusByIssueNumber(
839
- event.issue.number,
840
- status
841
- );
842
- if (updated > 0) {
843
- this.logger?.info("feedback status synced from github issue", {
844
- issueNumber: event.issue.number,
845
- action: event.action,
846
- status,
847
- updated
848
- });
849
- }
850
- return updated;
851
- }
852
- async isFeedbackRepo(fullName) {
853
- const repo = await this.host.getFeedbackRepoFullName();
854
- return repo.toLowerCase() === fullName.trim().toLowerCase();
855
- }
856
- };
857
-
858
- // src/feedback/createGithubFeedbackIssueBundle.ts
859
- function createGithubFeedbackIssueBundle(options) {
860
- const renderer = new FeedbackIssueTemplateRenderer();
861
- const templateResolver = new FeedbackIssueTemplateResolver({
862
- client: options.client,
863
- cache: options.cache,
864
- logger: options.logger,
865
- defaultTemplate: options.defaultTemplate
866
- });
867
- const screenshots = new FeedbackIssueScreenshotSyncEngine({
868
- host: options.host,
869
- client: options.client,
870
- logger: options.logger
871
- });
872
- const sync = new FeedbackIssueSyncEngine({
873
- host: options.host,
874
- client: options.client,
875
- templateResolver,
876
- renderer,
877
- screenshotSync: screenshots,
878
- logger: options.logger
879
- });
880
- const status = new FeedbackIssueStatusSyncEngine({
881
- host: options.host,
882
- logger: options.logger
883
- });
884
- return {
885
- sync,
886
- screenshots,
887
- status,
888
- renderer,
889
- templateResolver
890
- };
891
- }
892
- // Annotate the CommonJS export names for ESM import in node:
893
- 0 && (module.exports = {
894
- FEEDBACK_ISSUE_ASSETS_BRANCH,
895
- FEEDBACK_ISSUE_ASSETS_DIR,
896
- FEEDBACK_ISSUE_ASSETS_README,
897
- FEEDBACK_ISSUE_DEFAULT_TEMPLATE,
898
- FEEDBACK_ISSUE_DEFAULT_TITLE,
899
- FEEDBACK_ISSUE_TEMPLATE_PATH,
900
- FeedbackIssueScreenshotSyncEngine,
901
- FeedbackIssueStatus,
902
- FeedbackIssueStatusResolver,
903
- FeedbackIssueStatusSyncEngine,
904
- FeedbackIssueSyncEngine,
905
- FeedbackIssueSyncStatus,
906
- FeedbackIssueTemplateRenderer,
907
- FeedbackIssueTemplateResolver,
908
- FeedbackIssueTemplateSource,
909
- createGithubFeedbackIssueBundle
910
- });
42
+ `;var X=256,Y=/\{\{\s*([a-z_]+)\s*\}\}/g,g=class{render(e,t){return e.replace(Y,(s,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]??"":`{{${r}}}`)}buildIssue(e,t,s=[]){let r=e.title.trim()||_;return{title:Array.from(this.render(r,t).replace(/\s+/g," ").trim()).slice(0,X).join(""),body:this.render(e.body,t).trim(),labels:[...new Set([...e.labels,...s])]}}};var Q=z(require("jsonwebtoken"),1);var h=class extends Error{code="ISSUE_FORGE_FAILED";status;constructor(e,t){super(e),this.name="IssueForgeError",this.status=t}};var ye=120*1e3;var Z="application/vnd.github.raw+json",b=class{constructor(e,t){this.client=e;this.config=t}async readTextFile(e){let t=await this.client.request(this.config,this.contentsPath(e),{method:"GET",accept:Z});if(t.status===404)return null;if(!t.ok)throw await this.client.toError("read file",t);return t.text()}async hasFile(e,t){let s=await this.client.request(this.config,`${this.contentsPath(e)}?ref=${encodeURIComponent(t)}`,{method:"GET"});if(s.status===404)return!1;if(!s.ok)throw await this.client.toError("has file",s);return!0}async ensureBranch(e,t){let s=await this.client.request(this.config,`${this.repoPath()}/git/ref/heads/${this.encodePath(e)}`,{method:"GET"});if(s.ok)return;if(s.status!==404)throw await this.client.toError("get branch",s);let r=await this.postForSha("create tree","/git/trees",{tree:[{path:t.path,mode:"100644",type:"blob",content:t.content}]}),o=await this.postForSha("create commit","/git/commits",{message:`chore: \u521D\u59CB\u5316 ${e} \u5206\u652F`,tree:r,parents:[]}),a=await this.client.request(this.config,`${this.repoPath()}/git/refs`,{method:"POST",body:{ref:`refs/heads/${e}`,sha:o}});if(!a.ok&&a.status!==422)throw await this.client.toError("create branch",a)}async uploadFile(e){let t=await this.client.request(this.config,this.contentsPath(e.path),{method:"PUT",body:{message:e.message,content:e.contentBase64,branch:e.branch}});if(t.ok){let s=await t.json();return{url:this.requireHtmlUrl(s.content?.html_url,t)}}if(t.status===422)return this.readExisting(e);throw await this.client.toError("upload file",t)}async readExisting(e){let t=await this.client.request(this.config,`${this.contentsPath(e.path)}?ref=${encodeURIComponent(e.branch)}`,{method:"GET"});if(!t.ok)throw await this.client.toError("upload file",t);let s=await t.json();return{url:this.requireHtmlUrl(s.html_url,t)}}async postForSha(e,t,s){let r=await this.client.request(this.config,`${this.repoPath()}${t}`,{method:"POST",body:s});if(!r.ok)throw await this.client.toError(e,r);let o=await r.json();if(typeof o.sha!="string"||!o.sha)throw new h(`${e}: unexpected response`,r.status);return o.sha}requireHtmlUrl(e,t){if(typeof e!="string"||!e)throw new h("upload file: unexpected response",t.status);return e}contentsPath(e){return`${this.repoPath()}/contents/${this.encodePath(e)}`}encodePath(e){return e.split("/").filter(t=>t.length>0).map(t=>encodeURIComponent(t)).join("/")}repoPath(){return`/repos/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}`}};var B=100,U=class{constructor(e,t){this.client=e;this.config=t;this.assets=new b(e,t)}assets;async createIssue(e){let t=await this.postIssue(e,e.labels);if(t.ok)return this.readCreated(t);if(t.status===422&&e.labels.length>0){let s=await this.postIssue(e,[]);if(s.ok)return this.readCreated(s);throw await this.client.toError("create issue",s)}throw await this.client.toError("create issue",t)}async createComment(e,t){let s=await this.client.request(this.config,`${this.repoPath()}/issues/${String(e.issueNumber)}/comments`,{method:"POST",body:{body:t}});if(!s.ok)throw await this.client.toError("create comment",s)}async listComments(e){let t=[],s=1;for(;;){let r=await this.client.request(this.config,`${this.repoPath()}/issues/${String(e.issueNumber)}/comments?per_page=${String(B)}&page=${String(s)}`,{method:"GET"});if(!r.ok)throw await this.client.toError("list comments",r);let o=await r.json();for(let a of o)typeof a.body=="string"&&t.push({body:a.body});if(o.length<B)break;s+=1}return t}async uploadAsset(e){let t=e.branch?.trim()||"feedback-assets";await this.assets.uploadFile({path:e.path,contentBase64:e.contentBase64,branch:t,message:e.message?.trim()||`chore(feedback): upload ${e.path}`});let s=e.path.split("/").filter(r=>r.length>0).map(r=>encodeURIComponent(r)).join("/");return{url:`https://github.com/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}/raw/${encodeURIComponent(t)}/${s}`}}postIssue(e,t){return this.client.request(this.config,`${this.repoPath()}/issues`,{method:"POST",body:{title:e.title,body:e.body,...t.length>0?{labels:[...t]}:{}}})}async readCreated(e){let t=await e.json();if(typeof t.number!="number"||typeof t.html_url!="string")throw new h("create issue: unexpected response",e.status);return{issueNumber:t.number,issueUrl:t.html_url,...typeof t.node_id=="string"?{resourceKey:t.node_id}:{}}}repoPath(){return`/repos/${encodeURIComponent(this.config.owner)}/${encodeURIComponent(this.config.repo)}`}};function A(n,e){return new U(n,e)}function x(n,e){return new b(n,e)}var f=class{client;cache;logger;defaultTemplate;constructor(e){this.client=e.client,this.cache=e.cache,this.logger=e.logger,this.defaultTemplate=e.defaultTemplate??G}async resolve(e){let t=await this.loadRaw(e);if(t){let s=this.parse(t,E.repo);if(s.body)return s}return this.parse(this.defaultTemplate,E.builtin)}async loadRaw(e){let t=`issue-forge:feedback:issue-template:${e.owner}/${e.repo}`,s=await this.cache.getItem(t);if(s)return s.raw;try{let o=await x(this.client,e).readTextFile(C);return await this.cache.setItem(t,{raw:o},{ttlMs:L}),o}catch(r){return this.logger?.warn("feedback issue template load failed",{message:r instanceof Error?r.message:String(r)}),await this.cache.setItem(t,{raw:null},{ttlMs:O}),null}}parse(e,t){let s=e.replace(/^\uFEFF/,"").trim();if(!s.startsWith("---"))return{title:"",labels:["feedback"],body:s,source:t};let r=s.indexOf(`
43
+ ---`,3);if(r<0)return{title:"",labels:["feedback"],body:s,source:t};let o=s.slice(3,r).trim(),a=s.slice(r+4).replace(/^\r?\n/,""),i=this.parseFrontMatter(o),d=typeof i.title=="string"?i.title:Array.isArray(i.title)?i.title[0]??"":"",u=i.labels,p=Array.isArray(u)?u.map(String):typeof u=="string"?u.split(",").map(l=>l.trim()).filter(Boolean):["feedback"];return{title:d,labels:p,body:a,source:t}}parseFrontMatter(e){let t={};for(let s of e.split(/\r?\n/)){let r=s.indexOf(":");if(r<0)continue;let o=s.slice(0,r).trim(),a=s.slice(r+1).trim();(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),o==="labels"&&a.includes(",")?t[o]=a.split(",").map(i=>i.trim()).filter(Boolean):t[o]=a}return t}};var ee="closed",te="reopened",se="not_planned",re="duplicate",I=class{resolve(e){if(e.action===te)return m.open;if(e.action!==ee)return null;let t=e.issue.state_reason??null;return t===se||t===re?m.closed:m.resolved}};var T=class{host;client;templateResolver;renderer;screenshotSync;logger;constructor(e){this.host=e.host,this.client=e.client,this.templateResolver=e.templateResolver,this.renderer=e.renderer,this.screenshotSync=e.screenshotSync,this.logger=e.logger}async syncFeedback(e,t={}){let s=await this.host.resolveIssueContent(e);if(!s)return c.skipped;if(s.issueNumber!==null)return await this.screenshotSync.syncScreenshots(e,t),c.synced;let r=await this.host.resolveForgeAuth(t);if(!r)return await this.host.updateSync(e,{status:c.skipped,issueNumber:null,issueUrl:null,error:null}),c.skipped;try{let o=await this.templateResolver.resolve(r),i=await A(this.client,r).createIssue(this.renderer.buildIssue(o,s.variables,s.labels??[]));await this.host.updateSync(e,{status:c.synced,issueNumber:i.issueNumber,issueUrl:i.issueUrl,error:null})}catch(o){let a=o instanceof Error?o.message:String(o);return this.logger?.error("feedback github sync failed",{feedbackId:e,message:a}),await this.host.updateSync(e,{status:c.failed,issueNumber:null,issueUrl:null,error:a}),c.failed}return await this.screenshotSync.syncScreenshots(e,t),c.synced}};var oe=[200,400,800,800,800],N="screenshot: ",F=class n{host;client;logger;sleep;constructor(e){this.host=e.host,this.client=e.client,this.logger=e.logger,this.sleep=e.sleep??(t=>new Promise(s=>{setTimeout(s,t)}))}async ensureGithubScreenshotComments(e,t={}){let s=await this.host.findScreenshotState(e);if(!s||s.issueNumber===null||s.githubUrls.length===0)return 0;let r=await this.host.resolveForgeAuth(t);if(!r)return 0;let o=s.issueNumber,a=s.githubUrls;try{let i=A(this.client,r),d=await i.listComments({issueNumber:o});return a.every(p=>d.some(l=>l.body.includes(p)))?0:(await i.createComment({issueNumber:o},this.host.formatScreenshotComment(a,0)),await this.host.updateSync(e,{status:c.synced,issueNumber:o,issueUrl:s.issueUrl,error:null}),a.length)}catch(i){let d=i instanceof Error?i.message:String(i);return this.logger?.error("feedback screenshot comment ensure failed",{feedbackId:e,message:d}),await this.host.updateSync(e,{status:c.synced,issueNumber:o,issueUrl:s.issueUrl,error:`${N}${d}`}).catch(()=>{}),0}}async syncScreenshots(e,t={}){let s=await this.host.findScreenshotState(e);if(!s||s.paths.length<=s.postedCount)return 0;if(s.issueNumber===null&&(s=await this.waitForIssueNumber(e,s),!s||s.issueNumber===null||s.paths.length<=s.postedCount))return this.logger?.warn("feedback screenshot sync skipped: issue not ready",{feedbackId:e}),0;let r=await this.host.resolveForgeAuth(t);if(!r)return 0;let o=s.issueNumber,a=s.postedCount,i=s.paths.length;if(!await this.host.compareAndSetScreenshotCount(e,a,i))return 0;let u=s.paths.slice(a);try{let p=await this.uploadScreenshots(r,e,u),l=A(this.client,r),M=await l.listComments({issueNumber:o});return p.every(k=>M.some(v=>v.body.includes(k)))||await l.createComment({issueNumber:o},this.host.formatScreenshotComment(p,a)),await this.host.updateSync(e,{status:c.synced,issueNumber:o,issueUrl:s.issueUrl,error:null}),await this.host.releaseLocalScreenshotsAfterGithub(e,p,u).catch(k=>{let v=k instanceof Error?k.message:String(k);this.logger?.error("feedback screenshot local cleanup failed",{feedbackId:e,message:v})}),p.length}catch(p){let l=p instanceof Error?p.message:String(p);return this.logger?.error("feedback screenshot sync failed",{feedbackId:e,message:l}),await this.host.compareAndSetScreenshotCount(e,i,a).catch(()=>!1),await this.host.updateSync(e,{status:c.synced,issueNumber:o,issueUrl:s.issueUrl,error:`${N}${l}`}).catch(()=>{}),0}}static buildRawAssetUrl(e,t,s){let r=s.split("/").filter(o=>o.length>0).map(o=>encodeURIComponent(o)).join("/");return`https://github.com/${encodeURIComponent(e.owner)}/${encodeURIComponent(e.repo)}/raw/${encodeURIComponent(t)}/${r}`}async waitForIssueNumber(e,t){let s=t;for(let r of oe)if(await this.sleep(r),s=await this.host.findScreenshotState(e),s?.issueNumber!==null&&s?.issueNumber!==void 0)return s;return s}async uploadScreenshots(e,t,s){let r=x(this.client,e);await r.ensureBranch(y,{path:"README.md",content:P});let o=[];for(let[a,i]of s.entries()){let d=i.split("/").pop()||`${String(a)}.jpg`,u=`${R}/${t}/${d}`;if(!await r.hasFile(u,y)){let l=await this.host.downloadScreenshot(i);await r.uploadFile({branch:y,path:u,contentBase64:l.toString("base64"),message:`chore(feedback): feedback ${t} screenshot`})}o.push(n.buildRawAssetUrl(e,y,u))}return o}};var S=class{host;statusResolver;logger;constructor(e){this.host=e.host,this.statusResolver=e.statusResolver??new I,this.logger=e.logger}async applyIssueEvent(e){let t=this.statusResolver.resolve(e);if(t===null)return 0;if(!await this.isFeedbackRepo(e.repository.full_name))return this.logger?.warn("feedback status sync skipped: repo mismatch",{repo:e.repository.full_name}),0;let s=await this.host.updateStatusByIssueNumber(e.issue.number,t);return s>0&&this.logger?.info("feedback status synced from github issue",{issueNumber:e.issue.number,action:e.action,status:t,updated:s}),s}async isFeedbackRepo(e){return(await this.host.getFeedbackRepoFullName()).toLowerCase()===e.trim().toLowerCase()}};function D(n){let e=new g,t=new f({client:n.client,cache:n.cache,logger:n.logger,defaultTemplate:n.defaultTemplate}),s=new F({host:n.host,client:n.client,logger:n.logger}),r=new T({host:n.host,client:n.client,templateResolver:t,renderer:e,screenshotSync:s,logger:n.logger}),o=new S({host:n.host,logger:n.logger});return{sync:r,screenshots:s,status:o,renderer:e,templateResolver:t}}0&&(module.exports={FEEDBACK_ISSUE_ASSETS_BRANCH,FEEDBACK_ISSUE_ASSETS_DIR,FEEDBACK_ISSUE_ASSETS_README,FEEDBACK_ISSUE_DEFAULT_TEMPLATE,FEEDBACK_ISSUE_DEFAULT_TITLE,FEEDBACK_ISSUE_TEMPLATE_PATH,FeedbackIssueScreenshotSyncEngine,FeedbackIssueStatus,FeedbackIssueStatusResolver,FeedbackIssueStatusSyncEngine,FeedbackIssueSyncEngine,FeedbackIssueSyncStatus,FeedbackIssueTemplateRenderer,FeedbackIssueTemplateResolver,FeedbackIssueTemplateSource,createGithubFeedbackIssueBundle});
911
44
  //# sourceMappingURL=index.cjs.map