| 1 | using AgentForge.Contracts; |
| 2 | using AgentForge.Data.Entities; |
| 3 | using AgentForge.Models; |
| 4 | using AgentForge.Plugin.View; |
| 5 | |
| 6 | namespace AgentForge.Plugin.View.Components; |
| 7 | |
| 8 | public static class ForgeViewRepoMeta |
| 9 | { |
| 10 | public static string Render(ForgeRepoEntity repo, RepoResponse response) |
| 11 | { |
| 12 | var humanDescription = ForgeViewRepoImportSource.HumanDescription(repo.Description); |
| 13 | var linkParts = new List<string>(); |
| 14 | |
| 15 | if (ForgeViewRepoImportSource.TryParseGitHub(repo.Description, out var github)) |
| 16 | Append(linkParts, ForgeHtml.AExternal(github.Url, "GitHub")); |
| 17 | |
| 18 | Append(linkParts, ForgeHtml.A(ForgeViewLinks.DocsHref(repo.Name), "Docs")); |
| 19 | |
| 20 | if (response.Group is { Length: > 0 } group && response.Org is { Length: > 0 } org) |
| 21 | { |
| 22 | var groupHref = |
| 23 | $"{ForgeViewRepoHeader.OrgCatalogHref(org)}?group={Uri.EscapeDataString(ForgeRepoGroupPath.ToUrlPath(group))}"; |
| 24 | Append(linkParts, ForgeHtml.A(groupHref, group)); |
| 25 | } |
| 26 | |
| 27 | var badges = ForgeHtml.Fragment( |
| 28 | ForgeHtml.Badge(response.Visibility), |
| 29 | ForgeHtml.Text(" "), |
| 30 | ForgeHtml.Badge(repo.DriveMode.ToSlug())); |
| 31 | |
| 32 | var blocks = new List<string>(); |
| 33 | if (humanDescription is not null) |
| 34 | blocks.Add(ForgeHtml.P("repo-desc", ForgeHtml.Text(humanDescription))); |
| 35 | |
| 36 | if (linkParts.Count > 0) |
| 37 | blocks.Add(ForgeHtml.P("repo-links meta", [.. linkParts])); |
| 38 | |
| 39 | if (!string.IsNullOrWhiteSpace(response.CloneUrl)) |
| 40 | { |
| 41 | blocks.Add(ForgeHtml.P( |
| 42 | "repo-clone meta", |
| 43 | ForgeHtml.Code(response.CloneUrl, "clone-url", null))); |
| 44 | } |
| 45 | |
| 46 | blocks.Add(ForgeHtml.P("repo-badges meta", badges)); |
| 47 | return ForgeHtml.Fragment([.. blocks]); |
| 48 | } |
| 49 | |
| 50 | private static void Append(List<string> parts, string segment) |
| 51 | { |
| 52 | if (parts.Count > 0) |
| 53 | parts.Add(ForgeHtml.Sep()); |
| 54 | |
| 55 | parts.Add(segment); |
| 56 | } |
| 57 | } |
| 58 | |