| 1 | using AgentForge.Abstractions; |
| 2 | using AgentForge.Data; |
| 3 | using AgentForge.Data.Entities; |
| 4 | using AgentForge.Models; |
| 5 | using AgentForge.Plugin.Sdk; |
| 6 | using AgentForge.Plugin.View; |
| 7 | using Microsoft.Extensions.DependencyInjection; |
| 8 | |
| 9 | namespace AgentForge.Plugin.Issue; |
| 10 | |
| 11 | internal static class ForgeIssueListPage |
| 12 | { |
| 13 | internal static string Render(string repoName, IReadOnlyList<ForgeIssueEntity> issues) |
| 14 | { |
| 15 | if (issues.Count == 0) |
| 16 | return ForgeHtml.Ul("plain", ForgeHtml.Li("meta", ForgeHtml.Text("No issues yet."))); |
| 17 | |
| 18 | var items = new List<string>(issues.Count); |
| 19 | foreach (var issue in issues) |
| 20 | { |
| 21 | var href = $"/view/repos/{ForgeRepoNames.ToUrlPath(repoName)}/issues/{issue.Number}"; |
| 22 | items.Add(ForgeHtml.Li(null, |
| 23 | ForgeHtml.A(href, $"#{issue.Number}"), |
| 24 | ForgeHtml.Text(" "), |
| 25 | ForgeHtml.Text(issue.Title), |
| 26 | ForgeHtml.Text(" "), |
| 27 | ForgeHtml.Badge(issue.Status.ToSlug()))); |
| 28 | } |
| 29 | |
| 30 | return ForgeHtml.Ul("plain", [.. items]); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | internal static class ForgeIssueTabBodyRegistration |
| 35 | { |
| 36 | internal static void Register(ForgeRepoTabBodyRegistry registry) => |
| 37 | registry.Add("issues", ctx => |
| 38 | { |
| 39 | var repository = ctx.Services.GetRequiredService<ForgeRepository>(); |
| 40 | var issues = repository.ListIssues(ctx.RepoId); |
| 41 | return ForgeIssueListPage.Render(ctx.RepoName, issues); |
| 42 | }); |
| 43 | } |
| 44 | |