| 1 | using System.Text; |
| 2 | using AgentForge.Abstractions; |
| 3 | |
| 4 | namespace AgentForge.Plugin.View; |
| 5 | |
| 6 | internal static class ForgeViewLinks |
| 7 | { |
| 8 | internal static string BlobHref( |
| 9 | string repo, |
| 10 | string branch, |
| 11 | string file, |
| 12 | int lineStart = 0, |
| 13 | int? lineEnd = null) |
| 14 | { |
| 15 | var href = new StringBuilder("/view/repos/"); |
| 16 | href.Append(ForgeRepoNames.ToUrlPath(repo)); |
| 17 | href.Append("/blob?branch=").Append(Uri.EscapeDataString(branch)); |
| 18 | href.Append("&path=").Append(Uri.EscapeDataString(file.Trim())); |
| 19 | if (lineStart > 0) |
| 20 | href.Append("&line=").Append(lineStart); |
| 21 | if (lineEnd is > 0 && lineEnd != lineStart) |
| 22 | href.Append("&line_end=").Append(lineEnd.Value); |
| 23 | return href.ToString(); |
| 24 | } |
| 25 | |
| 26 | internal static string RepoViewHref(string repoName, string activeTab = "code") |
| 27 | { |
| 28 | var href = new StringBuilder("/view/repos/"); |
| 29 | href.Append(ForgeRepoNames.ToUrlPath(repoName)); |
| 30 | if (!string.Equals(activeTab, "code", StringComparison.OrdinalIgnoreCase)) |
| 31 | href.Append("?tab=").Append(Uri.EscapeDataString(activeTab)); |
| 32 | return href.ToString(); |
| 33 | } |
| 34 | |
| 35 | internal static string DocsHref(string repo, string? path = null) |
| 36 | { |
| 37 | var href = new StringBuilder("/view/repos/"); |
| 38 | href.Append(ForgeRepoNames.ToUrlPath(repo)); |
| 39 | href.Append("/docs"); |
| 40 | var relative = ForgeGitViewHelpers.ToDocsRelativePath(path); |
| 41 | if (relative.Length > 0) |
| 42 | { |
| 43 | href.Append('/').Append(string.Join('/', relative.Split('/', StringSplitOptions.RemoveEmptyEntries) |
| 44 | .Select(Uri.EscapeDataString))); |
| 45 | } |
| 46 | |
| 47 | return href.ToString(); |
| 48 | } |
| 49 | } |
| 50 | |