Forge
csharp3407750f
1namespace AgentForge.Plugin.View.Components;
2
3internal static class ForgeViewRepoImportSource
4{
5 private const string GitHubPrefix = "Imported from GitHub ";
6
7 internal readonly record struct GitHubSource(string Org, string Repo, string Url);
8
9 internal static bool TryParseGitHub(string? description, out GitHubSource source)
10 {
11 source = default;
12 if (string.IsNullOrWhiteSpace(description)
13 || !description.StartsWith(GitHubPrefix, StringComparison.OrdinalIgnoreCase))
14 {
15 return false;
16 }
17
18 var rest = description[GitHubPrefix.Length..].Trim();
19 var slash = rest.IndexOf('/');
20 if (slash <= 0 || slash >= rest.Length - 1)
21 return false;
22
23 var org = rest[..slash].Trim();
24 var repo = rest[(slash + 1)..].Trim();
25 if (org.Length == 0 || repo.Length == 0)
26 return false;
27
28 source = new GitHubSource(org, repo, $"https://github.com/{org}/{repo}");
29 return true;
30 }
31
32 internal static string? HumanDescription(string? description)
33 {
34 if (string.IsNullOrWhiteSpace(description) || TryParseGitHub(description, out _))
35 return null;
36
37 return description.Trim();
38 }
39}
40
View only · write via MCP/CIDE