plugin-git-manager 1.2.14 → 1.2.16

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 (61) hide show
  1. package/dist/client/156.c27c2392746e7866.js +10 -0
  2. package/dist/client/434.1d19d4d6acc114f1.js +10 -0
  3. package/dist/client/900.ee2fa037aff389e2.js +10 -0
  4. package/dist/client/index.js +1 -1
  5. package/dist/client-v2/356.11ed4f8d56a6c08a.js +10 -0
  6. package/dist/client-v2/434.f8836ea116648de1.js +10 -0
  7. package/dist/client-v2/900.bef1c41d267e50c5.js +10 -0
  8. package/dist/client-v2/index.js +1 -1
  9. package/dist/externalVersion.js +8 -7
  10. package/dist/locale/en-US.json +73 -2
  11. package/dist/locale/vi-VN.json +72 -1
  12. package/dist/locale/zh-CN.json +49 -0
  13. package/dist/server/actions/git-actions.js +31 -15
  14. package/dist/server/actions/gitlab-api.js +46 -20
  15. package/dist/server/actions/review.js +13 -10
  16. package/dist/server/actions/subtree.js +430 -0
  17. package/dist/server/collections/gitAccounts.js +86 -0
  18. package/dist/server/collections/gitRepositories.js +11 -10
  19. package/dist/server/collections/gitSubtreeConfigs.js +67 -0
  20. package/dist/server/collections/gitSubtreeRuns.js +60 -0
  21. package/dist/server/migrations/20260712000000-add-git-accounts.js +186 -0
  22. package/dist/server/plugin.js +76 -12
  23. package/dist/server/poller.js +12 -24
  24. package/dist/server/utils/get-repo-account.js +49 -0
  25. package/package.json +1 -1
  26. package/src/client/components/CommitHistory.tsx +21 -5
  27. package/src/client/components/GitAccounts.tsx +179 -0
  28. package/src/client/components/GitManagerSettings.tsx +10 -6
  29. package/src/client/components/GitOperations.tsx +27 -18
  30. package/src/client/components/LLMModelSelect.tsx +2 -2
  31. package/src/client/components/MarkdownView.tsx +1 -4
  32. package/src/client/components/MergeRequests.tsx +238 -129
  33. package/src/client/components/PollingStatus.tsx +10 -5
  34. package/src/client/components/RepositoryConfig.tsx +32 -14
  35. package/src/client/components/RepositoryPermissions.tsx +1 -8
  36. package/src/client/index.tsx +11 -0
  37. package/src/client-v2/components/SubtreeSplits.tsx +503 -0
  38. package/src/client-v2/locale.ts +8 -0
  39. package/src/client-v2/plugin.tsx +12 -5
  40. package/src/locale/en-US.json +73 -2
  41. package/src/locale/vi-VN.json +72 -1
  42. package/src/locale/zh-CN.json +49 -0
  43. package/src/server/__tests__/smoke.test.ts +1 -1
  44. package/src/server/__tests__/subtree.test.ts +73 -0
  45. package/src/server/actions/git-actions.ts +40 -19
  46. package/src/server/actions/gitlab-api.ts +59 -28
  47. package/src/server/actions/review.ts +13 -10
  48. package/src/server/actions/role-permissions.ts +2 -1
  49. package/src/server/actions/subtree.ts +460 -0
  50. package/src/server/collections/gitAccounts.ts +56 -0
  51. package/src/server/collections/gitRepositories.ts +11 -10
  52. package/src/server/collections/gitSubtreeConfigs.ts +37 -0
  53. package/src/server/collections/gitSubtreeRuns.ts +30 -0
  54. package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -0
  55. package/src/server/plugin.ts +79 -5
  56. package/src/server/poller.ts +31 -32
  57. package/src/server/utils/get-repo-account.ts +23 -0
  58. package/dist/client/434.f82454801cf84906.js +0 -10
  59. package/dist/client/900.ec1fa7f16eb8cce6.js +0 -10
  60. package/dist/client-v2/434.c2f944f911a56da0.js +0 -10
  61. package/dist/client-v2/900.7a5e80bf21feda66.js +0 -10
@@ -0,0 +1,49 @@
1
+ {
2
+ "Git Manager": "Git 管理器",
3
+ "Subtree Splits": "Subtree 拆分",
4
+ "Add subtree configuration": "添加 subtree 配置",
5
+ "Edit subtree configuration": "编辑 subtree 配置",
6
+ "Subtree configuration created": "已创建 subtree 配置",
7
+ "Subtree configuration updated": "已更新 subtree 配置",
8
+ "Delete this subtree configuration?": "删除此 subtree 配置?",
9
+ "Name": "名称",
10
+ "Repository": "仓库",
11
+ "Source": "源",
12
+ "Source branch": "源分支",
13
+ "Source folder": "源文件夹",
14
+ "Target branch": "目标分支",
15
+ "Remote name": "远程名称",
16
+ "Default policy": "默认策略",
17
+ "Push after run": "运行后推送",
18
+ "Enabled": "已启用",
19
+ "Last status": "最近状态",
20
+ "Actions": "操作",
21
+ "Run": "运行",
22
+ "Edit": "编辑",
23
+ "Delete": "删除",
24
+ "Deleted": "已删除",
25
+ "Run subtree split": "运行 subtree 拆分",
26
+ "Preview": "预览",
27
+ "Fast-forward only": "仅快进",
28
+ "Replace target": "替换目标分支",
29
+ "Merge histories": "合并历史",
30
+ "Replace target may discard target-only commits": "替换目标分支可能丢弃仅存在于目标分支的提交",
31
+ "Type the target branch name to confirm": "输入目标分支名称以确认",
32
+ "Push target branch after success": "成功后推送目标分支",
33
+ "Target branch does not exist": "目标分支不存在",
34
+ "Subtree split completed": "Subtree 拆分完成",
35
+ "Subtree relationship: target-missing": "目标分支不存在",
36
+ "Subtree relationship: already-up-to-date": "目标分支已是最新",
37
+ "Subtree relationship: fast-forward": "目标分支可以快进",
38
+ "Subtree relationship: diverged": "目标分支已分叉",
39
+ "Run history": "运行历史",
40
+ "Started at": "开始时间",
41
+ "Policy": "策略",
42
+ "Status": "状态",
43
+ "Split SHA": "拆分 SHA",
44
+ "Target before": "更新前目标",
45
+ "Target after": "更新后目标",
46
+ "Error": "错误"
47
+ ,"Execution mode": "执行模式"
48
+ ,"App process": "应用进程"
49
+ }
@@ -36,10 +36,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
36
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
37
  var git_actions_exports = {};
38
38
  __export(git_actions_exports, {
39
+ acquireLock: () => acquireLock,
39
40
  branches: () => branches,
40
41
  checkout: () => checkout,
41
42
  clone: () => clone,
42
43
  commitDetail: () => commitDetail,
44
+ createGit: () => createGit,
43
45
  diff: () => diff,
44
46
  fetch: () => fetch,
45
47
  fileContent: () => fileContent,
@@ -47,7 +49,10 @@ __export(git_actions_exports, {
47
49
  log: () => log,
48
50
  pull: () => pull,
49
51
  push: () => push,
50
- status: () => status
52
+ status: () => status,
53
+ validateBranch: () => validateBranch,
54
+ validateLocalPath: () => validateLocalPath,
55
+ withAuth: () => withAuth
51
56
  });
52
57
  module.exports = __toCommonJS(git_actions_exports);
53
58
  var import_simple_git = __toESM(require("simple-git"));
@@ -55,6 +60,7 @@ var path = __toESM(require("path"));
55
60
  var fs = __toESM(require("fs"));
56
61
  var import_child_process = require("child_process");
57
62
  var import_redact = require("../utils/redact");
63
+ var import_get_repo_account = require("../utils/get-repo-account");
58
64
  const REF_PATTERN = /^(?!-)[a-zA-Z0-9._/-]+$/;
59
65
  const repoLocks = /* @__PURE__ */ new Map();
60
66
  const GIT_BINARY = process.env.GIT_BINARY_PATH || process.env.GIT_EXECUTABLE || "git";
@@ -78,7 +84,8 @@ function validateRef(ref) {
78
84
  return ref;
79
85
  }
80
86
  function validateBranch(branch) {
81
- if (!branch || !REF_PATTERN.test(branch)) {
87
+ const segments = branch.split("/");
88
+ if (!branch || !REF_PATTERN.test(branch) || branch === "@" || branch.includes("..") || branch.includes("@{") || branch.includes("//") || branch.endsWith("/") || branch.endsWith(".") || segments.some((segment) => segment.startsWith(".") || segment.toLowerCase().endsWith(".lock"))) {
82
89
  throw new Error(`Invalid branch name: ${branch}`);
83
90
  }
84
91
  return branch;
@@ -94,22 +101,22 @@ function validateRepoUrl(repoUrl) {
94
101
  throw new Error("Only HTTPS repository URLs are allowed");
95
102
  }
96
103
  }
97
- async function withAuth(git, localPath, repoUrl, pat, fn, username) {
104
+ async function withAuth(git, localPath, repoUrl, pat, fn, username, remoteName = "origin") {
98
105
  const lockKey = localPath;
99
106
  const lock = acquireLock(lockKey);
100
107
  await lock.promise;
101
108
  const authUrl = getAuthUrl(repoUrl, pat, username);
102
- await git.remote(["set-url", "origin", authUrl]);
109
+ await git.remote(["set-url", remoteName, authUrl]);
103
110
  try {
104
111
  return await fn();
105
112
  } catch (err) {
106
113
  throw (0, import_redact.redactError)(err);
107
114
  } finally {
108
115
  try {
109
- await git.remote(["set-url", "origin", repoUrl]);
116
+ await git.remote(["set-url", remoteName, repoUrl]);
110
117
  } catch (cleanupErr) {
111
118
  try {
112
- await git.remote(["set-url", "origin", repoUrl]);
119
+ await git.remote(["set-url", remoteName, repoUrl]);
113
120
  } catch {
114
121
  console.error(
115
122
  `[plugin-git-manager] CRITICAL: failed to remove PAT from remote URL for ${(0, import_redact.redactPat)(repoUrl)}. Manual cleanup of .git/config may be required.`,
@@ -174,9 +181,10 @@ async function clone(ctx, next) {
174
181
  const repo = await getRepo(ctx);
175
182
  const localPath = validateLocalPath(repo.get("localPath"));
176
183
  const repoUrl = (repo.get("repoUrl") || "").trim();
177
- const pat = (repo.get("pat") || "").trim();
178
- const username = (repo.get("username") || "").trim();
179
184
  const defaultBranch = (repo.get("defaultBranch") || "main").trim() || "main";
185
+ const account = await (0, import_get_repo_account.getRepoAccount)(ctx.db, repo);
186
+ if (!account) return ctx.throw(400, "Repository has no Git account configured. Please assign a Git account first.");
187
+ const { pat, username } = account;
180
188
  validateRepoUrl(repoUrl);
181
189
  validateBranch(defaultBranch);
182
190
  if (fs.existsSync(localPath)) {
@@ -210,9 +218,10 @@ async function clone(ctx, next) {
210
218
  async function pull(ctx, next) {
211
219
  const repo = await getRepo(ctx);
212
220
  const localPath = validateLocalPath(repo.get("localPath"));
213
- const pat = (repo.get("pat") || "").trim();
214
221
  const repoUrl = (repo.get("repoUrl") || "").trim();
215
- const username = (repo.get("username") || "").trim();
222
+ const account = await (0, import_get_repo_account.getRepoAccount)(ctx.db, repo);
223
+ if (!account) return ctx.throw(400, "Repository has no Git account configured. Please assign a Git account first.");
224
+ const { pat, username } = account;
216
225
  const git = getGit(ctx, localPath);
217
226
  const result = await withAuth(git, localPath, repoUrl, pat, () => git.pull(), username);
218
227
  ctx.body = { success: true, data: result };
@@ -221,9 +230,10 @@ async function pull(ctx, next) {
221
230
  async function push(ctx, next) {
222
231
  const repo = await getRepo(ctx);
223
232
  const localPath = validateLocalPath(repo.get("localPath"));
224
- const pat = (repo.get("pat") || "").trim();
225
233
  const repoUrl = (repo.get("repoUrl") || "").trim();
226
- const username = (repo.get("username") || "").trim();
234
+ const account = await (0, import_get_repo_account.getRepoAccount)(ctx.db, repo);
235
+ if (!account) return ctx.throw(400, "Repository has no Git account configured. Please assign a Git account first.");
236
+ const { pat, username } = account;
227
237
  const git = getGit(ctx, localPath);
228
238
  const result = await withAuth(git, localPath, repoUrl, pat, () => git.push(), username);
229
239
  ctx.body = { success: true, data: result };
@@ -232,9 +242,10 @@ async function push(ctx, next) {
232
242
  async function fetch(ctx, next) {
233
243
  const repo = await getRepo(ctx);
234
244
  const localPath = validateLocalPath(repo.get("localPath"));
235
- const pat = (repo.get("pat") || "").trim();
236
245
  const repoUrl = (repo.get("repoUrl") || "").trim();
237
- const username = (repo.get("username") || "").trim();
246
+ const account = await (0, import_get_repo_account.getRepoAccount)(ctx.db, repo);
247
+ if (!account) return ctx.throw(400, "Repository has no Git account configured. Please assign a Git account first.");
248
+ const { pat, username } = account;
238
249
  const git = getGit(ctx, localPath);
239
250
  const result = await withAuth(git, localPath, repoUrl, pat, () => git.fetch(), username);
240
251
  ctx.body = { success: true, data: result };
@@ -392,10 +403,12 @@ async function commitDetail(ctx, next) {
392
403
  }
393
404
  // Annotate the CommonJS export names for ESM import in node:
394
405
  0 && (module.exports = {
406
+ acquireLock,
395
407
  branches,
396
408
  checkout,
397
409
  clone,
398
410
  commitDetail,
411
+ createGit,
399
412
  diff,
400
413
  fetch,
401
414
  fileContent,
@@ -403,5 +416,8 @@ async function commitDetail(ctx, next) {
403
416
  log,
404
417
  pull,
405
418
  push,
406
- status
419
+ status,
420
+ validateBranch,
421
+ validateLocalPath,
422
+ withAuth
407
423
  });
@@ -32,6 +32,7 @@ __export(gitlab_api_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(gitlab_api_exports);
34
34
  var import_gitlab_url = require("../utils/gitlab-url");
35
+ var import_get_repo_account = require("../utils/get-repo-account");
35
36
  function getActionParams(ctx) {
36
37
  var _a, _b;
37
38
  return { ...ctx.action.params, ...(_a = ctx.action.params) == null ? void 0 : _a.values, ...((_b = ctx.request) == null ? void 0 : _b.body) || {} };
@@ -48,7 +49,7 @@ async function gitlabFetch(apiBase, endpoint, pat, params) {
48
49
  const response = await fetch(url.toString(), {
49
50
  headers: {
50
51
  "PRIVATE-TOKEN": pat,
51
- "Accept": "application/json"
52
+ Accept: "application/json"
52
53
  }
53
54
  });
54
55
  if (!response.ok) {
@@ -69,9 +70,10 @@ async function getRepoApiContext(ctx) {
69
70
  if (!repo) {
70
71
  ctx.throw(404, "Repository not found");
71
72
  }
72
- const pat = (repo.get("pat") || "").trim();
73
+ const account = await (0, import_get_repo_account.getRepoAccount)(ctx.db, repo);
74
+ const pat = (account == null ? void 0 : account.pat) || "";
73
75
  const repoUrl = (repo.get("repoUrl") || "").trim();
74
- const isGitHub = repoUrl.includes("github.com");
76
+ const isGitHub = (account == null ? void 0 : account.provider) === "github" || repoUrl.includes("github.com");
75
77
  const { apiBase, encodedProject, projectPath } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
76
78
  return { repo, pat, apiBase, encodedProject, projectPath, isGitHub };
77
79
  }
@@ -85,7 +87,7 @@ async function githubFetch(endpoint, pat, params) {
85
87
  });
86
88
  }
87
89
  const headers = {
88
- "Accept": "application/vnd.github.v3+json"
90
+ Accept: "application/vnd.github.v3+json"
89
91
  };
90
92
  if (pat) {
91
93
  headers["Authorization"] = `Bearer ${pat}`;
@@ -110,14 +112,7 @@ async function githubFetch(endpoint, pat, params) {
110
112
  async function mergeRequests(ctx, next) {
111
113
  const { pat, apiBase, encodedProject, projectPath, isGitHub } = await getRepoApiContext(ctx);
112
114
  const params = getActionParams(ctx);
113
- const {
114
- state = "opened",
115
- search,
116
- page = 1,
117
- perPage = 20,
118
- orderBy = "updated_at",
119
- sort = "desc"
120
- } = params;
115
+ const { state = "opened", search, page = 1, perPage = 20, orderBy = "updated_at", sort = "desc" } = params;
121
116
  let result;
122
117
  let items;
123
118
  if (isGitHub) {
@@ -151,7 +146,11 @@ async function mergeRequests(ctx, next) {
151
146
  targetBranch: (_b = pr.base) == null ? void 0 : _b.ref,
152
147
  author: pr.user ? { name: pr.user.login, username: pr.user.login, avatarUrl: pr.user.avatar_url } : null,
153
148
  assignees: (pr.assignees || []).map((a) => ({ name: a.login, username: a.login, avatarUrl: a.avatar_url })),
154
- reviewers: (pr.requested_reviewers || []).map((r) => ({ name: r.login, username: r.login, avatarUrl: r.avatar_url })),
149
+ reviewers: (pr.requested_reviewers || []).map((r) => ({
150
+ name: r.login,
151
+ username: r.login,
152
+ avatarUrl: r.avatar_url
153
+ })),
155
154
  labels: (pr.labels || []).map((l) => l.name),
156
155
  draft: pr.draft || false,
157
156
  mergedBy: null,
@@ -188,8 +187,16 @@ async function mergeRequests(ctx, next) {
188
187
  sourceBranch: mr.source_branch,
189
188
  targetBranch: mr.target_branch,
190
189
  author: mr.author ? { name: mr.author.name, username: mr.author.username, avatarUrl: mr.author.avatar_url } : null,
191
- assignees: (mr.assignees || []).map((a) => ({ name: a.name, username: a.username, avatarUrl: a.avatar_url })),
192
- reviewers: (mr.reviewers || []).map((r) => ({ name: r.name, username: r.username, avatarUrl: r.avatar_url })),
190
+ assignees: (mr.assignees || []).map((a) => ({
191
+ name: a.name,
192
+ username: a.username,
193
+ avatarUrl: a.avatar_url
194
+ })),
195
+ reviewers: (mr.reviewers || []).map((r) => ({
196
+ name: r.name,
197
+ username: r.username,
198
+ avatarUrl: r.avatar_url
199
+ })),
193
200
  labels: mr.labels || [],
194
201
  draft: mr.draft || mr.work_in_progress || false,
195
202
  mergedBy: mr.merged_by ? { name: mr.merged_by.name, username: mr.merged_by.username } : null,
@@ -249,7 +256,11 @@ async function mergeRequestDetail(ctx, next) {
249
256
  targetBranch: (_b = pr.base) == null ? void 0 : _b.ref,
250
257
  author: pr.user ? { name: pr.user.login, username: pr.user.login, avatarUrl: pr.user.avatar_url } : null,
251
258
  assignees: (pr.assignees || []).map((a) => ({ name: a.login, username: a.login, avatarUrl: a.avatar_url })),
252
- reviewers: (pr.requested_reviewers || []).map((r) => ({ name: r.login, username: r.login, avatarUrl: r.avatar_url })),
259
+ reviewers: (pr.requested_reviewers || []).map((r) => ({
260
+ name: r.login,
261
+ username: r.login,
262
+ avatarUrl: r.avatar_url
263
+ })),
253
264
  labels: (pr.labels || []).map((l) => l.name),
254
265
  draft: pr.draft || false,
255
266
  createdAt: pr.created_at,
@@ -275,7 +286,9 @@ async function mergeRequestDetail(ctx, next) {
275
286
  if (!pat) ctx.throw(400, "Personal Access Token is required for GitLab API access");
276
287
  const [mrResult, changesResult] = await Promise.all([
277
288
  gitlabFetch(apiBase, `/projects/${encodedProject}/merge_requests/${mrIid}`, pat),
278
- gitlabFetch(apiBase, `/projects/${encodedProject}/merge_requests/${mrIid}/changes`, pat).catch(() => ({ data: {} }))
289
+ gitlabFetch(apiBase, `/projects/${encodedProject}/merge_requests/${mrIid}/changes`, pat).catch(() => ({
290
+ data: {}
291
+ }))
279
292
  ]);
280
293
  const mr = mrResult.data;
281
294
  const changes = (((_c = changesResult.data) == null ? void 0 : _c.changes) || []).map((c) => ({
@@ -295,8 +308,16 @@ async function mergeRequestDetail(ctx, next) {
295
308
  sourceBranch: mr.source_branch,
296
309
  targetBranch: mr.target_branch,
297
310
  author: mr.author ? { name: mr.author.name, username: mr.author.username, avatarUrl: mr.author.avatar_url } : null,
298
- assignees: (mr.assignees || []).map((a) => ({ name: a.name, username: a.username, avatarUrl: a.avatar_url })),
299
- reviewers: (mr.reviewers || []).map((r) => ({ name: r.name, username: r.username, avatarUrl: r.avatar_url })),
311
+ assignees: (mr.assignees || []).map((a) => ({
312
+ name: a.name,
313
+ username: a.username,
314
+ avatarUrl: a.avatar_url
315
+ })),
316
+ reviewers: (mr.reviewers || []).map((r) => ({
317
+ name: r.name,
318
+ username: r.username,
319
+ avatarUrl: r.avatar_url
320
+ })),
300
321
  labels: mr.labels || [],
301
322
  draft: mr.draft || mr.work_in_progress || false,
302
323
  createdAt: mr.created_at,
@@ -327,7 +348,12 @@ async function mergeRequestNotes(ctx, next) {
327
348
  ctx.throw(400, "mrIid is required");
328
349
  }
329
350
  let notes = [];
330
- let pagination = { page: parseInt(String(page), 10), perPage: parseInt(String(perPage), 10), total: null, totalPages: null };
351
+ const pagination = {
352
+ page: parseInt(String(page), 10),
353
+ perPage: parseInt(String(perPage), 10),
354
+ total: null,
355
+ totalPages: null
356
+ };
331
357
  if (isGitHub) {
332
358
  const result = await githubFetch(`/repos/${projectPath}/issues/${mrIid}/comments`, pat, {
333
359
  page,
@@ -40,6 +40,7 @@ __export(review_exports, {
40
40
  module.exports = __toCommonJS(review_exports);
41
41
  var import_gitlab_url = require("../utils/gitlab-url");
42
42
  var import_redact = require("../utils/redact");
43
+ var import_get_repo_account = require("../utils/get-repo-account");
43
44
  const WORKER_JOB_GIT_REVIEW_PROCESS = "git-review:process";
44
45
  const REVIEW_QUEUE_CHANNEL = "plugin-git-manager.review";
45
46
  const REVIEW_WORKER_ALIASES = [REVIEW_QUEUE_CHANNEL, "plugin-git-manager:review:queue"];
@@ -144,7 +145,7 @@ async function triggerReviewInternalLocked(app, args) {
144
145
  if (!repo) throwHttp(404, "Repository not found");
145
146
  let headSha = args.headSha || null;
146
147
  if (args.targetType === "mr" && !headSha && args.mrIid) {
147
- headSha = await fetchMrHeadSha(repo, args.mrIid).catch(() => null);
148
+ headSha = await fetchMrHeadSha(db, repo, args.mrIid).catch(() => null);
148
149
  }
149
150
  const reviewsRepo = db.getRepository("gitCodeReviews");
150
151
  const targetFilter = {
@@ -567,7 +568,7 @@ async function reviewApprovePost(ctx, next) {
567
568
  filterByTk: review.get("repositoryId")
568
569
  });
569
570
  if (!repo) ctx.throw(404, "Repository not found");
570
- const noteId = await postNoteToGitLab(repo, Number(review.get("mrIid")), markdown);
571
+ const noteId = await postNoteToGitLab(ctx.db, repo, Number(review.get("mrIid")), markdown);
571
572
  const userId = (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
572
573
  await reviewsRepo.update({
573
574
  filterByTk: reviewId,
@@ -741,7 +742,7 @@ async function runReview(app, args) {
741
742
  postStatus = "skipped";
742
743
  } else if (postMode === "auto" && args.targetType === "mr" && args.mrIid) {
743
744
  try {
744
- postedNoteId = String(await postNoteToGitLab(args.repo, args.mrIid, content));
745
+ postedNoteId = String(await postNoteToGitLab(db, args.repo, args.mrIid, content));
745
746
  postStatus = "posted";
746
747
  } catch (err) {
747
748
  autoPostError = (0, import_redact.redactPat)((err == null ? void 0 : err.message) || String(err));
@@ -919,12 +920,13 @@ function extractLastAiMessageContent(result) {
919
920
  }
920
921
  return "";
921
922
  }
922
- async function fetchMrHeadSha(repo, mrIid) {
923
+ async function fetchMrHeadSha(db, repo, mrIid) {
923
924
  var _a, _b;
924
- const repoUrl = repo.get("repoUrl");
925
- const pat = repo.get("pat");
925
+ const account = await (0, import_get_repo_account.getRepoAccount)(db, repo);
926
+ const pat = (account == null ? void 0 : account.pat) || "";
926
927
  if (!pat) return null;
927
- const isGitHub = repoUrl.includes("github.com");
928
+ const repoUrl = repo.get("repoUrl");
929
+ const isGitHub = (account == null ? void 0 : account.provider) === "github" || repoUrl.includes("github.com");
928
930
  try {
929
931
  if (isGitHub) {
930
932
  const { projectPath } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
@@ -947,10 +949,11 @@ async function fetchMrHeadSha(repo, mrIid) {
947
949
  return null;
948
950
  }
949
951
  }
950
- async function postNoteToGitLab(repo, mrIid, body) {
952
+ async function postNoteToGitLab(db, repo, mrIid, body) {
953
+ const account = await (0, import_get_repo_account.getRepoAccount)(db, repo);
954
+ const pat = (account == null ? void 0 : account.pat) || "";
951
955
  const repoUrl = repo.get("repoUrl");
952
- const pat = repo.get("pat");
953
- const isGitHub = repoUrl.includes("github.com");
956
+ const isGitHub = (account == null ? void 0 : account.provider) === "github" || repoUrl.includes("github.com");
954
957
  if (isGitHub) {
955
958
  if (!pat) throw new Error("Repository has no PAT configured");
956
959
  const { projectPath } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);