| 1 | using System.Text; |
| 2 | using AgentForge.Contracts; |
| 3 | using AgentForge.Data; |
| 4 | using AgentForge.Data.Entities; |
| 5 | using AgentForge.Plugin.View.Components.Iop; |
| 6 | |
| 7 | namespace AgentForge.Plugin.View; |
| 8 | |
| 9 | public static class ForgeIopViewRenderer |
| 10 | { |
| 11 | public static void AppendMrPanel( |
| 12 | StringBuilder body, |
| 13 | string repoName, |
| 14 | ForgeMergeRequestEntity mergeRequest, |
| 15 | ForgeRepoEntity repo, |
| 16 | IReadOnlyList<(string Author, string Text, DateTimeOffset CreatedAt)> comments, |
| 17 | ForgeCiRunEntity? ciRun, |
| 18 | bool showActions, |
| 19 | string iopTab, |
| 20 | ForgeIopTabLinks tabLinks, |
| 21 | MergeRequestDiffResponse? diff, |
| 22 | string? sourceBranchForFiles = null, |
| 23 | IReadOnlyList<string>? handoffTargets = null) => |
| 24 | body.Append(ForgeViewIopMrPanel.Render( |
| 25 | repoName, |
| 26 | mergeRequest, |
| 27 | repo, |
| 28 | comments, |
| 29 | ciRun, |
| 30 | showActions, |
| 31 | iopTab, |
| 32 | tabLinks, |
| 33 | diff, |
| 34 | sourceBranchForFiles, |
| 35 | handoffTargets)); |
| 36 | |
| 37 | public static void AppendIssuePanel( |
| 38 | StringBuilder body, |
| 39 | string repoName, |
| 40 | ForgeIssueEntity issue, |
| 41 | IReadOnlyList<(string Author, string Text, DateTimeOffset CreatedAt)> comments) => |
| 42 | body.Append(ForgeViewIopIssuePanel.Render(repoName, issue, comments)); |
| 43 | |
| 44 | internal static void AppendBranchContextPanel( |
| 45 | StringBuilder body, |
| 46 | string repoName, |
| 47 | string branch, |
| 48 | ForgeMergeRequestEntity? mergeRequest, |
| 49 | ForgeRepoEntity repo, |
| 50 | ForgeRepository repository, |
| 51 | string iopTab, |
| 52 | ForgeIopTabLinks tabLinks, |
| 53 | MergeRequestDiffResponse? diff) => |
| 54 | body.Append(ForgeViewIopBranchPanel.Render( |
| 55 | repoName, |
| 56 | branch, |
| 57 | mergeRequest, |
| 58 | repo, |
| 59 | repository, |
| 60 | iopTab, |
| 61 | tabLinks, |
| 62 | diff)); |
| 63 | |
| 64 | public static string NormalizeIopTab(string? tab) => ForgeIopTabs.Normalize(tab); |
| 65 | |
| 66 | public static ForgeIopTabLinks MrPageTabLinks(string repoName, int number) => |
| 67 | new( |
| 68 | $"/view/repos/{ForgeRepoNames.ToUrlPath(repoName)}/merge-requests/{number}?iop=conversation", |
| 69 | $"/view/repos/{ForgeRepoNames.ToUrlPath(repoName)}/merge-requests/{number}?iop=changes", |
| 70 | $"/view/repos/{ForgeRepoNames.ToUrlPath(repoName)}/merge-requests/{number}?iop=checks"); |
| 71 | |
| 72 | internal static ForgeIopTabLinks BlobTabLinks(string repoName, string branch, string path) => |
| 73 | new( |
| 74 | BlobQuery(repoName, branch, path, "conversation"), |
| 75 | BlobQuery(repoName, branch, path, "changes"), |
| 76 | BlobQuery(repoName, branch, path, "checks")); |
| 77 | |
| 78 | private static string BlobQuery(string repoName, string branch, string path, string iopTab) |
| 79 | { |
| 80 | var href = new StringBuilder("/view/repos/"); |
| 81 | href.Append(ForgeRepoNames.ToUrlPath(repoName)); |
| 82 | href.Append("/blob?branch=").Append(Uri.EscapeDataString(branch)); |
| 83 | href.Append("&path=").Append(Uri.EscapeDataString(path)); |
| 84 | href.Append("&iop=").Append(Uri.EscapeDataString(iopTab)); |
| 85 | return href.ToString(); |
| 86 | } |
| 87 | } |
| 88 | |