plugin-git-manager 1.2.28 → 1.3.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.
Files changed (67) hide show
  1. package/README.md +58 -40
  2. package/dist/client/941.1793e67472872992.js +10 -0
  3. package/dist/client/index.js +1 -1
  4. package/dist/client-v2/941.b0d55429cd053f32.js +10 -0
  5. package/dist/client-v2/index.js +1 -1
  6. package/dist/locale/en-US.json +90 -1
  7. package/dist/locale/vi-VN.json +90 -1
  8. package/dist/locale/zh-CN.json +90 -1
  9. package/dist/node_modules/simple-git/package.json +1 -1
  10. package/dist/node_modules/zod/package.json +1 -1
  11. package/dist/server/actions/review-cutover.js +137 -0
  12. package/dist/server/actions/review.js +132 -43
  13. package/dist/server/actions/role-permissions.js +1 -0
  14. package/dist/server/ai-tools.js +8 -9
  15. package/dist/server/collections/gitCodeReviews.js +10 -0
  16. package/dist/server/collections/gitReviewCutover.js +44 -0
  17. package/dist/server/collections/gitReviewFlows.js +3 -0
  18. package/dist/server/collections/gitReviewInbox.js +51 -0
  19. package/dist/server/collections/gitReviewProjects.js +43 -0
  20. package/dist/server/collections/gitReviewRequests.js +56 -0
  21. package/dist/server/index.js +8 -2
  22. package/dist/server/plugin.js +51 -16
  23. package/dist/server/poller.js +54 -34
  24. package/dist/server/repository-access.js +23 -5
  25. package/dist/server/request-method-policy.js +2 -1
  26. package/dist/server/review-control-access.js +79 -0
  27. package/dist/server/services/legacy-post-service.js +412 -0
  28. package/dist/server/services/review-service.js +1451 -0
  29. package/dist/server/services/review-source.js +325 -0
  30. package/package.json +2 -2
  31. package/src/client/__tests__/CommitHistory.test.tsx +79 -0
  32. package/src/client/__tests__/ReviewHistory.test.tsx +126 -0
  33. package/src/client/__tests__/RunReviewButton.test.tsx +46 -35
  34. package/src/client/__tests__/workflowRoutes.test.ts +65 -0
  35. package/src/client/components/CommitHistory.tsx +61 -6
  36. package/src/client/components/ReviewFlows.tsx +90 -41
  37. package/src/client/components/ReviewHistory.tsx +245 -15
  38. package/src/client/components/RunReviewButton.tsx +12 -136
  39. package/src/client/workflowRoutes.ts +42 -0
  40. package/src/locale/en-US.json +90 -1
  41. package/src/locale/vi-VN.json +90 -1
  42. package/src/locale/zh-CN.json +90 -1
  43. package/src/server/__tests__/repository-access.test.ts +11 -3
  44. package/src/server/__tests__/review-service.integration.test.ts +1263 -0
  45. package/src/server/__tests__/review.test.ts +37 -98
  46. package/src/server/actions/review-cutover.ts +121 -0
  47. package/src/server/actions/review.ts +148 -38
  48. package/src/server/actions/role-permissions.ts +10 -0
  49. package/src/server/ai-tools.ts +23 -8
  50. package/src/server/collections/gitCodeReviews.ts +19 -0
  51. package/src/server/collections/gitReviewCutover.ts +23 -0
  52. package/src/server/collections/gitReviewFlows.ts +12 -0
  53. package/src/server/collections/gitReviewInbox.ts +30 -0
  54. package/src/server/collections/gitReviewProjects.ts +22 -0
  55. package/src/server/collections/gitReviewRequests.ts +35 -0
  56. package/src/server/index.ts +12 -0
  57. package/src/server/plugin.ts +43 -6
  58. package/src/server/poller.ts +54 -40
  59. package/src/server/repository-access.ts +32 -2
  60. package/src/server/request-method-policy.ts +1 -0
  61. package/src/server/review-control-access.ts +71 -0
  62. package/src/server/services/__tests__/review-source.test.ts +226 -0
  63. package/src/server/services/legacy-post-service.ts +550 -0
  64. package/src/server/services/review-service.ts +1899 -0
  65. package/src/server/services/review-source.ts +359 -0
  66. package/dist/client/900.a48beac7e2ebee7d.js +0 -10
  67. package/dist/client-v2/900.e6155002a9c97e7f.js +0 -10
package/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  # plugin-git-manager
2
2
 
3
3
  ## Overview
4
- Manage Git repositories with PAT authentication and run AI-powered code reviews on
5
- merge requests. Combines repository operations (clone/pull/push/diff) with a configurable
6
- review pipeline backed by AI Employees.
4
+ Manage Git repositories with PAT authentication and run workflow-based AI reviews on
5
+ merge requests, commits, branches, and folders. Git Manager owns repository access,
6
+ request admission, project reservations, and review history; `plugin-workflow-git-review`
7
+ provides the workflow nodes and templates.
7
8
 
8
- ## Upgrade to 1.2.28
9
+ ## Repository prerequisites
9
10
 
10
- This release includes the Skill Registry tree-limit contract and the Git Manager security fixes.
11
+ The repository features are available independently of the optional review workflow.
11
12
 
12
13
  - Set each self-hosted GitLab account's **Base URL** to its HTTPS origin. A blank Base URL means
13
14
  `https://gitlab.com` for GitLab and `https://github.com` for GitHub. Repository and account origins
@@ -23,12 +24,11 @@ This release includes the Skill Registry tree-limit contract and the Git Manager
23
24
  remote refs. GET and HEAD return 405 before executing these actions. The bundled clients already use POST.
24
25
  - Poller timers, in-flight guards and status belong to each application. Stopping one application
25
26
  does not stop another application's poller. A running cycle retains its guard until it finishes.
26
- - AI chat is optional in both clients. It uses the installed AI plugin manager and is disabled when
27
- that plugin is absent. Standard Git screens can load without the AI module.
27
+ - Standard Git screens can load without the AI module. Git-specific review actions submit to the
28
+ workflow review queue.
28
29
 
29
- The HTTP integration test loads the real plugin and checks resource registration, method enforcement,
30
- POST checkout and junction rejection. Additional tests cover credential origin matching, redirect
31
- policy, credential-free Git config, lock recovery, poller isolation and optional AI chat.
30
+ For review workflows, install and enable the compatible Workflow, Workflow Manual, AI and
31
+ `plugin-workflow-git-review` plugins. The integration plugin requires NocoBase 2.2.40 or newer in the 2.x series.
32
32
 
33
33
  ## Features
34
34
 
@@ -43,31 +43,28 @@ policy, credential-free Git config, lock recovery, poller isolation and optional
43
43
 
44
44
  ### AI code review
45
45
  - **Review Flows** — configurable per repository or global (apply to all repos).
46
- Each flow binds an AI Employee, an optional LLM service / model override,
47
- trigger mode, post mode, branch filter (regex), and extra prompt instructions.
46
+ A flow defines admission and posting policy and binds a native Workflow. The workflow
47
+ owns its LLM configuration, review instructions and manual approval node.
48
48
  - **Trigger modes**:
49
- - `manual` — run from the Merge Requests tab.
49
+ - `manual` — submit a review from Git Manager.
50
50
  - `onMergeRequestCreated` — auto-trigger when a new MR is detected by the poller.
51
51
  - `both` — manual + auto.
52
52
  - **Post modes**:
53
53
  - `auto` — review is posted to the MR as soon as it completes.
54
- - `manual` — review is held in the Review History tab pending approval.
54
+ - `manual` — an MR/PR review waits for an assigned user's manual decision before posting.
55
55
  - `disabled` — review is generated and stored but never posted.
56
56
  - **Re-review on new commits** — every review tracks `headSha` (the SHA that was
57
57
  reviewed) and `latestSha` (the latest known SHA on the MR). The Merge Requests
58
58
  tab flags MRs whose `latestSha !== headSha` so reviewers can re-run the flow.
59
- - **One review per MR** — re-running a review UPSERTs the existing record, preserving
60
- history through `metadata` while keeping the row count bounded.
59
+ - **Review history** — each manual re-run is a separate queued request and history entry.
61
60
 
62
61
  ### Background poller
63
62
  - **5-minute interval** — polls open MRs for repos with `autoReview` enabled.
64
63
  - **Per-repo opt-in** — toggle `Auto Review` on the repository row to enable polling
65
64
  for that repo. Disabled repos are never queried.
66
- - **Smart re-poll** — uses GitLab `updated_after` (with a 1-second safety buffer) so
67
- each tick only fetches MRs that have changed since the last poll.
68
- - **No auto re-trigger** — auto-poll only triggers a review the **first time** an MR
69
- is seen. When new commits arrive on an already-reviewed MR, the poller refreshes
70
- `latestSha` only; re-review must be initiated manually.
65
+ - **Full pagination** — scans all pages of open MRs and retries unsuccessful scans.
66
+ - **New commits** — the default reviews the MR once; enable `Review new commits automatically`
67
+ on a flow to queue a review for each new head SHA.
71
68
  - **Status panel** — the Polling tab shows poller state (running/stopped), last tick,
72
69
  last error, and provides `Poll Now` / `Poll Now (All)` actions.
73
70
 
@@ -75,14 +72,14 @@ policy, credential-free Git config, lock recovery, poller isolation and optional
75
72
  | Name | Purpose |
76
73
  |---|---|
77
74
  | `gitRepositories` | Connected repos, PAT, default branch, `autoReview` flag, `lastPolledAt`. |
78
- | `gitReviewFlows` | Review pipeline definitions (AI employee, trigger mode, post mode, branch filter). |
79
- | `gitCodeReviews` | Review records — one per MR target — with status, markdown output, metadata, post status. |
75
+ | `gitReviewFlows` | Workflow bindings and admission policy (trigger mode, post mode, branch filter). |
76
+ | `gitCodeReviews` | Review records — one per submitted run — with status, markdown output, metadata, post status. |
80
77
 
81
78
  ## Permissions
82
79
  The plugin registers two ACL snippets:
83
80
  - `pm.plugin-git-manager.read` — list/get on repos, flows, reviews + read-only Git
84
81
  operations (status, log, diff, MR queries, poller status).
85
- - `pm.plugin-git-manager.write` — create/update/destroy on collections + write Git
82
+ - `pm.plugin-git-manager.write` — manage repository and flow configuration + write Git
86
83
  operations (clone, pull, push, checkout) + review actions
87
84
  (`triggerReview`, `reviewApprovePost`, `reviewReject`, `pollNow`).
88
85
 
@@ -97,37 +94,58 @@ The plugin registers two ACL snippets:
97
94
  1. Open the **Review Flows** tab.
98
95
  2. Click **Add Review Flow** and set:
99
96
  - **Repository** — leave empty for a global flow.
100
- - **AI Employee** — username of the AI Employee that will run the review.
97
+ - **AI Employee** and model — initial settings used to provision the workflow's LLM nodes.
101
98
  - **Trigger Mode** — `Manual`, `On Merge Request Created`, or `Both`.
102
99
  - **Post Mode** — `Auto post to MR`, `Manual approval before posting`, or
103
100
  `Do not post`.
104
101
  - **Branch Filter** — optional regex; only MRs whose source branch matches will
105
102
  be picked up.
106
103
  - **Additional Instructions** — extra prompt text appended to every review run.
104
+ 3. Configure the associated workflow under **Git Review Workflows**. Choose Quick or Full and assign
105
+ approvers with repository access when manual posting is required. The setup page reports missing
106
+ employee, model, repository or approver bindings. Create a disabled revision before editing its graph;
107
+ enabled revisions are frozen and the integration validates them before use.
107
108
 
108
109
  ### 3. Run a review
109
- - **Manual** — from the **Merge Requests** tab, click **Run Review** on any open MR.
110
+ - **Manual** — use a Git Manager review action for an MR/PR, commit, branch, or folder.
110
111
  - **Automatic** — enable **Auto Review** on the repo and create a flow with
111
112
  trigger mode `On Merge Request Created` or `Both`. Within ~5 minutes the poller
112
113
  will detect new MRs and trigger reviews.
113
114
 
114
115
  ### 4. Approve or reject
115
- If the flow uses `manual` post mode, completed reviews land in the **Review History**
116
- tab with status **Pending Approval**. From there:
117
- - **Approve & Post** — posts the review as a note on the MR.
118
- - **Reject** — marks the review as rejected; nothing is posted.
119
- - **Edit before posting** — tweak the markdown before approving.
116
+ If the flow uses `manual` post mode, an assigned user decides in the native Workflow
117
+ manual task. Approval applies to the exact stored review and fingerprint; rejection
118
+ does not publish a comment. Assigned users with repository access use **Git review approvals**
119
+ in the modern Workflow task center. Commit, branch and folder results are stored without posting.
120
+ Review History links to the workflow execution and tasks.
120
121
 
121
122
  ### 5. Re-review on new commits
122
123
  When new commits are pushed to an already-reviewed MR, the Merge Requests tab shows
123
- a **New commits** badge. Click **Re-run** to overwrite the existing review with a
124
- fresh one for the latest `headSha`.
124
+ a **New commits** badge. Click **Re-run** to queue a separate review for the latest
125
+ `headSha`, or enable automatic new-head reviews on the flow.
125
126
 
126
127
  ## Notes & limits
127
- - The poller fetches at most 50 MRs per repo per tick (`per_page=50`). Repos with
128
- more than 50 open MRs may need manual `Poll Now` runs to catch up.
129
- - GitLab is the only fully-supported MR provider for the review pipeline; basic
130
- Git operations work against any provider.
131
- - The poller is in-process. In multi-instance deployments it runs on every node;
132
- the `isPolling` flag prevents overlap within a single process but not across
133
- nodes. Co-ordinate via a single primary node if needed.
128
+ - The poller follows all pages of open MRs; provider availability and rate limits affect each scan.
129
+ - Review and publication support GitHub.com and GitLab HTTPS repositories. GitHub Enterprise is not supported.
130
+ - Each process runs a poller. PostgreSQL and MySQL/MariaDB use a shared advisory lock when available;
131
+ automatic request deduplication and project reservations are enforced in the database.
132
+
133
+ # Workflow-based AI review migration (1.3)
134
+
135
+ AI reviews use the Workflow integration in `plugin-workflow-git-review`, with individual Git review LLM nodes and a native manual node for required approvals. The LLM nodes use the native AI provider/model and structured-output contract, and persist the pending job before the provider call. They accept text messages for the diff review. Configure a workflow for each review flow and enable the bound revision before submitting a review. Git Manager keeps repository permissions, the review queue and review history; the workflow owns AI execution and approval. The old in-process review worker is not started by this version.
136
+
137
+ For an existing installation, stop **all** application and worker processes running the old Git Manager version and verify that all old review AI work, including work whose database row timed out or failed, has stopped or settled before confirming cutover in the workflow setup page. A fresh installation with no review history is ready automatically. The root-only cutover status shows legacy pending and running reviews and failed reviews with uncertain old execution history. Confirmation records the operator's acknowledgement; it does not itself stop an AI call and does not clear legacy running reviews. Pending legacy reviews migrate only when their original source commit, repository, actor and workflow can be established. A pending review with a missing or changed source, missing flow, or ambiguous actor is shown with its reason; a root user can explicitly cancel it with an audit record and submit a new review. Unresolved legacy reviews block their canonical project, including repository aliases. If project identity cannot be determined, dispatch remains blocked until the issue is resolved.
138
+
139
+ For historical merge-request reviews, the original reviewed base may not have been recorded and cannot be reconstructed reliably. Before approving one, compare the review with the current merge request and explicitly acknowledge this limitation. The current base is recorded for subsequent checks; it is not evidence of the original reviewed base. For a legacy publication in `posting`, `post_unknown` or `post_failed`, use Review History to check for an existing provider comment. A retry requires confirmation that the prior outbound call has stopped and settled, and keeps the approved content unchanged. An unmarked matching comment cannot be proven to belong to the same attempt and is not automatically reposted. Root administrators can release an abandoned publication hold after the same stop confirmation; this does not claim the remote outcome is known.
140
+
141
+ Requests are persisted separately from their workflow execution. A queued request uses the current enabled and validated workflow revision when it is dispatched, then pins that revision for its execution. One reservation per provider project is held across the entire workflow, including human approval. Reservations never expire on a timer. A failed, aborted or timed-out execution is quarantined when the underlying AI call might still be active; a settled failure or validated manual rejection may release it after the recorded job evidence is checked. Unclaimed or orphaned requests and missing execution records can also be recovered after the same verification. A root user may recover only after stopping and verifying the responsible worker or AI call; the setup page records the confirmation. Recovery fences late claims and results but cannot stop a still-running external call. Do not run old and new plugin binaries together during cutover: old binaries do not honor the new reservation.
142
+
143
+ Each run pins the project and commit identities at submission. GitHub.com and GitLab merge requests use provider comparison data; local commit, branch and folder reviews require the admitted commit objects to be present in the configured checkout. Missing or oversized context fails the review, and coverage limitations are reported to the workflow. The project and merge request head are checked again before publication. Publication uses an identifier in the remote comment to reconcile an uncertain response. No database transaction can make the remote head check and comment creation atomic, so provider-side head changes immediately after the check remain possible.
144
+
145
+ Automatic polling scans all open merge request pages and retries unsuccessful scans. Existing flows retain the original behavior of reviewing an MR once; enable **Review new commits automatically** to admit a review for each new head. Manual submissions are separate queued runs. Review history links to the workflow execution and workflow tasks; workflow-managed reviews must be approved in the workflow task instead of the legacy approval action.
146
+
147
+ When publication has an unknown outcome, Review History can check for the original comment without running AI again, even if the merge request head has since changed. A resend requires confirmation that the previous outbound post has stopped and settled, and the head must still match the reviewed commit. A root operator can release a publication hold after the same verification, including when no retry claim exists; the approved result is retained. The check matches the complete comment body and the authenticated Git account, and a different active review blocks the retry.
148
+
149
+ Version 1.3.1 also supports recovery of completed legacy reviews in `posting`, `post_unknown` and `post_failed`. Legacy records did not retain the reviewed base SHA: before a new post the reviewer must compare the saved review with the current merge request and explicitly acknowledge that the original base is unverified. The acknowledged current base and head are then pinned for subsequent attempts; this acknowledgement is not proof of the historical base. A matching historical comment without a marker is reported as observed rather than attributed to a specific attempt, and is not reposted. If an earlier outbound request may still be running, recovery or release of its project hold requires explicit confirmation that it has stopped and settled.
150
+
151
+ The publication retry action is a separate repository-scoped write permission. Existing roles with explicitly configured repository permissions must have their write scope saved again in Repository Permissions to grant this new action; it is not granted automatically during upgrade. Existing review submission permissions are unchanged.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ "use strict";(self.webpackChunkplugin_git_manager=self.webpackChunkplugin_git_manager||[]).push([["941"],{580:function(e,t,n){n.d(t,{GitManagerSettings:function(){return e7}});var r=n(155),l=n.n(r),a=n(59),o=n(375),i=n(602),c=n(866),u=[{key:"application",label:"Application code (C#, .NET, Java, JS/TS…)",text:"Please review the code changes with a focus on:\n1. Best Practices & Style:\n - C#/VB.NET: Follow standard naming conventions (PascalCase for methods/properties, camelCase for fields). Ensure proper use of async/await (avoid .Result/.Wait()). Use LINQ efficiently.\n - Java: Follow standard naming conventions. Check null-safety (Optional, null checks). Prefer try-with-resources for closeable resources and use streams/collections idiomatically.\n - JS/TS: Use strict equality (===), prefer const/let. Ensure TypeScript types are explicit and avoid 'any'.\n2. Performance: Watch out for N+1 queries, unnecessary loops, and memory leaks.\n3. Security: Identify potential SQL injections, XSS vulnerabilities, and improper data validation.\n4. Maintainability: Check for readability, SOLID principles, and DRY. Ensure meaningful naming.\n5. Error Handling: Verify that exceptions are properly caught, handled, and logged."},{key:"workflow-config",label:"Workflow / Config (XML, XAML, YAML, JSON…)",text:"Please review the workflow/configuration files (XML, XAML, YAML, JSON, ...) with a focus on:\n1. Structure & Validity: Well-formed syntax, correct schema/namespace usage, no duplicate or conflicting keys, consistent indentation and encoding.\n2. Workflow Logic: Unreachable or dead steps, missing error handling / retry / timeout settings, incorrect transitions or dependencies between steps, infinite loops.\n3. Security: Hardcoded credentials, secrets, tokens or connection strings; insecure endpoints (http instead of https); overly broad permissions.\n4. Environment & Portability: Hardcoded environment-specific values (paths, hosts, ports) that should be parameterized; missing default values.\n5. Maintainability: Meaningful naming for steps/variables, duplicated blocks that should be shared, obsolete or unused entries."}],s=n(578);function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function m(e,t,n,r,l,a,o){try{var i=e[a](o),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,l)}function p(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){m(a,r,l,o,i,"next",e)}function i(e){m(a,r,l,o,i,"throw",e)}o(void 0)})}}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||y(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return d(e,t)}}function g(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:c(0)}),i(o,"throw",{value:c(1)}),i(o,"return",{value:c(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){a.label=u[1];break}if(6===u[0]&&a.label<l[1]){a.label=l[1],l=u;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(u);break}l[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var v=function(e){var t,n=e.target,i=e.label,m=e.size,v=e.type,h=e.onTriggered,b=(0,s.k)(),E=(0,c.useApp)().apiClient,w=f((0,r.useState)(!1),2),S=w[0],k=w[1],O=f((0,r.useState)([]),2),C=O[0],x=O[1],I=f((0,r.useState)(!1),2),A=I[0],T=I[1],P=f((0,r.useState)(null),2),R=P[0],B=P[1],z=f((0,r.useState)(),2),j=z[0],M=z[1],F=f(a.Form.useForm(),1)[0],D=(0,r.useCallback)(function(){var e=!1,t={repositoryId:n.repositoryId,targetType:n.type};return"mr"===n.type&&(t.mrIid=n.mrIid),"commit"===n.type&&(t.commitSha=n.commitSha),"branch"===n.type&&(t.branch=n.branch),"folder"===n.type&&(t.folderPath=n.folderPath,t.branch=n.ref||null),E.request({url:"gitCodeReviews:list",params:{pageSize:1,sort:["-id"],filter:t}}).then(function(t){if(!e){var n;B(((null==t||null==(n=t.data)?void 0:n.data)||[])[0]||null)}}).catch(function(){}),function(){e=!0}},[E,n]);(0,r.useEffect)(function(){return D()},[D]);var L=(0,r.useCallback)(function(){return p(function(){var e,t;return g(this,function(r){switch(r.label){case 0:return[4,E.request({url:"gitReviewFlows:list",params:{pageSize:100,filter:{enabled:!0,$or:[{repositoryId:n.repositoryId},{repositoryId:null}]}}})];case 1:return x(t=(null==(e=r.sent().data)?void 0:e.data)||[]),[2,t]}})})()},[E,n.repositoryId]),q=(0,r.useCallback)(function(e){var t,r=e.find(function(e){return e.repositoryId===n.repositoryId});return null!=(t=null!=r?r:e[0])?t:null},[n.repositoryId]);(0,r.useEffect)(function(){if(S){M(void 0);var e=!1;return L().then(function(t){if(!e){var n=q(t);(null==n?void 0:n.id)&&F.setFieldValue("flowId",n.id)}}).catch(function(){}),function(){e=!0}}},[S,L,q,F]);var N=R&&R.headSha&&R.latestSha&&R.headSha!==R.latestSha,U=!!R,_=U?N?b("Re-review (new commits)"):b("Re-run review"):b("Code Review"),H=U?o.ReloadOutlined:o.RobotOutlined,W=[{key:"run",icon:l().createElement(o.ThunderboltOutlined,null),label:U?b("Re-run automated review"):b("Run automated review"),onClick:function(){return k(!0)}}].concat(function(e){if(Array.isArray(e))return d(e)}(t=R?[{key:"view",icon:l().createElement(o.RobotOutlined,null),label:b("Status: ".concat(R.status))+" - "+b("View in Review History tab"),onClick:function(){a.message.info(b('Please switch to the "Review History" tab to see the details.'))}}]:[])||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||y(t)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}());return l().createElement(l().Fragment,null,l().createElement(a.Dropdown,{menu:{items:W},placement:"bottomRight",trigger:["click"]},l().createElement(a.Button,{size:void 0===m?"small":m,type:N?"primary":void 0===v?"default":v,icon:l().createElement(H,null),danger:!!N},null!=i?i:_)),l().createElement(a.Modal,{title:l().createElement(a.Space,null,l().createElement(o.RobotOutlined,null),l().createElement("span",null,U?b("Re-run code review"):b("Run code review")),l().createElement("span",{style:{color:"#999",fontSize:12,fontWeight:400}},"mr"===n.type?"MR !".concat(n.mrIid):"commit"===n.type?"Commit ".concat(String(n.commitSha).slice(0,7)):"folder"===n.type?"".concat(b("Folder")," ").concat(n.folderPath||"/"):"".concat(b("Branch")," ").concat(n.branch))),open:S,onCancel:function(){return k(!1)},onOk:function(){return p(function(){var e,t,r,l,o,i,c,u,s,d,m,p;return g(this,function(f){switch(f.label){case 0:return f.trys.push([0,3,4,5]),[4,F.validateFields()];case 1:return r=f.sent(),T(!0),l={repositoryId:n.repositoryId,targetType:n.type,flowId:r.flowId,extraInstructions:r.extraInstructions||void 0},"mr"===n.type&&(l.mrIid=n.mrIid),"commit"===n.type&&(l.commitSha=n.commitSha),"branch"===n.type&&(l.branch=n.branch),"folder"===n.type&&(l.folderPath=n.folderPath,l.branch=n.ref),[4,E.request({url:"gitManager:triggerReview",method:"post",data:l})];case 2:return i=null==(o=f.sent())||null==(t=o.data)||null==(e=t.data)?void 0:e.reviewId,a.message.success(b("Review queued")),k(!1),F.resetFields(),D(),null==h||h(i),[3,5];case 3:var y;if((c=f.sent())&&(void 0===c?"undefined":c&&"u">typeof Symbol&&c.constructor===Symbol?"symbol":typeof c)=="object"&&"errorFields"in c)return[2];return p=c,a.message.error((null==p||null==(m=p.response)||null==(d=m.data)||null==(s=d.errors)||null==(u=s[0])?void 0:u.message)||(null!=(y=Error)&&"u">typeof Symbol&&y[Symbol.hasInstance]?!!y[Symbol.hasInstance](c):c instanceof y)&&c.message||b("Failed to trigger review")),[3,5];case 4:return T(!1),[7];case 5:return[2]}})})()},okText:U?b("Re-run"):b("Start Review"),confirmLoading:A,destroyOnClose:!0},U&&l().createElement(a.Alert,{type:N?"warning":"info",showIcon:!0,style:{marginBottom:12},message:N?b("New commits detected. A new review will be queued."):b("A new review will be queued and existing history will be kept."),description:l().createElement(a.Space,{size:8,wrap:!0,style:{fontSize:12}},(null==R?void 0:R.headSha)&&l().createElement("span",null,b("Reviewed at"),":\xa0",l().createElement(a.Tag,{style:{fontFamily:"monospace"}},String(R.headSha).slice(0,7))),N&&(null==R?void 0:R.latestSha)&&l().createElement("span",null,b("Latest"),":\xa0",l().createElement(a.Tag,{color:"orange",style:{fontFamily:"monospace"}},String(R.latestSha).slice(0,7))))}),l().createElement(a.Form,{form:F,layout:"vertical"},l().createElement(a.Form.Item,{name:"flowId",label:b("Review Flow"),rules:[{required:!0,message:b("Please select a review flow")}],extra:0===C.length?l().createElement(a.Tooltip,{title:b("Create a review flow in the Review Flows tab first")},l().createElement("span",{style:{color:"#faad14"}},b("No enabled flow found for this repository"))):null},l().createElement(a.Select,{options:C.map(function(e){return{value:e.id,label:"".concat(e.name).concat(e.aiEmployeeUsername?" — @".concat(e.aiEmployeeUsername):"").concat(null==e.repositoryId?" (".concat(b("global"),")"):"")}}),placeholder:b("Select a review flow")})),l().createElement(a.Form.Item,{label:b("Prompt template"),extra:b("Selecting a template replaces the extra instructions text")},l().createElement(a.Select,{allowClear:!0,value:j,placeholder:b("Load a default prompt by code type"),options:u.map(function(e){return{value:e.key,label:b(e.label)}}),onChange:function(e){M(e);var t=u.find(function(t){return t.key===e});t&&F.setFieldValue("extraInstructions",t.text)}})),l().createElement(a.Form.Item,{name:"extraInstructions",label:b("Extra instructions (optional)")},l().createElement(a.Input.TextArea,{rows:4,placeholder:b("e.g. Focus on security issues in authentication")})))))};function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function b(e,t,n,r,l,a,o){try{var i=e[a](o),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,l)}function E(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){b(a,r,l,o,i,"next",e)}function i(e){b(a,r,l,o,i,"throw",e)}o(void 0)})}}function w(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function S(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function k(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return h(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return h(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:c(0)}),i(o,"throw",{value:c(1)}),i(o,"return",{value:c(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){a.label=u[1];break}if(6===u[0]&&a.label<l[1]){a.label=l[1],l=u;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(u);break}l[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var C=a.Typography.Text,x=a.Input.Search,I=a.theme.useToken,A={ts:l().createElement(o.CodeOutlined,{style:{color:"#3178c6"}}),tsx:l().createElement(o.CodeOutlined,{style:{color:"#3178c6"}}),js:l().createElement(o.CodeOutlined,{style:{color:"#f7df1e"}}),jsx:l().createElement(o.CodeOutlined,{style:{color:"#f7df1e"}}),json:l().createElement(o.CodeOutlined,{style:{color:"#5b5b5b"}}),md:l().createElement(o.FileMarkdownOutlined,{style:{color:"#083fa1"}}),html:l().createElement(o.Html5Outlined,{style:{color:"#e34c26"}}),css:l().createElement(o.FileTextOutlined,{style:{color:"#563d7c"}}),py:l().createElement(o.CodeOutlined,{style:{color:"#3572A5"}}),png:l().createElement(o.FileImageOutlined,{style:{color:"#a85e32"}}),jpg:l().createElement(o.FileImageOutlined,{style:{color:"#a85e32"}}),svg:l().createElement(o.FileImageOutlined,{style:{color:"#ffb13b"}})},T=function(){var e,t=(0,s.k)(),n=I().token,u=(0,c.useApp)().apiClient,d=(0,i.B)(),m=d.selectedRepo,p=d.branches,f=d.currentBranch,y=d.refreshBranches,g=k((0,r.useState)([]),2),h=g[0],b=g[1],T=k((0,r.useState)(!1),2),P=T[0],R=T[1],B=k((0,r.useState)(null),2),z=B[0],j=B[1],M=k((0,r.useState)(null),2),F=M[0],D=M[1],L=k((0,r.useState)(null),2),q=L[0],N=L[1],U=k((0,r.useState)("HEAD"),2),_=U[0],H=U[1],W=k((0,r.useState)(""),2),G=W[0],V=W[1],$=k((0,r.useState)(""),2),J=$[0],K=$[1],Q=k((0,r.useState)(!1),2),X=Q[0],Y=Q[1],Z=(0,r.useCallback)(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:_;return E(function(){var n,r;return O(this,function(a){switch(a.label){case 0:if(!m)return[2,[]];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,u.request({url:"gitManager:fileTree",params:{repositoryId:m.id,ref:t,treePath:e}})];case 2:return[2,(Array.isArray(r=(null==(n=a.sent().data)?void 0:n.data)||n||[])?r:Array.isArray(null==r?void 0:r.data)?r.data:[]).map(function(e){return{key:e.path,title:l().createElement(C,{style:{fontSize:13}},e.name,"blob"===e.type&&e.size>0&&l().createElement(C,{type:"secondary",style:{fontSize:11,marginLeft:8}},e.size>1024?"".concat((e.size/1024).toFixed(1),"KB"):"".concat(e.size,"B"))),icon:function(e,t){if("tree"!==t){var n;return A[(null==(n=e.split(".").pop())?void 0:n.toLowerCase())||""]||l().createElement(o.FileOutlined,null)}}(e.name,e.type),isLeaf:"blob"===e.type,filePath:e.path,fileType:e.type}})];case 3:return console.warn("Failed to load file tree:",a.sent()),[2,[]];case 4:return[2]}})})()},[u,m,_]),ee=(0,r.useCallback)(function(){return E(function(){return O(this,function(e){switch(e.label){case 0:R(!0),e.label=1;case 1:return e.trys.push([1,,3,4]),[4,Z("",_)];case 2:return b(e.sent()),[3,4];case 3:return R(!1),[7];case 4:return[2]}})})()},[Z,_]);(0,r.useEffect)(function(){(null==m?void 0:m.status)==="connected"?(y(),j(null),D(null),N(null)):b([])},[m]),(0,r.useEffect)(function(){f&&"HEAD"===_&&H(f)},[f]),(0,r.useEffect)(function(){(null==m?void 0:m.status)==="connected"&&ee()},[_,m]);var et=(0,r.useRef)();(0,r.useEffect)(function(){return et.current=setTimeout(function(){return K(G)},300),function(){return clearTimeout(et.current)}},[G]);var en=(0,r.useMemo)(function(){var e;return{type:"folder",repositoryId:null!=(e=null==m?void 0:m.id)?e:0,folderPath:null!=q?q:"",ref:_}},[null==m?void 0:m.id,q,_]);if(!m)return l().createElement(a.Empty,{description:t("No repository selected")});if("connected"!==m.status)return l().createElement(a.Empty,{description:t("Repository not cloned yet")});var er=J?function e(t,n){return t.map(function(t){if(t.children){var r=e(t.children,n);if(r.length>0)return S(w({},t),{children:r})}return(t.filePath||"").toLowerCase().includes(n)?t:null}).filter(Boolean)}(h,J.toLowerCase()):h;return l().createElement("div",{style:{display:"flex",height:"calc(100vh - 280px)",gap:0}},l().createElement("div",{style:{width:320,minWidth:280,borderRight:"1px solid ".concat(n.colorBorderSecondary),display:"flex",flexDirection:"column",background:n.colorBgContainer}},l().createElement("div",{style:{padding:"8px 12px",borderBottom:"1px solid ".concat(n.colorBorderSecondary)}},l().createElement(a.Space,{direction:"vertical",style:{width:"100%"},size:6},l().createElement(a.Select,{size:"small",style:{width:"100%"},value:_,onChange:function(e){H(e),j(null),D(null),N(null)},options:p.map(function(e){return{label:e,value:e}}),placeholder:"Branch"}),l().createElement(x,{size:"small",placeholder:"Filter files...",allowClear:!0,onChange:function(e){return V(e.target.value)}}),l().createElement("div",{style:{display:"flex",alignItems:"center",gap:8}},l().createElement(C,{type:"secondary",ellipsis:!0,title:q||t("Entire repository"),style:{flex:1,minWidth:0,fontSize:12}},q||t("Entire repository")),l().createElement(v,{target:en})))),l().createElement("div",{style:{flex:1,overflow:"auto",padding:"4px 0"}},P?l().createElement("div",{style:{textAlign:"center",padding:40}},l().createElement(a.Spin,null)):l().createElement(a.Tree,{showIcon:!0,treeData:er,loadData:function(e){return E(function(){var t;return O(this,function(n){switch(n.label){case 0:if(e.children)return[2];return[4,Z(e.filePath,_)];case 1:return t=n.sent(),b(function(n){return function e(t,n,r){return t.map(function(t){return t.key===n?S(w({},t),{children:r}):t.children?S(w({},t),{children:e(t.children,n,r)}):t})}(n,e.key,t)}),[2]}})})()},onSelect:function(e,t){return E(function(){var e,n,r,l;return O(this,function(a){switch(a.label){case 0:if(!(e=t.node).isLeaf)return N(function(t){return t===e.filePath?null:e.filePath}),[2];N(null),Y(!0),D(e.filePath),a.label=1;case 1:return a.trys.push([1,3,4,5]),[4,u.request({url:"gitManager:fileContent",params:{repositoryId:m.id,ref:_,filePath:e.filePath}})];case 2:return j((null==(l=(null==(r=a.sent().data)||null==(n=r.data)?void 0:n.data)||(null==r?void 0:r.data))?void 0:l.content)||""),[3,5];case 3:return a.sent(),j("// Failed to load file content"),[3,5];case 4:return Y(!1),[7];case 5:return[2]}})})()},selectedKeys:F?[F]:q?[q]:[],style:{fontSize:13},blockNode:!0}))),l().createElement("div",{style:{flex:1,display:"flex",flexDirection:"column",background:n.colorBgLayout}},F?l().createElement(l().Fragment,null,l().createElement("div",{style:{padding:"6px 16px",borderBottom:"1px solid ".concat(n.colorBorderSecondary),background:n.colorBgContainer,display:"flex",alignItems:"center",gap:8}},l().createElement(a.Breadcrumb,{items:F.split("/").map(function(e,t,n){return{title:t===n.length-1?l().createElement(C,{strong:!0},e):e}})}),l().createElement(C,{type:"secondary",style:{marginLeft:"auto",fontSize:12}},{ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",json:"json",md:"markdown",html:"html",css:"css",scss:"scss",py:"python",sh:"bash",yml:"yaml",yaml:"yaml",sql:"sql",xml:"xml",java:"java",go:"go",rs:"rust",rb:"ruby"}[(null==(e=F.split(".").pop())?void 0:e.toLowerCase())||""]||"text")),l().createElement("div",{style:{flex:1,overflow:"auto"}},X?l().createElement("div",{style:{textAlign:"center",padding:40}},l().createElement(a.Spin,null)):l().createElement("pre",{style:{margin:0,padding:16,fontSize:13,lineHeight:1.6,fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace",whiteSpace:"pre-wrap",wordBreak:"break-all",background:n.colorBgContainer,minHeight:"100%"}},(z||"").split("\n").map(function(e,t){return l().createElement("div",{key:t,style:{display:"flex"}},l().createElement("span",{style:{display:"inline-block",width:50,textAlign:"right",paddingRight:16,color:n.colorTextQuaternary,userSelect:"none",flexShrink:0}},t+1),l().createElement("span",{style:{flex:1}},e||" "))})))):l().createElement("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%"}},l().createElement(C,{type:"secondary"},"Select a file to view its content"))))};function P(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function R(e,t,n,r,l,a,o){try{var i=e[a](o),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,l)}function B(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){R(a,r,l,o,i,"next",e)}function i(e){R(a,r,l,o,i,"throw",e)}o(void 0)})}}function z(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return P(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return P(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function j(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:c(0)}),i(o,"throw",{value:c(1)}),i(o,"return",{value:c(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){a.label=u[1];break}if(6===u[0]&&a.label<l[1]){a.label=l[1],l=u;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(u);break}l[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var M=a.Typography.Text,F=a.theme.useToken,D={A:{color:"green",icon:l().createElement(o.PlusCircleOutlined,null),label:"Added"},M:{color:"blue",icon:l().createElement(o.EditOutlined,null),label:"Modified"},D:{color:"red",icon:l().createElement(o.DeleteOutlined,null),label:"Deleted"},R:{color:"orange",icon:l().createElement(o.EditOutlined,null),label:"Renamed"}},L=function(){var e,t,n,u=(0,s.k)(),d=F().token,m=(0,c.useApp)().apiClient,p=(0,i.B)().selectedRepo,f=null==p?void 0:p.id,y=z((0,r.useState)(null),2),g=y[0],h=y[1],b=z((0,r.useState)([]),2),E=b[0],w=b[1],S=z((0,r.useState)(!1),2),k=S[0],O=S[1],C=z((0,r.useState)(null),2),x=C[0],I=C[1],A=z((0,r.useState)(null),2),T=A[0],P=A[1],R=z((0,r.useState)(!1),2),L=R[0],U=R[1],_=z((0,r.useState)(null),2),H=_[0],W=_[1],G=z((0,r.useState)(null),2),V=G[0],$=G[1],J=z((0,r.useState)(""),2),K=J[0],Q=J[1];(0,r.useEffect)(function(){var e=!1,t=null==p?void 0:p.id;return(h(null),t&&"connected"===p.status)?(m.request({url:"gitManager:branches",params:{repositoryId:t}}).then(function(n){var r,l=n.data,a=(null==l||null==(r=l.data)?void 0:r.data)||(null==l?void 0:l.data);!e&&(null==a?void 0:a.detached)===!1&&"string"==typeof(null==a?void 0:a.current)&&a.current&&Array.isArray(a.all)&&a.all.includes(a.current)&&h({repositoryId:t,branch:a.current,branches:a.all})}).catch(function(){}),function(){e=!0}):function(){e=!0}},[m,null==p?void 0:p.id,null==p?void 0:p.status]);var X=(0,r.useCallback)(function(){return B(function(){var e,t,n;return j(this,function(r){switch(r.label){case 0:if(!p)return[2];O(!0),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,m.request({url:"gitManager:log",params:{repositoryId:p.id,maxCount:100}})];case 2:return w((null==(n=(null==(t=r.sent().data)||null==(e=t.data)?void 0:e.data)||(null==t?void 0:t.data))?void 0:n.all)||[]),[3,5];case 3:return console.warn("Failed to load commit history:",r.sent()),w([]),[3,5];case 4:return O(!1),[7];case 5:return[2]}})})()},[m,p]);(0,r.useEffect)(function(){(null==p?void 0:p.status)==="connected"?X():w([])},[p,X]);var Y=E.filter(function(e){var t=K.trim().toLowerCase();return!t||String(e.message||e.subject||e.body||"").toLowerCase().includes(t)}),Z=function(e){return B(function(){var t,n;return j(this,function(r){switch(r.label){case 0:if(null==f)return[2];I(e),U(!0),W(null),$(null),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,m.request({url:"gitManager:commitDetail",params:{repositoryId:f,commitHash:e.hash}})];case 2:return P((null==(n=r.sent().data)||null==(t=n.data)?void 0:t.data)||(null==n?void 0:n.data)),[3,5];case 3:return r.sent(),P(null),[3,5];case 4:return U(!1),[7];case 5:return[2]}})})()};if(!p)return l().createElement(a.Empty,{description:u("No repository selected")});if("connected"!==p.status)return l().createElement(a.Empty,{description:u("Repository not cloned yet")});var ee=(null==g?void 0:g.repositoryId)===p.id?g:null,et=[{title:"",key:"graph",width:40,render:function(e,t,n){return l().createElement("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%"}},l().createElement("div",{style:{width:10,height:10,borderRadius:"50%",background:0===n?d.colorPrimary:d.colorBorder,border:"2px solid ".concat(0===n?d.colorPrimary:d.colorBorder),zIndex:1}}))}},{title:u("Message"),dataIndex:"message",key:"message",render:function(e,t){return l().createElement("div",null,l().createElement(M,{strong:!0,style:{fontSize:13}},e),l().createElement("div",{style:{marginTop:2}},l().createElement(M,{type:"secondary",style:{fontSize:12}},l().createElement(o.UserOutlined,{style:{marginRight:4}}),t.author_name,l().createElement("span",{style:{margin:"0 8px"}},"\xb7"),l().createElement(o.ClockCircleOutlined,{style:{marginRight:4}}),N(t.date))))}},{title:"Hash",dataIndex:"hash",key:"hash",width:100,render:function(e){return l().createElement(M,{code:!0,copyable:!0,style:{fontSize:12}},null==e?void 0:e.substring(0,7))}},{title:"",key:"action",width:80,render:function(e,t){return l().createElement(a.Button,{size:"small",icon:l().createElement(o.DiffOutlined,null),onClick:function(){return Z(t)}},"Detail")}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:12,display:"flex",alignItems:"center",gap:12}},l().createElement(o.BranchesOutlined,null),l().createElement(a.Select,{size:"small",style:{width:200},value:null==ee?void 0:ee.branch,options:(null!=(e=null==ee?void 0:ee.branches)?e:[]).map(function(e){return{label:e,value:e}}),disabled:!0}),ee&&l().createElement(v,{label:u("Review branch"),target:{type:"branch",repositoryId:p.id,branch:ee.branch},size:"small"}),l().createElement(a.Input.Search,{allowClear:!0,size:"small",style:{width:280},placeholder:u("Search commit title or message"),value:K,onChange:function(e){return Q(e.target.value)}}),l().createElement(M,{type:"secondary"},Y.length," commits")),k?l().createElement(a.Spin,null):l().createElement(a.Table,{dataSource:Y,columns:et,rowKey:"hash",size:"small",pagination:{pageSize:30,showSizeChanger:!0},onRow:function(e){return{style:{cursor:"pointer"},onClick:function(){return Z(e)}}}}),l().createElement(a.Drawer,{title:x?l().createElement("div",null,l().createElement(M,{strong:!0},x.message),l().createElement("div",null,l().createElement(M,{type:"secondary",style:{fontSize:12}},null==(t=x.hash)?void 0:t.substring(0,7)," \xb7 ",x.author_name," \xb7"," ",N(x.date)))):"Commit Detail",open:!!x,onClose:function(){I(null),P(null),W(null),$(null)},width:800,extra:x&&p?l().createElement(v,{target:{type:"commit",repositoryId:p.id,commitSha:x.hash,title:x.message},size:"small"}):null},L?l().createElement(a.Spin,null):T?l().createElement("div",null,l().createElement(M,{strong:!0},"Changed Files (",(null==(n=T.files)?void 0:n.length)||0,")"),l().createElement(a.List,{size:"small",style:{marginTop:8},dataSource:T.files||[],renderItem:function(e){var t=D[e.status]||D.M,n=V===e.file;return l().createElement(a.List.Item,{style:{cursor:"pointer",background:n?d.colorPrimaryBg:void 0,padding:"6px 12px",borderRadius:4},onClick:function(){var t,n;return t=x.hash,n=e.file,B(function(){var e,r;return j(this,function(l){switch(l.label){case 0:if(null==f)return[2];$(n),l.label=1;case 1:return l.trys.push([1,3,,4]),[4,m.request({url:"gitManager:diff",params:{repositoryId:f,commitHash:t,file:n}})];case 2:return W((null==(r=l.sent().data)||null==(e=r.data)?void 0:e.data)||(null==r?void 0:r.data)||""),[3,4];case 3:return l.sent(),W("// Failed to load diff"),[3,4];case 4:return[2]}})})()}},l().createElement(a.Space,null,l().createElement(a.Tag,{color:t.color,style:{minWidth:70,textAlign:"center"}},t.icon," ",t.label),l().createElement(M,{style:{fontSize:13}},e.file)))}}),null!==H&&l().createElement("div",{style:{marginTop:16}},l().createElement(M,{strong:!0,style:{display:"block",marginBottom:8}},l().createElement(o.FileTextOutlined,null)," ",V),l().createElement(q,{content:H}))):null))},q=(0,r.memo)(function(e){var t=e.content,n=F().token,r=t.split("\n");return l().createElement("div",{style:{fontFamily:"'JetBrains Mono', 'Fira Code', Consolas, monospace",fontSize:12,lineHeight:1.5,border:"1px solid ".concat(n.colorBorderSecondary),borderRadius:6,overflow:"auto",maxHeight:500}},r.map(function(e,t){var r="transparent",a=n.colorText;return e.startsWith("+")&&!e.startsWith("+++")?(r="rgba(46, 160, 67, 0.12)",a="#2ea043"):e.startsWith("-")&&!e.startsWith("---")?(r="rgba(248, 81, 73, 0.12)",a="#f85149"):e.startsWith("@@")?(r="rgba(56, 139, 253, 0.08)",a="#388bfd"):(e.startsWith("diff")||e.startsWith("index"))&&(a=n.colorTextSecondary),l().createElement("div",{key:t,style:{padding:"0 12px",background:r,color:a,whiteSpace:"pre",minHeight:20}},l().createElement("span",{style:{display:"inline-block",width:40,color:n.colorTextQuaternary,userSelect:"none",textAlign:"right",marginRight:12}},t+1),e)}))});function N(e){if(!e)return"";var t=new Date(e),n=new Date().getTime()-t.getTime(),r=n/36e5;return r<1?"".concat(Math.round(n/6e4),"m ago"):r<24?"".concat(Math.round(r),"h ago"):r<168?"".concat(Math.round(r/24),"d ago"):t.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function U(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function _(e,t,n,r,l,a,o){try{var i=e[a](o),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,l)}function H(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){_(a,r,l,o,i,"next",e)}function i(e){_(a,r,l,o,i,"throw",e)}o(void 0)})}}function W(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return U(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return U(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function G(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:c(0)}),i(o,"throw",{value:c(1)}),i(o,"return",{value:c(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){a.label=u[1];break}if(6===u[0]&&a.label<l[1]){a.label=l[1],l=u;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(u);break}l[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var V=a.Typography.Text;a.Typography.Paragraph,a.Typography.Title;var $=a.theme.useToken,J={opened:{color:"blue",icon:l().createElement(o.MergeOutlined,null),label:"Open"},merged:{color:"purple",icon:l().createElement(o.CheckCircleOutlined,null),label:"Merged"},closed:{color:"red",icon:l().createElement(o.CloseCircleOutlined,null),label:"Closed"}},K=function(){var e,t,n=(0,s.k)(),u=$().token,d=(0,c.useApp)().apiClient,m=(0,i.B)().selectedRepo,p=W((0,r.useState)([]),2),f=p[0],y=p[1],g=W((0,r.useState)(!1),2),h=g[0],b=g[1],E=W((0,r.useState)("opened"),2),w=E[0],S=E[1],k=W((0,r.useState)(""),2),O=k[0],C=k[1],x=W((0,r.useState)({page:1,perPage:20,total:0,totalPages:0}),2),I=x[0],A=x[1],T=W((0,r.useState)(null),2),P=T[0],R=T[1],B=W((0,r.useState)(null),2),z=B[0],j=B[1],M=W((0,r.useState)(!1),2),F=M[0],D=M[1],L=W((0,r.useState)([]),2),q=L[0],N=L[1],U=W((0,r.useState)(!1),2);U[0],U[1];var _=(0,r.useCallback)(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return H(function(){var t,n;return G(this,function(r){switch(r.label){case 0:if(!m)return[2];b(!0),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,d.request({url:"gitManager:mergeRequests",params:{repositoryId:m.id,state:w,search:O||void 0,page:e,perPage:20}})];case 2:return y((null==(n=(null==(t=r.sent().data)?void 0:t.data)||t)?void 0:n.data)||[]),(null==n?void 0:n.pagination)&&A(n.pagination),[3,5];case 3:return r.sent(),y([]),[3,5];case 4:return b(!1),[7];case 5:return[2]}})})()},[d,m,w,O]);(0,r.useEffect)(function(){(null==m?void 0:m.status)==="connected"?_(1):y([])},[m,w]);var K=function(e){return H(function(){var t,n,r,l,a,o,i,c,u,s;return G(this,function(p){switch(p.label){case 0:R(e),D(!0),N([]),p.label=1;case 1:return p.trys.push([1,3,4,5]),[4,Promise.all([d.request({url:"gitManager:mergeRequestDetail",params:{repositoryId:m.id,mrIid:e.iid}}),d.request({url:"gitManager:mergeRequestNotes",params:{repositoryId:m.id,mrIid:e.iid}})])];case 2:return c=(i=W.apply(void 0,[p.sent(),2]))[0],u=i[1],j((null==c||null==(n=c.data)||null==(t=n.data)?void 0:t.data)||(null==c||null==(r=c.data)?void 0:r.data)),N(Array.isArray(s=(null==u||null==(a=u.data)||null==(l=a.data)?void 0:l.data)||(null==u||null==(o=u.data)?void 0:o.data))?s:[]),[3,5];case 3:return p.sent(),j(null),[3,5];case 4:return D(!1),[7];case 5:return[2]}})})()};if(!m)return l().createElement(a.Empty,{description:n("No repository selected")});if("connected"!==m.status)return l().createElement(a.Empty,{description:n("Repository not cloned yet")});var X=[{title:"",key:"state_icon",width:40,render:function(e,t){var n=J[t.state]||J.opened;return l().createElement(a.Tooltip,{title:n.label},l().createElement("span",{style:{color:u["color".concat("blue"===n.color?"Primary":"purple"===n.color?"PurpleText":"Error")]||n.color,fontSize:16}},n.icon))}},{title:n("Title"),key:"title",render:function(e,t){var r,i;return l().createElement("div",null,l().createElement("div",{style:{display:"flex",alignItems:"center",gap:6}},t.draft&&l().createElement(a.Tag,{color:"default",style:{fontSize:11,lineHeight:"16px"}},"DRAFT"),l().createElement(V,{strong:!0,style:{fontSize:13}},t.title),t.hasConflicts&&l().createElement(a.Tooltip,{title:n("Has conflicts")},l().createElement(o.ExclamationCircleOutlined,{style:{color:u.colorWarning}}))),l().createElement("div",{style:{marginTop:2}},l().createElement(V,{type:"secondary",style:{fontSize:12}},"!",t.iid,l().createElement("span",{style:{margin:"0 6px"}},"\xb7"),l().createElement(o.UserOutlined,{style:{marginRight:3}}),(null==(r=t.author)?void 0:r.name)||(null==(i=t.author)?void 0:i.username)||"Unknown",l().createElement("span",{style:{margin:"0 6px"}},"\xb7"),l().createElement(o.ClockCircleOutlined,{style:{marginRight:3}}),et(t.updatedAt))))}},{title:"",key:"branches",width:250,render:function(e,t){return l().createElement("div",{style:{fontSize:12}},l().createElement(a.Tag,{color:"blue",style:{fontSize:11}},l().createElement(o.BranchesOutlined,null)," ",t.sourceBranch),l().createElement("span",{style:{margin:"0 4px",color:u.colorTextSecondary}},"→"),l().createElement(a.Tag,{color:"green",style:{fontSize:11}},l().createElement(o.BranchesOutlined,null)," ",t.targetBranch))}},{title:"",key:"labels",width:180,render:function(e,t){var n;return l().createElement(a.Space,{size:2,wrap:!0},(t.labels||[]).slice(0,3).map(function(e){return l().createElement(a.Tag,{key:e,style:{fontSize:11}},e)}),(null==(n=t.labels)?void 0:n.length)>3&&l().createElement(V,{type:"secondary",style:{fontSize:11}},"+",t.labels.length-3))}},{title:"",key:"meta",width:120,render:function(e,t){var n;return l().createElement(a.Space,{size:12},t.userNotesCount>0&&l().createElement(a.Tooltip,{title:"".concat(t.userNotesCount," comments")},l().createElement(a.Badge,{count:t.userNotesCount,size:"small",color:u.colorTextSecondary},l().createElement(o.CommentOutlined,{style:{fontSize:14,color:u.colorTextSecondary}}))),(null==(n=t.assignees)?void 0:n.length)>0&&l().createElement(a.Avatar.Group,{size:"small",max:{count:2}},t.assignees.map(function(e){var t;return l().createElement(a.Tooltip,{key:e.username,title:e.name},l().createElement(a.Avatar,{size:"small",src:e.avatarUrl},null==(t=e.name)?void 0:t[0]))})))}},{title:"",key:"actions",width:160,render:function(e,t){return l().createElement(a.Space,{onClick:function(e){return e.stopPropagation()}},l().createElement(v,{target:{type:"mr",repositoryId:m.id,mrIid:t.iid,title:t.title},size:"small"}),l().createElement(a.Tooltip,{title:n("View Details")},l().createElement(a.Button,{size:"small",icon:l().createElement(o.FileTextOutlined,null),onClick:function(e){e.stopPropagation(),K(t)}})),l().createElement(a.Tooltip,{title:n("Open in GitLab")},l().createElement(a.Button,{size:"small",icon:l().createElement(o.ExportOutlined,null),onClick:function(e){e.stopPropagation(),window.open(t.webUrl,"_blank")}})))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:12,display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"}},l().createElement(a.Select,{size:"small",style:{width:140},value:w,onChange:function(e){return S(e)},options:[{label:"\uD83D\uDFE2 ".concat(n("Open")),value:"opened"},{label:"\uD83D\uDFE3 ".concat(n("Merged")),value:"merged"},{label:"\uD83D\uDD34 ".concat(n("Closed")),value:"closed"},{label:"\uD83D\uDCCB ".concat(n("All")),value:"all"}]}),l().createElement(a.Input.Search,{size:"small",style:{width:260},placeholder:n("Search merge requests..."),value:O,onChange:function(e){return C(e.target.value)},onSearch:function(){_(1)},allowClear:!0}),l().createElement(a.Button,{size:"small",icon:l().createElement(o.ReloadOutlined,null),onClick:function(){return _(1)}},n("Refresh")),l().createElement(V,{type:"secondary",style:{fontSize:12}},null!=I.total?"".concat(I.total," ").concat(n("total")):"")),h?l().createElement(a.Spin,null):l().createElement(a.Table,{dataSource:f,columns:X,rowKey:"iid",size:"small",pagination:{current:I.page,pageSize:I.perPage,total:I.total||void 0,onChange:function(e){return _(e)},showSizeChanger:!1},onRow:function(e){return{style:{cursor:"pointer"},onClick:function(){return K(e)}}}}),l().createElement(a.Drawer,{title:P?l().createElement("div",null,l().createElement("div",{style:{display:"flex",alignItems:"center",gap:8}},(e=J[P.state]||J.opened,l().createElement(a.Tag,{color:e.color},e.icon," ",e.label)),P.draft&&l().createElement(a.Tag,null,"DRAFT"),l().createElement(V,{strong:!0,style:{fontSize:15}},"!",P.iid)),l().createElement(V,{strong:!0,style:{fontSize:16,display:"block",marginTop:4}},P.title)):n("Merge Request"),open:!!P,onClose:function(){R(null),j(null),N([])},width:900,extra:P&&l().createElement(a.Space,null,l().createElement(v,{target:{type:"mr",repositoryId:m.id,mrIid:P.iid,title:P.title},size:"small"}),l().createElement(a.Button,{type:"link",icon:l().createElement(o.ExportOutlined,null),onClick:function(){return window.open(P.webUrl,"_blank")}},n("Open in GitLab")))},F?l().createElement(a.Spin,null):z?l().createElement(a.Tabs,{defaultActiveKey:"overview",items:[{key:"overview",label:n("Overview"),children:l().createElement(Q,{mr:z})},{key:"changes",label:"".concat(n("Changes")," (").concat((null==(t=z.changes)?void 0:t.length)||0,")"),children:l().createElement(Y,{changes:z.changes||[]})},{key:"comments",label:l().createElement(a.Badge,{count:q.length,size:"small",offset:[6,0]},n("Comments")),children:l().createElement(Z,{notes:q})}]}):null))},Q=function(e){var t,n,r,i,c=e.mr,u=(0,s.k)(),d=$().token;return l().createElement("div",null,l().createElement("div",{style:{padding:"12px 16px",background:d.colorBgLayout,borderRadius:8,marginBottom:16,display:"flex",alignItems:"center",gap:8}},l().createElement(a.Tag,{color:"blue"},l().createElement(o.BranchesOutlined,null)," ",c.sourceBranch),l().createElement("span",{style:{color:d.colorTextSecondary,fontSize:16}},"→"),l().createElement(a.Tag,{color:"green"},l().createElement(o.BranchesOutlined,null)," ",c.targetBranch),c.hasConflicts&&l().createElement(a.Tag,{color:"warning",icon:l().createElement(o.ExclamationCircleOutlined,null)},u("Has conflicts"))),c.description&&l().createElement("div",{style:{marginBottom:16}},l().createElement(V,{strong:!0},u("Description")),l().createElement("div",{style:{marginTop:8,padding:"12px 16px",background:d.colorBgLayout,borderRadius:8,whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:13,lineHeight:1.6}},c.description)),l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px 24px",fontSize:13}},l().createElement(X,{label:u("Author"),value:c.author&&l().createElement(a.Space,{size:6},l().createElement(a.Avatar,{size:"small",src:c.author.avatarUrl},null==(t=c.author.name)?void 0:t[0]),l().createElement(V,null,c.author.name),l().createElement(V,{type:"secondary"},"@",c.author.username))}),l().createElement(X,{label:u("Assignees"),value:(null==(n=c.assignees)?void 0:n.length)>0?l().createElement(a.Space,{size:4,wrap:!0},c.assignees.map(function(e){var t;return l().createElement(a.Tooltip,{key:e.username,title:e.name},l().createElement(a.Tag,{icon:l().createElement(a.Avatar,{size:14,src:e.avatarUrl},null==(t=e.name)?void 0:t[0])},e.name))})):l().createElement(V,{type:"secondary"},"—")}),l().createElement(X,{label:u("Reviewers"),value:(null==(r=c.reviewers)?void 0:r.length)>0?l().createElement(a.Space,{size:4,wrap:!0},c.reviewers.map(function(e){return l().createElement(a.Tag,{key:e.username},e.name)})):l().createElement(V,{type:"secondary"},"—")}),l().createElement(X,{label:u("Labels"),value:(null==(i=c.labels)?void 0:i.length)>0?l().createElement(a.Space,{size:4,wrap:!0},c.labels.map(function(e){return l().createElement(a.Tag,{key:e},e)})):l().createElement(V,{type:"secondary"},"—")}),l().createElement(X,{label:u("Created"),value:l().createElement(V,null,en(c.createdAt))}),l().createElement(X,{label:u("Updated"),value:l().createElement(V,null,en(c.updatedAt))}),c.mergedBy&&l().createElement(X,{label:u("Merged by"),value:l().createElement(V,null,c.mergedBy.name," — ",en(c.mergedAt))}),c.closedBy&&l().createElement(X,{label:u("Closed by"),value:l().createElement(V,null,c.closedBy.name," — ",en(c.closedAt))})))},X=function(e){var t=e.label,n=e.value;return l().createElement("div",null,l().createElement(V,{type:"secondary",style:{fontSize:12,display:"block",marginBottom:2}},t),l().createElement("div",null,n))},Y=function(e){var t=e.changes,n=$().token,o=(0,s.k)(),i=W((0,r.useState)(null),2),c=i[0],u=i[1];return t.length?l().createElement("div",null,t.map(function(e,t){var r=e.newPath||e.oldPath,o=c===r,i=null;return i=e.newFile?l().createElement(a.Tag,{color:"green"},"NEW"):e.deletedFile?l().createElement(a.Tag,{color:"red"},"DEL"):e.renamedFile?l().createElement(a.Tag,{color:"orange"},"RENAMED"):l().createElement(a.Tag,{color:"blue"},"MOD"),l().createElement("div",{key:t,style:{marginBottom:8}},l().createElement("div",{style:{padding:"6px 12px",background:o?n.colorPrimaryBg:n.colorBgLayout,borderRadius:6,cursor:"pointer",display:"flex",alignItems:"center",gap:8},onClick:function(){return u(o?null:r)}},i,l().createElement(V,{style:{fontSize:13,fontFamily:"monospace"}},r),e.renamedFile&&e.oldPath!==e.newPath&&l().createElement(V,{type:"secondary",style:{fontSize:11}},"(← ",e.oldPath,")")),o&&e.diff&&l().createElement(ee,{content:e.diff}))})):l().createElement(a.Empty,{description:o("No changes")})},Z=function(e){var t=e.notes,n=$().token,r=(0,s.k)();return t.length?l().createElement("div",null,t.map(function(e){var t,o,i,c,u;return l().createElement("div",{key:e.id,style:{padding:"12px 16px",marginBottom:12,background:n.colorBgLayout,borderRadius:8,borderLeft:"3px solid ".concat(e.resolved?n.colorSuccess:n.colorBorderSecondary)}},l().createElement("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8}},l().createElement(a.Avatar,{size:"small",src:null==(t=e.author)?void 0:t.avatarUrl},null==(i=e.author)||null==(o=i.name)?void 0:o[0]),l().createElement(V,{strong:!0,style:{fontSize:13}},null==(c=e.author)?void 0:c.name),l().createElement(V,{type:"secondary",style:{fontSize:12}},"@",null==(u=e.author)?void 0:u.username),l().createElement(V,{type:"secondary",style:{fontSize:11,marginLeft:"auto"}},et(e.createdAt)),e.resolvable&&l().createElement(a.Tag,{color:e.resolved?"success":"default",style:{fontSize:11}},e.resolved?r("Resolved"):r("Unresolved"))),l().createElement("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:13,lineHeight:1.6}},e.body))})):l().createElement(a.Empty,{description:r("No comments")})},ee=(0,r.memo)(function(e){var t=e.content,n=$().token,r=t.split("\n");return l().createElement("div",{style:{fontFamily:"'JetBrains Mono', 'Fira Code', Consolas, monospace",fontSize:12,lineHeight:1.5,border:"1px solid ".concat(n.colorBorderSecondary),borderRadius:6,overflow:"auto",maxHeight:400,margin:"4px 0"}},r.map(function(e,t){var r="transparent",a=n.colorText;return e.startsWith("+")&&!e.startsWith("+++")?(r="rgba(46, 160, 67, 0.12)",a="#2ea043"):e.startsWith("-")&&!e.startsWith("---")?(r="rgba(248, 81, 73, 0.12)",a="#f85149"):e.startsWith("@@")?(r="rgba(56, 139, 253, 0.08)",a="#388bfd"):(e.startsWith("diff")||e.startsWith("index"))&&(a=n.colorTextSecondary),l().createElement("div",{key:t,style:{padding:"0 12px",background:r,color:a,whiteSpace:"pre",minHeight:20}},l().createElement("span",{style:{display:"inline-block",width:40,color:n.colorTextQuaternary,userSelect:"none",textAlign:"right",marginRight:12}},t+1),e)}))});function et(e){if(!e)return"";var t=new Date(e),n=new Date().getTime()-t.getTime(),r=n/36e5;return r<1?"".concat(Math.round(n/6e4),"m ago"):r<24?"".concat(Math.round(r),"h ago"):r<168?"".concat(Math.round(r/24),"d ago"):t.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function en(e){return e?new Date(e).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):""}function er(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function el(e,t,n,r,l,a,o){try{var i=e[a](o),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,l)}function ea(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){el(a,r,l,o,i,"next",e)}function i(e){el(a,r,l,o,i,"throw",e)}o(void 0)})}}function eo(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||ec(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ei(e){return function(e){if(Array.isArray(e))return er(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||ec(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ec(e,t){if(e){if("string"==typeof e)return er(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return er(e,t)}}function eu(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:c(0)}),i(o,"throw",{value:c(1)}),i(o,"return",{value:c(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){a.label=u[1];break}if(6===u[0]&&a.label<l[1]){a.label=l[1],l=u;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(u);break}l[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var es=a.Typography.Text,ed=a.theme.useToken,em={not_added:{color:"green",icon:l().createElement(o.FileAddOutlined,null),label:"New"},modified:{color:"blue",icon:l().createElement(o.EditOutlined,null),label:"Modified"},deleted:{color:"red",icon:l().createElement(o.DeleteOutlined,null),label:"Deleted"},renamed:{color:"orange",icon:l().createElement(o.EditOutlined,null),label:"Renamed"},conflicted:{color:"red",icon:l().createElement(o.WarningOutlined,null),label:"Conflict"},created:{color:"green",icon:l().createElement(o.FileAddOutlined,null),label:"Created"}},ep=function(){var e,t,n,u,d,m,p=(0,s.k)(),f=ed().token,y=(0,c.useApp)().apiClient,g=(0,i.B)(),v=g.selectedRepo,h=g.refreshRepos,b=eo((0,r.useState)(null),2),E=b[0],w=b[1],S=eo((0,r.useState)(null),2),k=S[0],O=S[1],C=eo((0,r.useState)(null),2),x=C[0],I=C[1],A=(0,r.useCallback)(function(){return ea(function(){var e,t;return eu(this,function(n){switch(n.label){case 0:if(!v||"connected"!==v.status)return O(null),[2];w("status"),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,y.request({url:"gitManager:status",method:"post",params:{repositoryId:v.id}})];case 2:return O((null==(t=n.sent().data)||null==(e=t.data)?void 0:e.data)||(null==t?void 0:t.data)),[3,5];case 3:return console.warn("Failed to load git status:",n.sent()),O(null),[3,5];case 4:return w(null),[7];case 5:return[2]}})})()},[y,v]);(0,r.useEffect)(function(){A()},[A]);var T=(0,r.useCallback)(function(e){return ea(function(){var t,n,r,l,o,i,c,u,s;return eu(this,function(d){switch(d.label){case 0:if(!v)return[2];w(e),I(null),d.label=1;case 1:return d.trys.push([1,6,7,8]),[4,y.request({url:"gitManager:".concat(e),method:"post",params:{repositoryId:v.id}})];case 2:if(n=d.sent().data,I({action:e,success:!0,message:p("{{action}} completed successfully",{action:e})}),a.message.success(p("{{action}} completed",{action:e})),r=(null==n||null==(t=n.data)?void 0:t.data)||(null==n?void 0:n.data),"status"===e&&O(r),"fetch"!==e&&"pull"!==e)return[3,4];return[4,A()];case 3:d.sent(),d.label=4;case 4:return[4,h()];case 5:return d.sent(),[3,8];case 6:return s=(null==(l=d.sent())||null==(u=l.response)||null==(c=u.data)||null==(i=c.errors)||null==(o=i[0])?void 0:o.message)||p("{{action}} failed",{action:e}),I({action:e,success:!1,message:s}),a.message.error(s),[3,8];case 7:return w(null),[7];case 8:return[2]}})})()},[y,v,h,A]);if(!v)return l().createElement(a.Empty,{description:p("No repository selected")});if("connected"!==v.status)return l().createElement(a.Empty,{description:p("Repository not cloned yet")});var P=k?ei((null==(e=k.not_added)?void 0:e.map(function(e){return{file:e,status:"not_added"}}))||[]).concat(ei((null==(t=k.modified)?void 0:t.map(function(e){return{file:e,status:"modified"}}))||[]),ei((null==(n=k.deleted)?void 0:n.map(function(e){return{file:e,status:"deleted"}}))||[]),ei((null==(u=k.renamed)?void 0:u.map(function(e){return{file:"string"==typeof e?e:e.to,status:"renamed"}}))||[]),ei((null==(d=k.conflicted)?void 0:d.map(function(e){return{file:e,status:"conflicted"}}))||[]),ei((null==(m=k.created)?void 0:m.map(function(e){return{file:e,status:"created"}}))||[])):[];return l().createElement("div",null,l().createElement(a.Space,{size:"middle",wrap:!0,style:{marginBottom:24}},l().createElement(a.Button,{size:"large",icon:l().createElement(o.SyncOutlined,null),loading:"fetch"===E,onClick:function(){return T("fetch")}},p("Fetch")),l().createElement(a.Button,{size:"large",type:"primary",icon:l().createElement(o.CloudDownloadOutlined,null),loading:"pull"===E,onClick:function(){return T("pull")}},p("Pull")),l().createElement(a.Button,{size:"large",icon:l().createElement(o.BranchesOutlined,null),loading:"status"===E,onClick:A},p("Status"))),x&&l().createElement(a.Card,{size:"small",style:{marginBottom:16,borderColor:x.success?f.colorSuccessBorder:f.colorErrorBorder}},l().createElement(a.Space,null,x.success?l().createElement(o.CheckCircleOutlined,{style:{color:f.colorSuccess}}):l().createElement(o.WarningOutlined,{style:{color:f.colorError}}),l().createElement(es,{strong:!0},x.action),l().createElement(es,null,x.message))),k&&l().createElement(a.Card,{title:p("Working Directory Status"),size:"small"},l().createElement(a.Descriptions,{column:3,size:"small",style:{marginBottom:16}},l().createElement(a.Descriptions.Item,{label:"Branch"},l().createElement(a.Tag,{icon:l().createElement(o.BranchesOutlined,null),color:"blue"},k.current)),l().createElement(a.Descriptions.Item,{label:"Tracking"},l().createElement(es,null,k.tracking||"N/A")),l().createElement(a.Descriptions.Item,{label:"Changes"},l().createElement(a.Space,null,k.ahead>0&&l().createElement(a.Badge,{count:"".concat(k.ahead," ahead"),style:{backgroundColor:f.colorPrimary}}),k.behind>0&&l().createElement(a.Badge,{count:"".concat(k.behind," behind"),style:{backgroundColor:f.colorWarning}}),0===k.ahead&&0===k.behind&&l().createElement(a.Tag,{color:"green",icon:l().createElement(o.CheckCircleOutlined,null)},"Up to date")))),P.length>0?l().createElement(l().Fragment,null,l().createElement(es,{strong:!0,style:{display:"block",marginBottom:8}},P.length," changed file(s)"),l().createElement(a.List,{size:"small",dataSource:P,renderItem:function(e){var t=em[e.status]||{color:"default",icon:l().createElement(o.QuestionCircleOutlined,null),label:e.status};return l().createElement(a.List.Item,{style:{padding:"4px 0"}},l().createElement(a.Space,null,l().createElement(a.Tag,{color:t.color,style:{minWidth:80,textAlign:"center"}},t.icon," ",t.label),l().createElement(es,{code:!0,style:{fontSize:13}},e.file)))}})):l().createElement(es,{type:"secondary"},"Working directory clean")))};function ef(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function ey(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return ef(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ef(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var eg=function(e){var t=e.value,n=e.onChange,o=e.allowClear,i=e.size,u=e.style,s=e.placeholder,d=(0,c.useApp)().apiClient,m=ey((0,r.useState)([]),2),p=m[0],f=m[1],y=ey((0,r.useState)(!1),2),g=y[0],v=y[1];return(0,r.useEffect)(function(){var e=!1;return v(!0),d.request({url:"aiEmployees:listByUser"}).then(function(t){if(!e){var n,r=(null==t||null==(n=t.data)?void 0:n.data)||[];f(Array.isArray(r)?r:[])}}).catch(function(){}).finally(function(){e||v(!1)}),function(){e=!0}},[d]),l().createElement(a.Select,{value:t,onChange:n,allowClear:void 0===o||o,loading:g,size:i,style:u,placeholder:s||"Select AI employee",options:p.map(function(e){return{value:e.username,label:"".concat(e.nickname||e.username," (@").concat(e.username,")")}}),showSearch:!0,optionFilterProp:"label"})};function ev(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function eh(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return ev(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ev(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var eb=function(e){var t=e.value,n=e.onChange,o=e.allowClear,i=e.size,u=e.style,s=e.placeholder,d=(0,c.useApp)().apiClient,m=eh((0,r.useState)([]),2),p=m[0],f=m[1],y=eh((0,r.useState)(!1),2),g=y[0],v=y[1];return(0,r.useEffect)(function(){var e=!1;return v(!0),d.request({url:"ai:listAllEnabledModels"}).then(function(t){if(!e){var n,r=(null==t||null==(n=t.data)?void 0:n.data)||[];f(Array.isArray(r)?r:[])}}).catch(function(){}).finally(function(){e||v(!1)}),function(){e=!0}},[d]),l().createElement(a.Select,{value:t,onChange:n,allowClear:void 0===o||o,loading:g,size:i,style:u,placeholder:s||"Select LLM Service",options:p.map(function(e){return{value:e.llmService,label:e.llmServiceTitle||e.llmService}}),showSearch:!0,optionFilterProp:"label"})};function eE(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function ew(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return eE(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return eE(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var eS=function(e){var t=e.llmService,n=e.value,o=e.onChange,i=e.allowClear,u=e.size,s=e.style,d=e.placeholder,m=(0,c.useApp)().apiClient,p=ew((0,r.useState)([]),2),f=p[0],y=p[1],g=ew((0,r.useState)(!1),2),v=g[0],h=g[1];return(0,r.useEffect)(function(){var e=!1;return t?(h(!0),m.request({url:"ai:listModels",params:{llmService:t}}).then(function(t){if(!e){var n,r=(null==t||null==(n=t.data)?void 0:n.data)||[];y(Array.isArray(r)?r:[])}}).catch(function(){e||y([])}).finally(function(){e||h(!1)}),function(){e=!0}):void y([])},[m,t]),l().createElement(a.Select,{value:n,onChange:o,allowClear:void 0===i||i,loading:v,size:u,style:s,placeholder:d||"Select LLM Model",options:f.map(function(e){return{value:e.id,label:e.id}}),showSearch:!0,optionFilterProp:"label",disabled:!t})};function ek(e,t){return"".concat(e.replace(/\/+$/,""),"/").concat(t.replace(/^\/+/,""))}function eO(e){var t="u"<typeof window?void 0:window.__nocobase_public_path__;return(0,c.stripModernClientPrefix)(t||e.getPublicPath())}function eC(e,t,n){var r="modern"===(0,c.getRouteRuntimeVersion)(),l=r?"/admin/workflow/".concat("workflow"===t?"workflows":"executions","/").concat(encodeURIComponent(String(n))):"/admin/settings/workflow/".concat("workflow"===t?"workflows":"executions","/").concat(encodeURIComponent(String(n)));return ek(r?(0,c.getV2EffectiveBasePath)(e):eO(e),l)}function ex(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function eI(e,t,n,r,l,a,o){try{var i=e[a](o),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,l)}function eA(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){eI(a,r,l,o,i,"next",e)}function i(e){eI(a,r,l,o,i,"throw",e)}o(void 0)})}}function eT(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return ex(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ex(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function eP(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:c(0)}),i(o,"throw",{value:c(1)}),i(o,"return",{value:c(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){a.label=u[1];break}if(6===u[0]&&a.label<l[1]){a.label=l[1],l=u;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(u);break}l[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var eR={manual:"Manual",onMergeRequestCreated:"On MR Created",both:"Both"},eB={auto:"Auto",manual:"Manual",disabled:"Disabled"},ez=function(){var e=(0,s.k)(),t=(0,c.useApp)(),n=t.apiClient,d=(0,i.B)().repos,m=eT((0,r.useState)([]),2),p=m[0],f=m[1],y=eT((0,r.useState)(!1),2),g=y[0],v=y[1],h=eT((0,r.useState)(null),2),b=h[0],E=h[1],w=eT((0,r.useState)(!1),2),S=w[0],k=w[1],O=eT((0,r.useState)(),2),C=O[0],x=O[1],I=eT(a.Form.useForm(),1)[0],A=(0,r.useCallback)(function(){return eA(function(){var e;return eP(this,function(t){switch(t.label){case 0:v(!0),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,n.request({url:"gitReviewFlows:list",params:{pageSize:100}})];case 2:return f((null==(e=t.sent().data)?void 0:e.data)||[]),[3,4];case 3:return v(!1),[7];case 4:return[2]}})})()},[n]);(0,r.useEffect)(function(){A()},[A]);var T=function(e){E(e),x(void 0),I.setFieldsValue(e),k(!0)},P=[{title:e("Name"),dataIndex:"name",render:function(t,n){return l().createElement(a.Space,null,l().createElement("span",{style:{fontWeight:500}},t),!n.enabled&&l().createElement(a.Tag,{color:"default"},e("Disabled")))}},{title:e("Repository"),dataIndex:"repositoryId",render:function(t){if(null==t)return l().createElement(a.Tag,{color:"purple"},e("Global"));var n=d.find(function(e){return e.id===t});return n?l().createElement(a.Space,{size:4},l().createElement(o.BranchesOutlined,null),n.name):"#".concat(t)}},{title:e("AI Employee"),dataIndex:"aiEmployeeUsername",render:function(e){return e?l().createElement(a.Tag,{color:"blue"},"@",e):l().createElement("span",{style:{color:"#999"}},"—")}},{title:e("Trigger"),dataIndex:"triggerMode",render:function(t){return l().createElement(a.Tag,null,e(eR[t]||t))}},{title:e("Post"),dataIndex:"postMode",render:function(t){return l().createElement(a.Tag,{color:"auto"===t?"green":"manual"===t?"orange":"default"},e(eB[t]||t))}},{title:"",key:"actions",width:100,render:function(t,r){return l().createElement(a.Space,null,l().createElement(a.Tooltip,{title:e("Edit")},l().createElement(a.Button,{size:"small",icon:l().createElement(o.EditOutlined,null),onClick:function(){return T(r)}})),l().createElement(a.Popconfirm,{title:e("Delete this flow?"),onConfirm:function(){var t;return t=r.id,eA(function(){var r;return eP(this,function(l){switch(l.label){case 0:return l.trys.push([0,2,,3]),[4,n.request({url:"gitReviewFlows:destroy",method:"post",params:{filterByTk:t}})];case 1:return l.sent(),a.message.success(e("Flow deleted")),A(),[3,3];case 2:return r=l.sent(),a.message.error((null==r?void 0:r.message)||e("Failed to delete")),[3,3];case 3:return[2]}})})()}},l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(o.DeleteOutlined,null)})))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:12,display:"flex",justifyContent:"space-between"}},l().createElement(a.Button,{type:"primary",icon:l().createElement(o.PlusOutlined,null),onClick:function(){var e;E(null),I.resetFields(),x("application"),I.setFieldsValue({enabled:!0,triggerMode:"manual",postMode:"manual",instructions:null==(e=u.find(function(e){return"application"===e.key}))?void 0:e.text}),k(!0)}},e("Add Review Flow")),l().createElement(a.Button,{onClick:A,loading:g},e("Refresh"))),l().createElement(a.Table,{size:"small",rowKey:"id",loading:g,dataSource:p,columns:P,locale:{emptyText:l().createElement(a.Empty,{description:e("No review flows yet")})},pagination:{pageSize:20}}),l().createElement(a.Modal,{title:(null==b?void 0:b.id)?e("Edit Review Flow"):e("Add Review Flow"),open:S,onCancel:function(){k(!1),E(null),x(void 0),I.resetFields()},onOk:function(){return eA(function(){var t,r,l,o,i,c;return eP(this,function(u){switch(u.label){case 0:return u.trys.push([0,6,,7]),[4,I.validateFields()];case 1:if((void 0===(t=u.sent()).repositoryId||""===t.repositoryId)&&(t.repositoryId=null),!(null==b?void 0:b.id))return[3,3];return[4,n.request({url:"gitReviewFlows:update",method:"post",params:{filterByTk:b.id},data:t})];case 2:return u.sent(),a.message.success(e("Flow updated")),[3,5];case 3:return[4,n.request({url:"gitReviewFlows:create",method:"post",data:t})];case 4:u.sent(),a.message.success(e("Flow created")),u.label=5;case 5:return k(!1),E(null),x(void 0),I.resetFields(),A(),[3,7];case 6:if(null==(r=u.sent())?void 0:r.errorFields)return[2];return a.message.error((null==r||null==(c=r.response)||null==(i=c.data)||null==(o=i.errors)||null==(l=o[0])?void 0:l.message)||(null==r?void 0:r.message)||e("Failed to save")),[3,7];case 7:return[2]}})})()},width:640,destroyOnClose:!0},l().createElement(a.Form,{form:I,layout:"vertical"},(null==b?void 0:b.workflowId)&&l().createElement(a.Alert,{type:"info",showIcon:!0,message:e("Edit the AI employee, model and prompt in the bound workflow"),action:l().createElement(a.Button,{href:eC(t,"workflow",b.workflowId),target:"_blank",rel:"noreferrer"},e("Open workflow")),style:{marginBottom:16}}),l().createElement(a.Form.Item,{name:"name",label:e("Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:e("e.g. Default review flow")})),l().createElement(a.Form.Item,{name:"repositoryId",label:e("Repository"),extra:e("Leave empty to apply to all repositories")},l().createElement(a.Select,{allowClear:!0,placeholder:e("All repositories (global)"),options:d.map(function(e){return{value:e.id,label:e.name}})})),l().createElement(a.Form.Item,{name:"aiEmployeeUsername",label:e("AI Employee"),rules:[{required:!0}],hidden:!!(null==b?void 0:b.workflowId)},l().createElement(eg,{placeholder:e("Select an AI employee")})),!(null==b?void 0:b.workflowId)&&l().createElement(a.Space.Compact,{style:{width:"100%"}},l().createElement(a.Form.Item,{name:"llmService",label:e("LLM Service (optional)"),style:{flex:1,marginRight:8}},l().createElement(eb,{placeholder:e("Override flow LLM service")})),l().createElement(a.Form.Item,{noStyle:!0,shouldUpdate:function(e,t){return e.llmService!==t.llmService}},function(t){var n=(0,t.getFieldValue)("llmService");return l().createElement(a.Form.Item,{name:"model",label:e("Model (optional)"),style:{flex:1}},n?l().createElement(eS,{llmService:n,placeholder:e("Override LLM model")}):l().createElement(a.Input,{placeholder:e("Select an LLM service first"),disabled:!0}))})),l().createElement(a.Form.Item,{name:"triggerMode",label:e("Trigger Mode"),rules:[{required:!0}],extra:e("Auto modes require enabling Auto Review on the repository")},l().createElement(a.Select,{options:[{value:"manual",label:e("Manual")},{value:"onMergeRequestCreated",label:e("On Merge Request Created")},{value:"both",label:e("Both")}]})),l().createElement(a.Form.Item,{name:"reviewOnNewCommits",label:e("Review new commits automatically"),valuePropName:"checked",extra:e("Only applies to automatic merge request reviews")},l().createElement(a.Switch,null)),l().createElement(a.Form.Item,{name:"postMode",label:e("Post Mode"),rules:[{required:!0}],extra:(null==b?void 0:b.workflowId)?e("Reconfigure the workflow after changing post mode"):void 0},l().createElement(a.Select,{options:[{value:"auto",label:e("Auto post to MR")},{value:"manual",label:e("Manual approval before posting")},{value:"disabled",label:e("Do not post")}]})),l().createElement(a.Form.Item,{name:"branchFilter",label:e("Branch Filter (regex, optional)")},l().createElement(a.Input,{placeholder:"^(feature|hotfix)/.*$"})),!(null==b?void 0:b.workflowId)&&l().createElement(a.Form.Item,{label:e("Prompt template"),extra:e("Selecting a template replaces the instructions text")},l().createElement(a.Select,{allowClear:!0,value:C,placeholder:e("Load a default prompt by code type"),options:u.map(function(t){return{value:t.key,label:e(t.label)}}),onChange:function(e){x(e);var t=u.find(function(t){return t.key===e});t&&I.setFieldsValue({instructions:t.text})}})),!(null==b?void 0:b.workflowId)&&l().createElement(a.Form.Item,{name:"instructions",label:e("Additional Instructions (optional)")},l().createElement(a.Input.TextArea,{rows:8,placeholder:e("Extra guidance appended to every review prompt")})),l().createElement(a.Form.Item,{name:"enabled",label:e("Enabled"),valuePropName:"checked"},l().createElement(a.Switch,null)))))},ej=n(664),eM=a.theme.useToken,eF=function(e){var t=e.content,n=e.maxHeight,r=eM().token;return t?l().createElement("div",{style:{fontSize:13,lineHeight:1.65,color:r.colorText,maxHeight:n,overflow:n?"auto":void 0}},l().createElement(ej.oz,{components:{code:function(e){var t,n,a=e.inline,o=e.children,i=function(e,t){if(null==e)return{};var n,r,l,a={};if("u">typeof Reflect&&Reflect.ownKeys){for(l=0,n=Reflect.ownKeys(Object(e));l<n.length;l++)r=n[l],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r]);return a}if(a=function(e,t){if(null==e)return{};var n,r,l={},a=Object.getOwnPropertyNames(e);for(r=0;r<a.length;r++)n=a[r],!(t.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(e,n)&&(l[n]=e[n]);return l}(e,t),Object.getOwnPropertySymbols)for(l=0,n=Object.getOwnPropertySymbols(e);l<n.length;l++)r=n[l],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r]);return a}(e,["inline","children"]),c=String(o).replace(/\n$/,"");return a?l().createElement("code",(t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},i),n=n={style:{background:r.colorBgLayout,padding:"1px 6px",borderRadius:4,fontSize:12,fontFamily:"'JetBrains Mono', 'Fira Code', Consolas, monospace"}},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t),c):l().createElement("pre",{style:{background:r.colorBgLayout,padding:"10px 14px",borderRadius:6,overflowX:"auto",fontSize:12,fontFamily:"'JetBrains Mono', 'Fira Code', Consolas, monospace"}},l().createElement("code",null,c))},blockquote:function(e){var t=e.children;return l().createElement("blockquote",{style:{borderLeft:"3px solid ".concat(r.colorBorder),paddingLeft:12,color:r.colorTextSecondary,margin:"8px 0"}},t)}}},t)):null};function eD(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function eL(e,t,n,r,l,a,o){try{var i=e[a](o),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,l)}function eq(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){eL(a,r,l,o,i,"next",e)}function i(e){eL(a,r,l,o,i,"throw",e)}o(void 0)})}}function eN(e,t){return null!=t&&"u">typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function eU(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function e_(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return eD(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return eD(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function eH(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:c(0)}),i(o,"throw",{value:c(1)}),i(o,"return",{value:c(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){a.label=u[1];break}if(6===u[0]&&a.label<l[1]){a.label=l[1],l=u;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(u);break}l[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var eW=a.Typography.Text;a.Typography.Title,a.Typography.Paragraph;var eG=a.theme.useToken,eV={pending:"default",queued:"default",running:"blue",completed:"green",failed:"red"},e$={pending_approval:"orange",approved:"cyan",posted:"green",post_failed:"red",post_unknown:"orange",posting:"blue",retrying:"blue",skipped:"default",rejected:"red"},eJ=function(e){var t=e.initialFilter,n=(0,s.k)();eG().token;var u=(0,c.useApp)().apiClient,d=(0,i.B)().repos,m=e_((0,r.useState)([]),2),p=m[0],f=m[1],y=e_((0,r.useState)(!1),2),g=y[0],v=y[1],h=e_((0,r.useState)("all"),2),b=h[0],E=h[1],w=e_((0,r.useState)("pending_approval"===(void 0===t?"all":t)?"pending_approval":"all"),2),S=w[0],k=w[1],O=e_((0,r.useState)("all"),2),C=O[0],x=O[1],I=e_((0,r.useState)(null),2),A=I[0],T=I[1],P=e_((0,r.useState)(!1),2),R=P[0],B=P[1],z=e_((0,r.useState)(!1),2),j=z[0],M=z[1],F=e_((0,r.useState)(null),2),D=F[0],L=F[1],q=e_((0,r.useState)(""),2),N=q[0],U=q[1],_=(0,r.useCallback)(function(){return eq(function(){var e,t;return eH(this,function(n){switch(n.label){case 0:v(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),e={},"all"!==b&&(e.status=b),"all"!==S&&(e.postStatus=S),"all"!==C&&(e.triggeredBy=C),[4,u.request({url:"gitCodeReviews:list",params:{pageSize:50,sort:["-id"],filter:Object.keys(e).length?e:void 0}})];case 2:return f((null==(t=n.sent().data)?void 0:t.data)||[]),[3,4];case 3:return v(!1),[7];case 4:return[2]}})})()},[u,b,S,C]);(0,r.useEffect)(function(){_()},[_]),(0,r.useEffect)(function(){if(p.some(function(e){return"running"===e.status||"pending"===e.status||"queued"===e.status})){var e=setInterval(_,4e3);return function(){return clearInterval(e)}}},[p,_]);var H=(0,r.useCallback)(function(e){return eq(function(){var t,n;return eH(this,function(r){switch(r.label){case 0:return[4,u.request({url:"gitCodeReviews:get",params:{filterByTk:e}})];case 1:return(n=null==(t=r.sent().data)?void 0:t.data)&&(f(function(t){return t.map(function(t){return t.id===e?n:t})}),(null==A?void 0:A.id)===e&&T(n)),[2]}})})()},[u,A]),W=(0,r.useMemo)(function(){var e={};return d.forEach(function(t){return e[t.id]=t}),e},[d]),G=[{title:n("Target"),key:"target",render:function(e,t){var n=W[t.repositoryId],r=(null==n?void 0:n.name)||"#".concat(t.repositoryId);return"mr"===t.targetType?l().createElement(a.Space,{size:4},l().createElement(eW,{strong:!0},r),l().createElement(eW,{type:"secondary"},"!",t.mrIid)):"commit"===t.targetType?l().createElement(a.Space,{size:4},l().createElement(eW,{strong:!0},r),l().createElement(eW,{type:"secondary",style:{fontFamily:"monospace"}},String(t.commitSha||"").slice(0,7))):"folder"===t.targetType?l().createElement(a.Space,{size:4},l().createElement(eW,{strong:!0},r),l().createElement(eW,{type:"secondary"},t.folderPath||"/"),t.branch&&l().createElement(a.Tag,{style:{fontSize:11}},t.branch)):l().createElement(a.Space,{size:4},l().createElement(eW,{strong:!0},r),l().createElement(eW,{type:"secondary"},t.branch))}},{title:n("Type"),dataIndex:"targetType",width:80,render:function(e){return l().createElement(a.Tag,null,n(e.toUpperCase()))}},{title:n("Status"),dataIndex:"status",width:120,render:function(e){var t=eV[e]||"default",r="running"===e?l().createElement(o.ClockCircleOutlined,{spin:!0}):null;return l().createElement(a.Tag,{color:t,icon:r},n(e))}},{title:n("Post Status"),dataIndex:"postStatus",width:140,render:function(e){return l().createElement(a.Tag,{color:e$[e]||"default"},n(e))}},{title:n("Commit"),key:"sha",width:140,render:function(e,t){var r=t.headSha,o=t.latestSha;return r?l().createElement(a.Space,{size:4},l().createElement(a.Tag,{style:{fontFamily:"monospace",fontSize:11}},String(r).slice(0,7)),r&&o&&r!==o&&l().createElement(a.Tooltip,{title:"".concat(n("New commits"),": ").concat(String(o).slice(0,7))},l().createElement(a.Tag,{color:"orange",style:{fontSize:11}},n("new")))):l().createElement(eW,{type:"secondary"},"—")}},{title:n("Trigger"),dataIndex:"triggeredBy",width:90,render:function(e){return l().createElement(a.Tag,{color:"poll"===e?"geekblue":"default",style:{fontSize:11}},"poll"===e?n("Polling"):n("Manual"))}},{title:n("Duration"),dataIndex:"durationMs",width:90,render:function(e){return e?"".concat((e/1e3).toFixed(1),"s"):"—"}},{title:n("Created"),dataIndex:"createdAt",width:160,render:function(e){return e?new Date(e).toLocaleString():""}},{title:"",key:"actions",width:60,render:function(e,t){return l().createElement(a.Tooltip,{title:n("View")},l().createElement(a.Button,{size:"small",icon:l().createElement(o.FileTextOutlined,null),onClick:function(){T(t),B(!1),U(t.reviewMarkdown||"")}}))}}];return l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:12},wrap:!0},l().createElement(a.Select,{size:"small",style:{width:140},value:b,onChange:E,options:[{value:"all",label:n("All statuses")},{value:"pending",label:n("pending")},{value:"queued",label:n("queued")},{value:"running",label:n("running")},{value:"completed",label:n("completed")},{value:"failed",label:n("failed")}]}),l().createElement(a.Select,{size:"small",style:{width:180},value:S,onChange:k,options:[{value:"all",label:n("All post statuses")},{value:"pending_approval",label:n("pending_approval")},{value:"approved",label:n("approved")},{value:"posted",label:n("posted")},{value:"post_failed",label:n("post_failed")},{value:"post_unknown",label:n("post_unknown")},{value:"posting",label:n("posting")},{value:"skipped",label:n("skipped")},{value:"rejected",label:n("rejected")}]}),l().createElement(a.Select,{size:"small",style:{width:130},value:C,onChange:x,options:[{value:"all",label:n("All triggers")},{value:"manual",label:n("Manual")},{value:"poll",label:n("Polling")}]}),l().createElement(a.Button,{size:"small",icon:l().createElement(o.ReloadOutlined,null),onClick:_},n("Refresh"))),l().createElement(a.Table,{size:"small",rowKey:"id",loading:g,dataSource:p,columns:G,locale:{emptyText:l().createElement(a.Empty,{description:n("No reviews yet")})},pagination:{pageSize:20},onRow:function(e){return{style:{cursor:"pointer"},onClick:function(){T(e),B(!1),L(null),U(e.reviewMarkdown||"")}}}}),l().createElement(a.Drawer,{title:A?l().createElement(a.Space,null,l().createElement(o.RobotOutlined,null),l().createElement("span",null,n("Code Review")),l().createElement(a.Tag,{color:eV[A.status]},n(A.status)),l().createElement(a.Tag,{color:e$[A.postStatus]},n(A.postStatus))):n("Code Review"),open:!!A,onClose:function(){T(null),B(!1)},width:840,extra:A&&l().createElement(a.Space,null,l().createElement(a.Button,{size:"small",icon:l().createElement(o.ReloadOutlined,null),onClick:function(){return H(A.id)}},n("Refresh")),"mr"===A.targetType&&l().createElement(a.Button,{size:"small",icon:l().createElement(o.ExportOutlined,null),onClick:function(){var e,t=W[A.repositoryId],n=null==t||null==(e=t.repoUrl)?void 0:e.replace(/\.git$/,"");n&&A.mrIid&&window.open("".concat(n,"/-/merge_requests/").concat(A.mrIid),"_blank")}},n("Open MR")))},A&&l().createElement(eK,{review:A,editing:R,editedMarkdown:N,onEdit:function(){return B(!0)},onCancelEdit:function(){B(!1),U(A.reviewMarkdown||"")},onChangeMarkdown:U,onApprove:function(e){return eq(function(){var t,r,l,o,i,c,s,d,m;return eH(this,function(p){switch(p.label){case 0:if(!A)return[2];p.label=1;case 1:return p.trys.push([1,3,,4]),[4,u.request({url:"gitManager:reviewApprovePost",method:"post",data:{reviewId:A.id,editedMarkdown:e,baseConfirmation:"LEGACY_BASE_UNVERIFIED"}})];case 2:return(null==(o=(null==(l=null==(r=p.sent())||null==(t=r.data)?void 0:t.data)?void 0:l.success)?l.data:l)?void 0:o.status)==="posted"?a.message.success(n("Review posted to merge request")):(null==o?void 0:o.status)==="observed"?a.message.warning(n("A matching comment was found, but its attempt cannot be confirmed")):a.message.warning(n("Publication outcome is still unknown")),B(!1),H(A.id),_(),[3,4];case 3:return i=p.sent(),a.message.error((null==i||null==(m=i.response)||null==(d=m.data)||null==(s=d.errors)||null==(c=s[0])?void 0:c.message)||(null==i?void 0:i.message)||n("Failed to post review")),[3,4];case 4:return[2]}})})()},onReject:function(){return eq(function(){var e;return eH(this,function(t){switch(t.label){case 0:if(!A)return[2];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,u.request({url:"gitManager:reviewReject",method:"post",data:{reviewId:A.id}})];case 2:return t.sent(),a.message.success(n("Review rejected")),H(A.id),_(),[3,4];case 3:return e=t.sent(),a.message.error((null==e?void 0:e.message)||n("Failed to reject")),[3,4];case 4:return[2]}})})()},onRetryPost:function(e){return eq(function(){var t,r,l,o,i,c,s,d,m;return eH(this,function(p){switch(p.label){case 0:if(!A)return[2];M(!0),p.label=1;case 1:return p.trys.push([1,5,6,7]),[4,u.request({url:"gitManager:reviewWorkflowRetryPost",method:"post",data:eU({reviewId:A.id},e?{confirmation:"OUTBOUND_POST_STOPPED"}:{})})];case 2:return(null==(l=null==(r=p.sent())||null==(t=r.data)?void 0:t.data)?void 0:l.status)==="posted"?a.message.success(n("Review publication confirmed")):(null==l?void 0:l.status)==="observed"?a.message.info(n("Matching comment found; another publication attempt still owns the review")):(null==l?void 0:l.canResend)?a.message.warning(n("No matching comment found; confirm the previous post stopped before retrying")):a.message.warning(n("A previous publication attempt may still be running; ask an administrator to recover it")),[4,H(A.id)];case 3:return p.sent(),[4,_()];case 4:return p.sent(),[3,7];case 5:return m=o=p.sent(),a.message.error((null==m||null==(d=m.response)||null==(s=d.data)||null==(c=s.errors)||null==(i=c[0])?void 0:i.message)||eN(o,Error)&&o.message||n("Failed to reconcile review publication")),[3,7];case 6:return M(!1),[7];case 7:return[2]}})})()},legacyPost:(null==D?void 0:D.reviewId)===A.id?D:null,onLegacyPost:function(e){return eq(function(){var t,r,l,o,i,c,s,d,m,p,f,y;return eH(this,function(g){switch(g.label){case 0:if(!A||"check"!==e&&(null==D?void 0:D.reviewId)!==A.id)return[2];M(!0),g.label=1;case 1:return g.trys.push([1,5,6,7]),l="check"===e?"reviewLegacyPostStatus":"retry"===e?"reviewLegacyRetryPost":"reviewLegacyReleaseHold",[4,u.request({url:"gitManager:".concat(l),method:"post",data:eU({reviewId:A.id},"check"===e?{}:{confirmation:"OUTBOUND_POST_STOPPED",expectedAttempt:null!=(t=null==D?void 0:D.attemptId)?t:null},"retry"===e&&(null==D?void 0:D.baseUnverified)&&!D.baseAcknowledged?{baseConfirmation:"LEGACY_BASE_UNVERIFIED"}:{})})];case 2:if(c=(null==(i=null==(o=g.sent())||null==(r=o.data)?void 0:r.data)?void 0:i.success)?i.data:i,"check"===e&&c){var v,h;L((v=eU({},c),h=h={reviewId:A.id},Object.getOwnPropertyDescriptors?Object.defineProperties(v,Object.getOwnPropertyDescriptors(h)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(h)).forEach(function(e){Object.defineProperty(v,e,Object.getOwnPropertyDescriptor(h,e))}),v))}else L(null);return(null==c?void 0:c.status)==="posted"?a.message.success(n("Review publication confirmed")):(null==c?void 0:c.status)==="observed"&&(null==c?void 0:c.canRetry)?a.message.warning(n("A matching marked comment was found; confirm the previous attempt stopped to finalize it")):(null==c?void 0:c.status)==="observed"?a.message.warning(n("A matching comment was found, but its attempt cannot be confirmed")):"release"===e?a.message.success(n("Legacy publication hold released")):"retry"===e&&a.message.warning(n("Publication outcome is still unknown")),[4,H(A.id)];case 3:return g.sent(),[4,_()];case 4:return g.sent(),[3,7];case 5:return y=s=g.sent(),a.message.error((null==y||null==(f=y.response)||null==(p=f.data)||null==(m=p.errors)||null==(d=m[0])?void 0:d.message)||eN(s,Error)&&s.message||n("Failed to reconcile review publication")),[3,7];case 6:return M(!1),[7];case 7:return[2]}})})()},reconcilingPost:j})))},eK=function(e){var t,n,r,i,u,d,m=e.review,p=e.editing,f=e.editedMarkdown,y=e.onEdit,g=e.onCancelEdit,v=e.onChangeMarkdown,h=e.onApprove,b=e.onReject,E=e.onRetryPost,w=e.legacyPost,S=e.onLegacyPost,k=e.reconcilingPost,O=(0,s.k)(),C=eG().token,x=(0,c.useApp)(),I=!(null==(n=m.metadata)?void 0:n.workflowManaged)&&"completed"===m.status&&"mr"===m.targetType&&"pending_approval"===m.postStatus,A=(null==(r=m.metadata)?void 0:r.workflowManaged)&&"running"!==m.status&&"mr"===m.targetType&&["posting","post_unknown","post_failed","retrying"].includes(m.postStatus),T=!(null==(i=m.metadata)?void 0:i.workflowManaged)&&"mr"===m.targetType&&["posting","post_unknown","post_failed"].includes(m.postStatus);return l().createElement("div",null,(null==(u=m.metadata)?void 0:u.workflowManaged)&&"pending_approval"===m.postStatus&&l().createElement(a.Alert,{type:"info",showIcon:!0,message:O("Use the workflow approval task for this review"),action:l().createElement(a.Button,{href:(t="modern"===(0,c.getRouteRuntimeVersion)()?(0,c.getV2EffectiveBasePath)(x):ek(eO(x),(0,c.getModernClientPrefix)()),ek(t,"/admin/workflow/tasks/git-review-approval/pending"))},O("Open workflow tasks")),style:{marginBottom:16}}),(null==(d=m.metadata)?void 0:d.workflowExecutionId)&&l().createElement(a.Button,{href:eC(x,"execution",m.metadata.workflowExecutionId),target:"_blank",rel:"noreferrer",style:{marginBottom:16}},O("Open workflow execution")),A&&l().createElement(a.Space,{wrap:!0,style:{marginBottom:16}},l().createElement(a.Button,{loading:k,onClick:function(){return E(!1)}},O("Check publication")),l().createElement(a.Popconfirm,{title:O("Has the previous outbound post stopped and settled?"),onConfirm:function(){return E(!0)}},l().createElement(a.Button,{loading:k},O("Retry publication")))),T&&l().createElement(a.Space,{wrap:!0,style:{marginBottom:16}},l().createElement(a.Button,{loading:k,onClick:function(){return S("check")}},O("Check publication")),(null==w?void 0:w.canRetry)&&l().createElement(a.Popconfirm,{title:O("Has the previous outbound post stopped and settled?"),description:w.baseUnverified&&!w.baseAcknowledged?O("The original review base cannot be verified. Compare the review with the current merge request before continuing."):void 0,onConfirm:function(){return S("retry")}},l().createElement(a.Button,{loading:k},O("Retry publication"))),(null==w?void 0:w.holdActive)&&l().createElement(a.Popconfirm,{title:O("Has the previous outbound post stopped and settled?"),onConfirm:function(){return S("release")}},l().createElement(a.Button,{loading:k},O("Release legacy publication hold")))),I&&l().createElement(a.Alert,{type:"warning",showIcon:!0,message:O("The original review base cannot be verified. Compare the review with the current merge request before continuing."),style:{marginBottom:16}}),"running"===m.status&&l().createElement(a.Alert,{type:"info",showIcon:!0,message:O("Review in progress…"),description:O("The AI employee is analyzing the code. This page will refresh automatically."),style:{marginBottom:16}}),"failed"===m.status&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:O("Review failed"),description:l().createElement("pre",{style:{whiteSpace:"pre-wrap",margin:0}},m.error),style:{marginBottom:16}}),"completed"===m.status&&"post_failed"===m.postStatus&&m.error&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:O("Post Failed"),description:l().createElement("pre",{style:{whiteSpace:"pre-wrap",margin:0}},m.error),style:{marginBottom:16}}),I&&l().createElement(a.Space,{style:{marginBottom:16},wrap:!0},p?l().createElement(l().Fragment,null,l().createElement(a.Popconfirm,{title:O("The original review base cannot be verified. Compare the review with the current merge request before continuing."),onConfirm:function(){return h(f)}},l().createElement(a.Button,{type:"primary",icon:l().createElement(o.CheckOutlined,null)},O("Save & Post"))),l().createElement(a.Button,{onClick:g},O("Cancel"))):l().createElement(l().Fragment,null,l().createElement(a.Popconfirm,{title:O("The original review base cannot be verified. Compare the review with the current merge request before continuing."),onConfirm:function(){return h(m.reviewMarkdown)}},l().createElement(a.Button,{type:"primary",icon:l().createElement(o.CheckOutlined,null)},O("Approve & Post"))),l().createElement(a.Button,{icon:l().createElement(o.EditOutlined,null),onClick:y},O("Edit & Post")),l().createElement(a.Popconfirm,{title:O("Reject this review?"),onConfirm:b},l().createElement(a.Button,{danger:!0,icon:l().createElement(o.CloseOutlined,null)},O("Reject"))))),l().createElement(a.Tabs,{defaultActiveKey:"content",items:[{key:"content",label:O("Review Content"),children:p?l().createElement(a.Input.TextArea,{value:f,onChange:function(e){return v(e.target.value)},autoSize:{minRows:16,maxRows:40},style:{fontFamily:"'JetBrains Mono', 'Fira Code', Consolas, monospace",fontSize:13}}):m.reviewMarkdown?l().createElement("div",{style:{background:C.colorBgLayout,padding:16,borderRadius:8,maxHeight:"70vh",overflowY:"auto"}},l().createElement(eF,{content:m.reviewMarkdown})):l().createElement(a.Empty,{description:O("No content yet")})},{key:"metadata",label:O("Metadata"),children:l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px 16px",fontSize:13}},l().createElement(eQ,{label:O("Status"),value:m.status}),l().createElement(eQ,{label:O("Post Status"),value:m.postStatus}),l().createElement(eQ,{label:O("Trigger Type"),value:m.targetType}),"folder"===m.targetType&&l().createElement(eQ,{label:O("Folder"),value:m.folderPath||"/"}),l().createElement(eQ,{label:O("Triggered By"),value:m.triggeredBy}),l().createElement(eQ,{label:O("Reviewed SHA"),value:m.headSha||"—"}),l().createElement(eQ,{label:O("Latest SHA"),value:m.latestSha||"—"}),l().createElement(eQ,{label:O("Started At"),value:m.startedAt&&new Date(m.startedAt).toLocaleString()}),l().createElement(eQ,{label:O("Finished At"),value:m.finishedAt&&new Date(m.finishedAt).toLocaleString()}),l().createElement(eQ,{label:O("Duration"),value:m.durationMs?"".concat((m.durationMs/1e3).toFixed(1),"s"):"—"}),l().createElement(eQ,{label:O("Posted Note ID"),value:m.postedNoteId||"—"}),l().createElement(eQ,{label:O("Approved By"),value:m.approvedBy||"—"}),l().createElement(eQ,{label:O("Approved At"),value:m.approvedAt&&new Date(m.approvedAt).toLocaleString()}),l().createElement(eQ,{label:O("Session ID"),value:m.sessionId||"—"}),l().createElement(eQ,{label:O("Flow ID"),value:m.flowId||"—"}))}]}))},eQ=function(e){var t=e.label,n=e.value;return l().createElement("div",null,l().createElement(eW,{type:"secondary",style:{fontSize:12,display:"block"}},t),l().createElement("div",{style:{wordBreak:"break-all"}},n||"—"))};function eX(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function eY(e,t,n,r,l,a,o){try{var i=e[a](o),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,l)}function eZ(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){eY(a,r,l,o,i,"next",e)}function i(e){eY(a,r,l,o,i,"throw",e)}o(void 0)})}}function e0(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return eX(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return eX(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function e1(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:c(0)}),i(o,"throw",{value:c(1)}),i(o,"return",{value:c(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){a.label=u[1];break}if(6===u[0]&&a.label<l[1]){a.label=l[1],l=u;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(u);break}l[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var e2=a.Typography.Text,e3=a.theme.useToken,e4=function(){var e=(0,s.k)();e3().token;var t=(0,c.useApp)().apiClient,n=(0,i.B)(),u=n.repos,d=n.refreshRepos,m=e0((0,r.useState)(null),2),p=m[0],f=m[1],y=e0((0,r.useState)(!1),2),g=y[0],v=y[1],h=e0((0,r.useState)(null),2),b=h[0],E=h[1],w=e0((0,r.useState)([]),2),S=w[0],k=w[1],O=(0,r.useCallback)(function(){return eZ(function(){var e,n,r,l;return e1(this,function(a){switch(a.label){case 0:v(!0),a.label=1;case 1:return a.trys.push([1,,4,5]),[4,Promise.all([t.request({url:"gitManager:pollerStatus"}),t.request({url:"gitReviewFlows:list",params:{pageSize:100,filter:{enabled:!0,triggerMode:{$in:["onMergeRequestCreated","both"]}}}})])];case 2:return r=(n=e0.apply(void 0,[a.sent(),2]))[0].data,l=n[1],f((null==r?void 0:r.data)||null),k((null==l||null==(e=l.data)?void 0:e.data)||[]),[4,d()];case 3:return a.sent(),[3,5];case 4:return v(!1),[7];case 5:return[2]}})})()},[t,d]);(0,r.useEffect)(function(){O()},[O]);var C=u.filter(function(e){return e.autoReview});return l().createElement("div",null,l().createElement(a.Card,{size:"small",style:{marginBottom:16},title:l().createElement(a.Space,null,l().createElement(o.ClockCircleOutlined,null),e("Polling Status")),extra:l().createElement(a.Space,null,l().createElement(a.Button,{size:"small",type:"primary",icon:l().createElement(o.ThunderboltOutlined,null),onClick:function(){return eZ(function(){var n,r,l,o,i,c,u,s,d;return e1(this,function(m){switch(m.label){case 0:E("all"),m.label=1;case 1:return m.trys.push([1,3,4,5]),[4,t.request({url:"gitManager:pollNow",method:"post"})];case 2:return o=(null==(l=m.sent().data)?void 0:l.data)||{},a.message.success(e("Polled {{scanned}} MRs, triggered {{triggered}} reviews",{scanned:null!=(n=o.scanned)?n:0,triggered:null!=(r=o.triggered)?r:0})),O(),[3,5];case 3:return i=m.sent(),a.message.error((null==i||null==(d=i.response)||null==(s=d.data)||null==(u=s.errors)||null==(c=u[0])?void 0:c.message)||(null==i?void 0:i.message)||e("Failed")),[3,5];case 4:return E(null),[7];case 5:return[2]}})})()},loading:"all"===b,disabled:0===C.length},e("Poll Now (All)")),l().createElement(a.Button,{size:"small",icon:l().createElement(o.ReloadOutlined,null),onClick:O,loading:g},e("Refresh")))},l().createElement(a.Space,{direction:"vertical",size:4,style:{width:"100%"}},l().createElement(a.Space,null,l().createElement(e2,{type:"secondary"},e("Background poller"),":"),l().createElement(a.Tag,{color:(null==p?void 0:p.running)?"green":"default"},(null==p?void 0:p.running)?e("Running"):e("Stopped")),(null==p?void 0:p.polling)&&l().createElement(a.Tag,{color:"blue"},e("Polling now…"))),l().createElement(a.Space,null,l().createElement(e2,{type:"secondary"},e("Interval"),":"),l().createElement(e2,null,(null==p?void 0:p.intervalSec)?"".concat(p.intervalSec,"s"):"—")),l().createElement(a.Space,null,l().createElement(e2,{type:"secondary"},e("Last tick"),":"),l().createElement(e2,null,(null==p?void 0:p.lastTickAt)?new Date(p.lastTickAt).toLocaleString():e("Never"))),(null==p?void 0:p.lastError)&&l().createElement(a.Space,null,l().createElement(e2,{type:"secondary"},e("Last error"),":"),l().createElement(e2,{type:"danger",style:{fontSize:12}},p.lastError)))),l().createElement(a.Card,{size:"small",title:l().createElement(a.Space,null,l().createElement(o.RobotOutlined,null),e("Auto-Review Repositories")),extra:l().createElement(e2,{type:"secondary",style:{fontSize:12}},e("Toggle Auto Review on the Repositories tab to enable polling"))},0===C.length?l().createElement(a.Empty,{description:e("No repositories have Auto Review enabled")}):l().createElement(a.Table,{size:"small",rowKey:"id",dataSource:C,pagination:!1,columns:[{title:e("Repository Name"),dataIndex:"name"},{title:e("Primary Auto Flow"),dataIndex:"autoReviewFlowId",width:220,render:function(t,n){var r=S.find(function(e){return Number(e.id)===Number(t)}),o=S.find(function(e){return e.repositoryId===n.id||null==e.repositoryId});return r?l().createElement(a.Tag,{color:"blue"},r.name):o?l().createElement(a.Tag,{color:"default"},e("Fallback"),": ",o.name):l().createElement(a.Tag,{color:"red"},e("No matching flow available"))}},{title:e("Last Polled At"),dataIndex:"lastPolledAt",width:200,render:function(t){return t?new Date(t).toLocaleString():e("Never")}},{title:"",key:"actions",width:120,render:function(n,r){return l().createElement(a.Tooltip,{title:e("Poll this repository now")},l().createElement(a.Button,{size:"small",icon:l().createElement(o.ThunderboltOutlined,null),onClick:function(){var n;return n=r.id,eZ(function(){var r,l,o,i,c,u,s,d,m;return e1(this,function(p){switch(p.label){case 0:E(n),p.label=1;case 1:return p.trys.push([1,3,4,5]),[4,t.request({url:"gitManager:pollNow",method:"post",data:{repositoryId:n}})];case 2:return i=(null==(o=p.sent().data)?void 0:o.data)||{},a.message.success(e("Polled {{scanned}} MRs, triggered {{triggered}} reviews",{scanned:null!=(r=i.scanned)?r:0,triggered:null!=(l=i.triggered)?l:0})),O(),[3,5];case 3:return c=p.sent(),a.message.error((null==c||null==(m=c.response)||null==(d=m.data)||null==(s=d.errors)||null==(u=s[0])?void 0:u.message)||(null==c?void 0:c.message)||e("Failed")),[3,5];case 4:return E(null),[7];case 5:return[2]}})})()},loading:b===r.id},e("Poll Now")))}}]})))},e6=a.Typography.Text,e5=a.theme.useToken,e8=function(){var e=(0,s.k)(),t=e5().token,n=(0,i.B)(),c=n.repos,u=n.selectedRepo,d=n.setSelectedRepo,m=n.refreshRepos;return(0,r.useEffect)(function(){m()},[]),l().createElement("div",{style:{height:"100%"}},l().createElement("div",{style:{padding:"12px 0",marginBottom:16,display:"flex",alignItems:"center",gap:12,borderBottom:"1px solid ".concat(t.colorBorderSecondary)}},l().createElement(o.DatabaseOutlined,{style:{fontSize:16}}),l().createElement(e6,{strong:!0},"Repository:"),l().createElement(a.Select,{style:{minWidth:250},placeholder:e("Select a repository"),value:null==u?void 0:u.id,onChange:function(e){d(c.find(function(t){return t.id===e})||null)},options:c.map(function(t){return{label:l().createElement(a.Space,null,t.name,l().createElement(a.Tag,{color:"connected"===t.status?"green":"default",style:{fontSize:11}},"connected"===t.status?e("Connected"):e("Disconnected"))),value:t.id}}),allowClear:!0,onClear:function(){return d(null)}}),u&&l().createElement(e6,{type:"secondary",style:{fontSize:12}},u.repoUrl)),l().createElement(a.Tabs,{type:"card",defaultActiveKey:"explorer",destroyInactiveTabPane:!0,items:[{key:"explorer",label:l().createElement("span",null,l().createElement(o.FolderOutlined,null)," ",e("File Explorer")),children:l().createElement(T,null)},{key:"history",label:l().createElement("span",null,l().createElement(o.HistoryOutlined,null)," ",e("History")),children:l().createElement(L,null)},{key:"merge-requests",label:l().createElement("span",null,l().createElement(o.MergeOutlined,null)," ",e("Merge Requests")),children:l().createElement(K,null)},{key:"operations",label:l().createElement("span",null,l().createElement(o.ToolOutlined,null)," ",e("Operations")),children:l().createElement(ep,null)},{key:"review-flows",label:l().createElement("span",null,l().createElement(o.RobotOutlined,null)," ",e("Review Flows")),children:l().createElement(ez,null)},{key:"review-history",label:l().createElement("span",null,l().createElement(o.AuditOutlined,null)," ",e("Review History")),children:l().createElement(eJ,null)},{key:"polling",label:l().createElement("span",null,l().createElement(o.ClockCircleOutlined,null)," ",e("Polling")),children:l().createElement(e4,null)}]}))},e7=function(){return l().createElement(i.N,null,l().createElement(e8,null))}},602:function(e,t,n){n.d(t,{B:function(){return m},N:function(){return p}});var r=n(155),l=n.n(r),a=n(866);function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function i(e,t,n,r,l,a,o){try{var i=e[a](o),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,l)}function c(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){i(a,r,l,o,c,"next",e)}function c(e){i(a,r,l,o,c,"throw",e)}o(void 0)})}}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return o(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return o(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:c(0)}),i(o,"throw",{value:c(1)}),i(o,"return",{value:c(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){a.label=u[1];break}if(6===u[0]&&a.label<l[1]){a.label=l[1],l=u;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(u);break}l[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var d=(0,r.createContext)(null);function m(){var e=(0,r.useContext)(d);if(!e)throw Error("useGitManager must be used within GitManagerProvider");return e}var p=function(e){var t=e.children,n=(0,a.useApp)().apiClient,o=u((0,r.useState)([]),2),i=o[0],m=o[1],p=u((0,r.useState)(null),2),f=p[0],y=p[1],g=u((0,r.useState)(!1),2),v=g[0],h=g[1],b=u((0,r.useState)([]),2),E=b[0],w=b[1],S=u((0,r.useState)(""),2),k=S[0],O=S[1],C=(0,r.useRef)(f);C.current=f;var x=(0,r.useCallback)(function(){return c(function(){var e,t,r,l;return s(this,function(a){switch(a.label){case 0:if(!(e=C.current)||"connected"!==e.status)return w([]),O(""),[2];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,n.request({url:"gitManager:branches",params:{repositoryId:e.id}})];case 2:return(l=(null==(r=a.sent().data)||null==(t=r.data)?void 0:t.data)||(null==r?void 0:r.data))&&(w(l.all||[]),O(l.current||"")),[3,4];case 3:return a.sent(),w([]),O(""),[3,4];case 4:return[2]}})})()},[n]),I=(0,r.useCallback)(function(){return c(function(){var e,t,r,l;return s(this,function(a){switch(a.label){case 0:h(!0),a.label=1;case 1:return a.trys.push([1,,3,4]),[4,n.request({url:"gitRepositories:list",params:{pageSize:100}})];case 2:return m(t=(null==(e=a.sent().data)?void 0:e.data)||[]),(r=C.current)&&(l=t.find(function(e){return e.id===r.id}))&&y(l),[3,4];case 3:return h(!1),[7];case 4:return[2]}})})()},[n]);return l().createElement(d.Provider,{value:{repos:i,selectedRepo:f,loading:v,branches:E,currentBranch:k,setSelectedRepo:y,refreshRepos:I,refreshBranches:x}},t)}},578:function(e,t,n){n.d(t,{k:function(){return l}});var r=n(866);function l(){var e=(0,r.useApp)();return function(t,n){return e.i18n.t(t,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({ns:["plugin-git-manager","client"]},n))}}}}]);