revdeck 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/daemon.js CHANGED
@@ -702,6 +702,33 @@ rename to ${newPath}
702
702
  const endpoint = `projects/${this.projectRef}/repository/files/${encodeURIComponent(path12)}/raw`;
703
703
  return this.call([query(endpoint, { ref })]);
704
704
  }
705
+ async readiness() {
706
+ const errors = [];
707
+ let checks = [];
708
+ let approvals = null;
709
+ try {
710
+ const pipelines = await this.json([query(this.endpoint("/pipelines"), { per_page: 1 })]);
711
+ const pipeline = Array.isArray(pipelines) ? pipelines[0] : void 0;
712
+ if (pipeline) {
713
+ const status = pipeline.status === "success" ? "success" : pipeline.status === "failed" ? "failed" : pipeline.status === "running" || pipeline.status === "pending" || pipeline.status === "created" ? "pending" : pipeline.status === "canceled" ? "skipped" : "neutral";
714
+ checks = [{ id: String(pipeline.id), name: `Pipeline #${pipeline.id}`, status, url: pipeline.web_url ?? null }];
715
+ }
716
+ } catch (error) {
717
+ errors.push(`pipeline: ${messageOf(error)}`);
718
+ }
719
+ try {
720
+ const data = await this.json([this.endpoint("/approvals")]);
721
+ const required = Number(data.approvals_required);
722
+ approvals = {
723
+ approved: (data.approved_by ?? []).length,
724
+ required: Number.isFinite(required) ? required : null,
725
+ changesRequested: 0
726
+ };
727
+ } catch (error) {
728
+ errors.push(`approvals: ${messageOf(error)}`);
729
+ }
730
+ return { checks, approvals, errors, checkedAt: (/* @__PURE__ */ new Date()).toISOString() };
731
+ }
705
732
  async threads() {
706
733
  const discussions = await this.paged(this.endpoint("/discussions"));
707
734
  const threads = [];
@@ -825,6 +852,21 @@ rename to ${newPath}
825
852
  async reactToReview(emoji) {
826
853
  return this.toggleAward(this.endpoint("/award_emoji"), emoji);
827
854
  }
855
+ async submitReview(input) {
856
+ const note = await withTempJson(
857
+ { body: input.body },
858
+ async (file) => this.json(["--method", "POST", this.endpoint("/notes"), "--input", file])
859
+ );
860
+ if (input.verdict === "approve") {
861
+ await this.call(["--method", "POST", this.endpoint("/approve")]);
862
+ } else if (input.verdict === "request_changes") {
863
+ try {
864
+ await this.call(["--method", "POST", this.endpoint("/unapprove")]);
865
+ } catch {
866
+ }
867
+ }
868
+ return { id: String(note.id) };
869
+ }
828
870
  async updateNote(noteId, body) {
829
871
  await withTempJson({ body }, async (file) => {
830
872
  await this.call(["--method", "PUT", this.endpoint(`/notes/${encodeURIComponent(noteId)}`), "--input", file]);
@@ -910,6 +952,7 @@ var init_github = __esm({
910
952
  "use strict";
911
953
  init_diff();
912
954
  init_errors();
955
+ init_errors();
913
956
  init_exec();
914
957
  init_util();
915
958
  init_locale();
@@ -1065,6 +1108,40 @@ rename to ${newPath}
1065
1108
  const encoded = path12.split("/").map(encodeURIComponent).join("/");
1066
1109
  return this.call(["-H", "Accept: application/vnd.github.raw", query(`repos/${this.repo}/contents/${encoded}`, { ref })]);
1067
1110
  }
1111
+ async readiness() {
1112
+ const errors = [];
1113
+ let checks = [];
1114
+ let approvals = null;
1115
+ const info = await this.info();
1116
+ try {
1117
+ const data = await this.json([query(`repos/${this.repo}/commits/${encodeURIComponent(info.commit.head)}/check-runs`, { per_page: 100 })]);
1118
+ checks = (data.check_runs ?? []).map((run2) => ({
1119
+ id: String(run2.id),
1120
+ name: run2.name,
1121
+ status: run2.status !== "completed" ? "pending" : run2.conclusion === "success" ? "success" : run2.conclusion === "failure" || run2.conclusion === "timed_out" || run2.conclusion === "action_required" ? "failed" : run2.conclusion === "skipped" ? "skipped" : "neutral",
1122
+ url: run2.html_url ?? run2.details_url ?? null
1123
+ }));
1124
+ } catch (error) {
1125
+ errors.push(`checks: ${messageOf(error)}`);
1126
+ }
1127
+ try {
1128
+ const reviews = await this.paged(`${this.pullBase}/reviews`);
1129
+ const latest = /* @__PURE__ */ new Map();
1130
+ for (const review of reviews) {
1131
+ const login = review.user?.login;
1132
+ if (!login || review.state !== "APPROVED" && review.state !== "CHANGES_REQUESTED") continue;
1133
+ latest.set(login, review.state);
1134
+ }
1135
+ approvals = {
1136
+ approved: [...latest.values()].filter((state) => state === "APPROVED").length,
1137
+ required: null,
1138
+ changesRequested: [...latest.values()].filter((state) => state === "CHANGES_REQUESTED").length
1139
+ };
1140
+ } catch (error) {
1141
+ errors.push(`approvals: ${messageOf(error)}`);
1142
+ }
1143
+ return { checks, approvals, errors, checkedAt: (/* @__PURE__ */ new Date()).toISOString() };
1144
+ }
1068
1145
  async threads() {
1069
1146
  const nodes = [];
1070
1147
  let after = null;
@@ -1088,6 +1165,7 @@ rename to ${newPath}
1088
1165
  path: node.path,
1089
1166
  line: node.line ?? node.originalLine,
1090
1167
  side: node.diffSide === "LEFT" ? "old" : "new",
1168
+ ...node.isOutdated ? { outdated: true } : {},
1091
1169
  resolvable: true,
1092
1170
  resolved: node.isResolved,
1093
1171
  notes,
@@ -1211,6 +1289,14 @@ rename to ${newPath}
1211
1289
  async reactToReview(emoji) {
1212
1290
  return this.toggleReaction(`repos/${this.repo}/issues/${this.ref.number}/reactions`, emoji);
1213
1291
  }
1292
+ async submitReview(input) {
1293
+ const event = input.verdict === "approve" ? "APPROVE" : input.verdict === "request_changes" ? "REQUEST_CHANGES" : "COMMENT";
1294
+ const review = await withTempJson(
1295
+ { body: input.body, event },
1296
+ async (file) => this.json(["--method", "POST", `${this.pullBase}/reviews`, "--input", file])
1297
+ );
1298
+ return { id: String(review.id) };
1299
+ }
1214
1300
  async updateNote(noteId, body) {
1215
1301
  await withTempJson({ body }, async (file) => {
1216
1302
  await this.call(["--method", "PATCH", `repos/${this.repo}/pulls/comments/${encodeURIComponent(noteId)}`, "--input", file]);
@@ -1413,7 +1499,7 @@ async function writeFileAtomic(file, data, mode = 384, dirMode = 448) {
1413
1499
  init_redact();
1414
1500
 
1415
1501
  // src/version.ts
1416
- var VERSION = "0.13.0";
1502
+ var VERSION = "0.15.0";
1417
1503
  var PROTOCOL_VERSION = 2;
1418
1504
 
1419
1505
  // src/daemon/main.ts
@@ -3320,6 +3406,40 @@ function computeGroups(diff, custom = []) {
3320
3406
  return [...groups.values()].sort((left, right) => right.additions + right.deletions - (left.additions + left.deletions) || left.title.localeCompare(right.title));
3321
3407
  }
3322
3408
 
3409
+ // src/core/codeowners.ts
3410
+ function parseCodeowners(text2) {
3411
+ const entries = [];
3412
+ for (const raw of text2.replace(/\r\n/g, "\n").split("\n")) {
3413
+ const line = raw.trim();
3414
+ if (!line || line.startsWith("#")) continue;
3415
+ const [pattern, ...owners] = line.split(/\s+/);
3416
+ if (!pattern || !owners.length) continue;
3417
+ entries.push({ pattern, owners });
3418
+ }
3419
+ return entries;
3420
+ }
3421
+ function matches(path12, pattern) {
3422
+ const cleaned = pattern.replace(/^\/+/, "").replace(/\/+$/, "");
3423
+ if (!cleaned) return false;
3424
+ if (!cleaned.includes("/")) {
3425
+ const segment = cleaned.includes("*") || cleaned.includes("?") ? cleaned : cleaned.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3426
+ return new RegExp(`(^|/)${segment}(/|$)`).test(path12);
3427
+ }
3428
+ if (globToRegExp(cleaned).test(path12)) return true;
3429
+ return globToRegExp(`${cleaned}/**`).test(path12);
3430
+ }
3431
+ function codeownersFor(files, entries) {
3432
+ const result = [];
3433
+ for (const file of files) {
3434
+ let owners = [];
3435
+ for (const entry of entries) {
3436
+ if (matches(file, entry.pattern)) owners = entry.owners;
3437
+ }
3438
+ if (owners.length) result.push({ file, owners });
3439
+ }
3440
+ return result;
3441
+ }
3442
+
3323
3443
  // src/core/secrets.ts
3324
3444
  var PATTERNS = [
3325
3445
  { id: "aws-access-key", title: "AWS access key", regex: /\bAKIA[0-9A-Z]{16}\b/g },
@@ -3786,6 +3906,147 @@ function toReviewView(review, now = Date.now()) {
3786
3906
  };
3787
3907
  }
3788
3908
 
3909
+ // src/daemon/update.ts
3910
+ init_errors();
3911
+
3912
+ // src/core/update.ts
3913
+ function parseVersion(value) {
3914
+ const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(value.trim());
3915
+ if (!match) return null;
3916
+ return {
3917
+ major: Number(match[1]),
3918
+ minor: Number(match[2]),
3919
+ patch: Number(match[3]),
3920
+ prerelease: match[4] ? match[4].split(".") : []
3921
+ };
3922
+ }
3923
+ function comparePrerelease(left, right) {
3924
+ if (!left.length && !right.length) return 0;
3925
+ if (!left.length) return 1;
3926
+ if (!right.length) return -1;
3927
+ const length = Math.max(left.length, right.length);
3928
+ for (let index = 0; index < length; index += 1) {
3929
+ const a = left[index];
3930
+ const b = right[index];
3931
+ if (a === void 0) return -1;
3932
+ if (b === void 0) return 1;
3933
+ const aNumeric = /^\d+$/.test(a);
3934
+ const bNumeric = /^\d+$/.test(b);
3935
+ if (aNumeric && bNumeric) {
3936
+ const delta = Number(a) - Number(b);
3937
+ if (delta !== 0) return delta < 0 ? -1 : 1;
3938
+ } else if (aNumeric !== bNumeric) {
3939
+ return aNumeric ? -1 : 1;
3940
+ } else {
3941
+ const delta = a < b ? -1 : a > b ? 1 : 0;
3942
+ if (delta !== 0) return delta;
3943
+ }
3944
+ }
3945
+ return 0;
3946
+ }
3947
+ function compareVersions(left, right) {
3948
+ const a = parseVersion(left);
3949
+ const b = parseVersion(right);
3950
+ if (!a || !b) return 0;
3951
+ const delta = a.major - b.major || a.minor - b.minor || a.patch - b.patch;
3952
+ if (delta !== 0) return delta < 0 ? -1 : 1;
3953
+ return comparePrerelease(a.prerelease, b.prerelease);
3954
+ }
3955
+ function isNewerVersion(latest, current2) {
3956
+ return compareVersions(latest, current2) > 0;
3957
+ }
3958
+
3959
+ // src/daemon/update.ts
3960
+ init_locale();
3961
+ var DEFAULT_TTL_MS = 24 * 60 * 60 * 1e3;
3962
+ var ERROR_TTL_MS = 5 * 60 * 1e3;
3963
+ var REQUEST_TIMEOUT_MS = 5e3;
3964
+ var DIST_TAGS_URL = "https://registry.npmjs.org/-/package/revdeck/dist-tags";
3965
+ var RELEASE_TAG_URL = "https://github.com/katrov/revdeck/releases/tag/v";
3966
+ var UpdateChecker = class {
3967
+ currentVersion;
3968
+ fetchImpl;
3969
+ now;
3970
+ ttlMs;
3971
+ enabled;
3972
+ cache = null;
3973
+ pending = null;
3974
+ constructor(options = {}) {
3975
+ this.currentVersion = options.currentVersion ?? VERSION;
3976
+ this.fetchImpl = options.fetchImpl ?? globalThis.fetch;
3977
+ this.now = options.now ?? (() => /* @__PURE__ */ new Date());
3978
+ this.ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
3979
+ this.enabled = (options.env ?? process.env).REVDECK_UPDATE_CHECK !== "0";
3980
+ }
3981
+ base() {
3982
+ return {
3983
+ enabled: this.enabled,
3984
+ current: this.currentVersion,
3985
+ latest: null,
3986
+ updateAvailable: false,
3987
+ releaseUrl: null,
3988
+ checkedAt: null
3989
+ };
3990
+ }
3991
+ async check(force = false) {
3992
+ if (!this.enabled) return this.base();
3993
+ const now = this.now().getTime();
3994
+ if (!force && this.cache) {
3995
+ const ttl = this.cache.info.error ? ERROR_TTL_MS : this.ttlMs;
3996
+ if (now - this.cache.at < ttl) return this.cache.info;
3997
+ }
3998
+ if (this.pending) return this.pending;
3999
+ this.pending = this.fetchLatest().then((latest) => this.success(latest)).catch((error) => this.failure(error)).finally(() => {
4000
+ this.pending = null;
4001
+ });
4002
+ return this.pending;
4003
+ }
4004
+ async fetchLatest() {
4005
+ const response = await this.fetchImpl(DIST_TAGS_URL, {
4006
+ headers: {
4007
+ accept: "application/json",
4008
+ "user-agent": `revdeck/${this.currentVersion}`
4009
+ },
4010
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
4011
+ });
4012
+ if (!response.ok) {
4013
+ throw new Error(`npm registry: HTTP ${response.status}`);
4014
+ }
4015
+ const data = await response.json();
4016
+ const latest = typeof data.latest === "string" ? data.latest.trim().replace(/^v/, "") : "";
4017
+ if (!parseVersion(latest)) {
4018
+ throw new Error(tr("npm registry: \u043D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u0430\u044F \u0432\u0435\u0440\u0441\u0438\u044F \u0432 dist-tags", "npm registry: invalid version in dist-tags"));
4019
+ }
4020
+ return latest;
4021
+ }
4022
+ success(latest) {
4023
+ const updateAvailable = isNewerVersion(latest, this.currentVersion);
4024
+ const info = {
4025
+ enabled: true,
4026
+ current: this.currentVersion,
4027
+ latest,
4028
+ updateAvailable,
4029
+ releaseUrl: updateAvailable ? `${RELEASE_TAG_URL}${latest}` : null,
4030
+ checkedAt: this.now().toISOString()
4031
+ };
4032
+ this.cache = { info, at: this.now().getTime() };
4033
+ return info;
4034
+ }
4035
+ failure(error) {
4036
+ const previous = this.cache?.info;
4037
+ const info = {
4038
+ ...this.base(),
4039
+ latest: previous?.latest ?? null,
4040
+ updateAvailable: previous?.updateAvailable ?? false,
4041
+ releaseUrl: previous?.releaseUrl ?? null,
4042
+ checkedAt: previous?.checkedAt ?? null,
4043
+ error: tr(`\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u044F: ${messageOf(error)}`, `could not check for updates: ${messageOf(error)}`).slice(0, 400)
4044
+ };
4045
+ this.cache = { info, at: this.now().getTime() };
4046
+ return info;
4047
+ }
4048
+ };
4049
+
3789
4050
  // src/cli/format.ts
3790
4051
  init_redact();
3791
4052
  init_locale();
@@ -4298,6 +4559,24 @@ ${body}` : `${marker}
4298
4559
 
4299
4560
  ${body}`;
4300
4561
  }
4562
+ function renderPublishedSummary(summary) {
4563
+ const lines = [];
4564
+ const title = summary.title.trim();
4565
+ lines.push(`## ${title || tr("\u0420\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442 \u0440\u0435\u0432\u044C\u044E", "Review result")}`);
4566
+ if (summary.scope.trim()) lines.push("", `\`${summary.scope.trim()}\``);
4567
+ if (summary.summary.trim()) lines.push("", summary.summary.trim());
4568
+ const section = (label, items) => {
4569
+ const list = (items ?? []).map((item) => item.trim()).filter(Boolean);
4570
+ if (!list.length) return;
4571
+ lines.push("", `### ${label}`);
4572
+ for (const item of list) lines.push(`- ${item}`);
4573
+ };
4574
+ section(tr("\u0427\u0442\u043E \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u043E", "What changed"), summary.changes);
4575
+ section(tr("\u041D\u0430 \u0447\u0442\u043E \u0441\u043C\u043E\u0442\u0440\u0435\u0442\u044C", "What to focus on"), summary.focus);
4576
+ section(tr("\u0427\u0442\u043E \u043F\u0440\u043E\u0432\u0435\u0440\u0435\u043D\u043E", "What was checked"), summary.coverage);
4577
+ section(tr("\u0427\u0442\u043E \u043D\u0435 \u043F\u0440\u043E\u0432\u0435\u0440\u0435\u043D\u043E", "Not checked"), summary.unknowns);
4578
+ return lines.join("\n").trim();
4579
+ }
4301
4580
  var ReviewService = class {
4302
4581
  events = new EventEmitter();
4303
4582
  store;
@@ -4306,6 +4585,7 @@ var ReviewService = class {
4306
4585
  now;
4307
4586
  refreshTtlMs;
4308
4587
  syncIntervalMs;
4588
+ updates;
4309
4589
  timer = null;
4310
4590
  syncing = false;
4311
4591
  /** Ревью, которые уже обновляются: не запускаем параллельный refresh из UI и sync. */
@@ -4314,6 +4594,8 @@ var ReviewService = class {
4314
4594
  previews = /* @__PURE__ */ new Map();
4315
4595
  /** Полные файлы для раскрытия diff; ключ включает head/base, коммит и путь. */
4316
4596
  fileContentCache = /* @__PURE__ */ new Map();
4597
+ readinessCache = /* @__PURE__ */ new Map();
4598
+ codeownersCache = /* @__PURE__ */ new Map();
4317
4599
  constructor(options) {
4318
4600
  this.store = options.store;
4319
4601
  this.runImpl = options.runImpl ?? run;
@@ -4321,6 +4603,10 @@ var ReviewService = class {
4321
4603
  this.refreshTtlMs = options.refreshTtlMs ?? 6e4;
4322
4604
  this.syncIntervalMs = options.syncIntervalMs ?? 12e4;
4323
4605
  this.providerFactory = options.providerFactory ?? (async (ref, root) => createProvider(ref, { root }));
4606
+ this.updates = new UpdateChecker({
4607
+ now: this.now,
4608
+ ...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
4609
+ });
4324
4610
  this.events.setMaxListeners(50);
4325
4611
  }
4326
4612
  close() {
@@ -5108,6 +5394,87 @@ ${t("\u2026 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442 \u0444\u0438\u0447\
5108
5394
  if (!found) return null;
5109
5395
  return { path: found.path, status: found.status, binary: found.binary, hunks: found.hunks };
5110
5396
  }
5397
+ /** CI/approvals платформы; кешируется на минуту, чтобы Overview не дёргал API на каждый рендер. */
5398
+ async readiness(id, force = false) {
5399
+ const cached = this.readinessCache.get(id);
5400
+ if (!force && cached && this.now().getTime() - cached.at < 6e4) return cached.value;
5401
+ const preview = this.previews.get(id);
5402
+ let provider;
5403
+ try {
5404
+ provider = preview && this.now().getTime() - preview.at < 60 * 6e4 ? await this.providerFactory(preview.ref, preview.root) : await this.providerFor(id);
5405
+ } catch (error) {
5406
+ return {
5407
+ checks: [],
5408
+ approvals: null,
5409
+ errors: [tr(`\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u043E\u0434\u043A\u043B\u044E\u0447\u0438\u0442\u044C\u0441\u044F \u043A \u043F\u043B\u0430\u0442\u0444\u043E\u0440\u043C\u0435: ${redact(messageOf(error))}`, `could not reach the platform: ${redact(messageOf(error))}`)],
5410
+ checkedAt: this.now().toISOString()
5411
+ };
5412
+ }
5413
+ let value;
5414
+ try {
5415
+ value = await provider.readiness();
5416
+ } catch (error) {
5417
+ value = {
5418
+ checks: [],
5419
+ approvals: null,
5420
+ errors: [tr(`\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u0442\u044C \u0433\u043E\u0442\u043E\u0432\u043D\u043E\u0441\u0442\u044C: ${redact(messageOf(error))}`, `could not read readiness: ${redact(messageOf(error))}`)],
5421
+ checkedAt: this.now().toISOString()
5422
+ };
5423
+ }
5424
+ this.readinessCache.set(id, { value, at: this.now().getTime() });
5425
+ return value;
5426
+ }
5427
+ /** CODEOWNERS из рабочей копии или head платформы; только чтение. */
5428
+ async codeowners(id, force = false) {
5429
+ const cached = this.codeownersCache.get(id);
5430
+ if (!force && cached && this.now().getTime() - cached.at < 5 * 6e4) return cached.value;
5431
+ const preview = this.previews.get(id);
5432
+ const stored = preview ? null : this.store.getReview(id);
5433
+ if (!preview && !stored) throw Object.assign(new Error(tr(`\u0440\u0435\u0432\u044C\u044E ${id} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E`, `review ${id} not found`)), { status: 404 });
5434
+ const info = preview?.view.info ?? this.store.info(id);
5435
+ const root = preview?.root ?? stored.row.root;
5436
+ const files = (preview?.diff ?? stored.snapshot.diff).map((file) => file.path);
5437
+ const candidates = [".github/CODEOWNERS", "CODEOWNERS", "docs/CODEOWNERS", ".gitlab/CODEOWNERS"];
5438
+ let text2 = null;
5439
+ let foundPath = null;
5440
+ for (const candidate of candidates) {
5441
+ try {
5442
+ text2 = await readConfigFile(root, candidate, 1e6);
5443
+ foundPath = candidate;
5444
+ break;
5445
+ } catch {
5446
+ }
5447
+ }
5448
+ if (text2 === null && info.commit.head) {
5449
+ try {
5450
+ const provider = preview ? await this.providerFactory(preview.ref, preview.root) : await this.providerFor(id);
5451
+ for (const candidate of candidates) {
5452
+ try {
5453
+ const raw = await provider.fileContent(candidate, info.commit.head);
5454
+ if (raw.trim()) {
5455
+ text2 = raw;
5456
+ foundPath = candidate;
5457
+ break;
5458
+ }
5459
+ } catch {
5460
+ }
5461
+ }
5462
+ } catch {
5463
+ }
5464
+ }
5465
+ const value = {
5466
+ found: text2 !== null,
5467
+ path: foundPath,
5468
+ matches: text2 === null ? [] : codeownersFor(files, parseCodeowners(text2)),
5469
+ errors: []
5470
+ };
5471
+ this.codeownersCache.set(id, { value, at: this.now().getTime() });
5472
+ return value;
5473
+ }
5474
+ /** Последняя версия revdeck в npm; force=true — ручная проверка из настроек. */
5475
+ async updateInfo(force = false) {
5476
+ return this.updates.check(force);
5477
+ }
5111
5478
  /**
5112
5479
  * Полный файл на head (или base для удалённого файла), чтобы UI раскрывал
5113
5480
  * скрытые между hunks строки. Локальный git дешевле API платформы, но
@@ -5529,16 +5896,33 @@ ${errors.join("\n")}`));
5529
5896
  return message;
5530
5897
  }
5531
5898
  // ---------------------------------------------------------------- publish
5532
- previewPublish(id, kind, ids) {
5899
+ previewPublish(id, kind, ids, verdict = "comment") {
5533
5900
  const review = this.getReview(id);
5534
5901
  const items = [];
5535
5902
  const warnings = [];
5536
5903
  const max = this.configOf(id)?.publish?.maxComments ?? 50;
5537
- for (const itemId of ids) {
5904
+ const reviewVerdict = verdict === "approve" || verdict === "request_changes" ? verdict : "comment";
5905
+ const targets = kind === "review" ? ["review"] : ids;
5906
+ for (const itemId of targets) {
5538
5907
  if (items.length >= max) {
5539
5908
  warnings.push(tr(`\u0434\u043E\u0441\u0442\u0438\u0433\u043D\u0443\u0442 \u043B\u0438\u043C\u0438\u0442 ${max} \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u0435\u0432 \u0437\u0430 \u0440\u0430\u0437`, `limit of ${max} comments per batch reached`));
5540
5909
  break;
5541
5910
  }
5911
+ if (kind === "review") {
5912
+ const summary = this.store.getSummary(id);
5913
+ if (!summary) {
5914
+ warnings.push(tr("\u0432\u044B\u0436\u0438\u043C\u043A\u0438 \u0440\u0435\u0432\u044C\u044E \u043D\u0435\u0442: \u0441\u043D\u0430\u0447\u0430\u043B\u0430 \u0437\u0430\u043F\u0438\u0448\u0438\u0442\u0435 summary", "there is no review summary: write one first"));
5915
+ continue;
5916
+ }
5917
+ const body2 = renderPublishedSummary(summary);
5918
+ const check2 = sanitizeBody(body2, review.info.ref.platform, { host: review.info.ref.host });
5919
+ if (!check2.ok) {
5920
+ warnings.push(tr(`\u0432\u044B\u0436\u0438\u043C\u043A\u0430 \u0440\u0435\u0432\u044C\u044E: ${check2.reason}`, `review summary: ${check2.reason}`));
5921
+ continue;
5922
+ }
5923
+ items.push({ kind: "review", id: "review", body: body2, verdict: reviewVerdict });
5924
+ continue;
5925
+ }
5542
5926
  if (kind === "reply") {
5543
5927
  const thread = review.threads.find((item) => item.id === itemId);
5544
5928
  const draft = review.drafts.find((item) => item.threadId === itemId);
@@ -5619,9 +6003,9 @@ ${errors.join("\n")}`));
5619
6003
  const hash = canonicalHash(id, kind, items);
5620
6004
  return { reviewId: id, kind, items, hash, createdAt: this.now().toISOString() };
5621
6005
  }
5622
- approve(id, kind, ids, expectedHash) {
6006
+ approve(id, kind, ids, expectedHash, verdict = "comment") {
5623
6007
  this.assertWritable(id);
5624
- const preview = this.previewPublish(id, kind, ids);
6008
+ const preview = this.previewPublish(id, kind, ids, verdict);
5625
6009
  if (preview.plan.hash !== expectedHash) {
5626
6010
  throw new Error(tr("\u043D\u0430\u0431\u043E\u0440 \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0439 \u0438\u0437\u043C\u0435\u043D\u0438\u043B\u0441\u044F \u043F\u043E\u0441\u043B\u0435 \u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D\u0438\u044F: \u043E\u0431\u043D\u043E\u0432\u0438\u0442\u0435 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0443 \u0438 \u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u0435 \u0437\u0430\u043D\u043E\u0432\u043E", "the plan changed after confirmation: refresh and confirm again"));
5627
6011
  }
@@ -5670,6 +6054,15 @@ ${errors.join("\n")}`));
5670
6054
  const result = { kind: item.kind, id: item.id, ok: false };
5671
6055
  results.push(result);
5672
6056
  try {
6057
+ if (item.kind === "review") {
6058
+ const body = String(item.body ?? "").trim();
6059
+ if (!body) throw new Error(tr("\u043F\u0443\u0441\u0442\u0430\u044F \u0432\u044B\u0436\u0438\u043C\u043A\u0430 \u0440\u0435\u0432\u044C\u044E", "empty review summary"));
6060
+ const check = sanitizeBody(body, platform, { host: review.info.ref.host });
6061
+ if (!check.ok) throw new Error(check.reason);
6062
+ await provider.submitReview({ body, verdict: item.verdict ?? "comment" });
6063
+ result.ok = true;
6064
+ continue;
6065
+ }
5673
6066
  if (item.kind === "reply") {
5674
6067
  const thread = review.threads.find((entry) => entry.id === item.id);
5675
6068
  const draft = this.store.getDraft(id, item.id) ?? EMPTY_DRAFT(item.id);
@@ -6614,6 +7007,23 @@ data: ${JSON.stringify(event)}
6614
7007
  reply(res, 401, { ok: false, error: "\u043D\u0435\u0442 \u0430\u0432\u0442\u043E\u0440\u0438\u0437\u0430\u0446\u0438\u0438" });
6615
7008
  return;
6616
7009
  }
7010
+ if (req.method === "GET" && url.pathname === "/api/update") {
7011
+ const update = await service.updateInfo(url.searchParams.get("refresh") === "1");
7012
+ reply(res, 200, { ok: true, update });
7013
+ return;
7014
+ }
7015
+ if (req.method === "GET" && url.pathname === "/api/codeowners") {
7016
+ const review = url.searchParams.get("review") ?? "";
7017
+ const codeowners = await service.codeowners(review, url.searchParams.get("refresh") === "1");
7018
+ reply(res, 200, { ok: true, codeowners });
7019
+ return;
7020
+ }
7021
+ if (req.method === "GET" && url.pathname === "/api/readiness") {
7022
+ const review = url.searchParams.get("review") ?? "";
7023
+ const readiness = await service.readiness(review, url.searchParams.get("refresh") === "1");
7024
+ reply(res, 200, { ok: true, readiness });
7025
+ return;
7026
+ }
6617
7027
  if (req.method === "GET" && url.pathname === "/api/health") {
6618
7028
  reply(res, 200, { ok: true, version: options.version ?? "dev", reviews: service.listReviews().length });
6619
7029
  return;
@@ -6853,7 +7263,12 @@ data: ${JSON.stringify(event)}
6853
7263
  return;
6854
7264
  }
6855
7265
  case "/api/publish/preview": {
6856
- const preview = service.previewPublish(review, String(body.kind ?? "reply"), Array.isArray(body.ids) ? body.ids.map(String) : []);
7266
+ const preview = service.previewPublish(
7267
+ review,
7268
+ String(body.kind ?? "reply"),
7269
+ Array.isArray(body.ids) ? body.ids.map(String) : [],
7270
+ body.verdict === "approve" || body.verdict === "request_changes" ? body.verdict : "comment"
7271
+ );
6857
7272
  reply(res, 200, { ok: true, preview });
6858
7273
  return;
6859
7274
  }
@@ -6862,7 +7277,8 @@ data: ${JSON.stringify(event)}
6862
7277
  review,
6863
7278
  String(body.kind ?? "reply"),
6864
7279
  Array.isArray(body.ids) ? body.ids.map(String) : [],
6865
- String(body.hash ?? "")
7280
+ String(body.hash ?? ""),
7281
+ body.verdict === "approve" || body.verdict === "request_changes" ? body.verdict : "comment"
6866
7282
  );
6867
7283
  reply(res, 200, { ok: true, approval: { id: approval.id, expiresAt: approval.expiresAt } });
6868
7284
  return;