Forge
csharp3407750f
1using System.Text.Json;
2using System.Text.Json.Serialization;
3
4namespace AgentForge.Plugin.Ci.Ir;
5
6public sealed class ForgeCiDocument
7{
8 public const string SchemaVersion = "forge.ci/v1";
9
10 [JsonPropertyName("schema")]
11 public string Schema { get; set; } = SchemaVersion;
12
13 [JsonPropertyName("name")]
14 public string Name { get; set; } = "";
15
16 [JsonPropertyName("triggers")]
17 public List<ForgeCiTrigger> Triggers { get; set; } = [];
18
19 [JsonPropertyName("variables")]
20 public Dictionary<string, string> Variables { get; set; } = new(StringComparer.Ordinal);
21
22 [JsonPropertyName("nodes")]
23 public List<ForgeCiNode> Nodes { get; set; } = [];
24
25 [JsonPropertyName("edges")]
26 public List<ForgeCiEdge> Edges { get; set; } = [];
27
28 public static JsonSerializerOptions JsonOptions { get; } = new()
29 {
30 PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
31 WriteIndented = true,
32 DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
33 };
34
35 public string ToJson() => JsonSerializer.Serialize(this, JsonOptions);
36
37 public static ForgeCiDocument FromJson(string json) =>
38 JsonSerializer.Deserialize<ForgeCiDocument>(json, JsonOptions)
39 ?? throw new ForgeCiValidationException("CI document JSON is empty or invalid.");
40}
41
42public sealed class ForgeCiTrigger
43{
44 [JsonPropertyName("event")]
45 public string Event { get; set; } = "";
46
47 [JsonPropertyName("branches")]
48 public List<string>? Branches { get; set; }
49}
50
51public sealed class ForgeCiNode
52{
53 [JsonPropertyName("id")]
54 public string Id { get; set; } = "";
55
56 [JsonPropertyName("kind")]
57 public string Kind { get; set; } = "";
58
59 [JsonPropertyName("name")]
60 public string? Name { get; set; }
61
62 [JsonPropertyName("body")]
63 public string? Body { get; set; }
64
65 [JsonPropertyName("task")]
66 public string? Task { get; set; }
67
68 [JsonPropertyName("inputs")]
69 public Dictionary<string, string>? Inputs { get; set; }
70}
71
72public sealed class ForgeCiEdge
73{
74 [JsonPropertyName("kind")]
75 public string Kind { get; set; } = "";
76
77 [JsonPropertyName("from")]
78 public string From { get; set; } = "";
79
80 [JsonPropertyName("to")]
81 public string To { get; set; } = "";
82}
83
View only · write via MCP/CIDE