|
| 1 | +using ModularityKit.Mutator.Abstractions.Changes; |
| 2 | +using ModularityKit.Mutator.Abstractions.Context; |
| 3 | +using ModularityKit.Mutator.Abstractions.Engine; |
| 4 | +using ModularityKit.Mutator.Abstractions.Results; |
| 5 | +using PolicyComposition.State; |
| 6 | + |
| 7 | +namespace PolicyComposition.Mutations; |
| 8 | + |
| 9 | +/// <summary> |
| 10 | +/// Submits a release and carries the governance metadata consumed by the policies. |
| 11 | +/// </summary> |
| 12 | +/// <remarks> |
| 13 | +/// The mutation itself only moves the release into the submitted stage. The |
| 14 | +/// interesting governance behavior lives in the composed policies, which read the |
| 15 | +/// approval count, emergency flag, and target environment from the mutation |
| 16 | +/// context metadata. |
| 17 | +/// </remarks> |
| 18 | +internal sealed class SubmitReleaseMutation( |
| 19 | + string releaseName, |
| 20 | + int approvals, |
| 21 | + bool emergency, |
| 22 | + string environment) : MutationBase<ReleaseGateState>( |
| 23 | + CreateIntent( |
| 24 | + operationName: "SubmitRelease", |
| 25 | + category: "ReleaseGovernance", |
| 26 | + description: "Submit a release through composed governance policies"), |
| 27 | + MutationContext.User("release-manager", "Release Manager", "Release composition example") |
| 28 | + with |
| 29 | + { |
| 30 | + StateId = releaseName, |
| 31 | + Metadata = new Dictionary<string, object> |
| 32 | + { |
| 33 | + ["approvals"] = approvals, |
| 34 | + ["emergency"] = emergency, |
| 35 | + ["environment"] = environment |
| 36 | + } |
| 37 | + }) |
| 38 | +{ |
| 39 | + /// <summary> |
| 40 | + /// Marks the release as submitted before policy composition evaluates it. |
| 41 | + /// </summary> |
| 42 | + /// <param name="state">The current release state.</param> |
| 43 | + /// <returns>A mutation result that moves the release into the submitted stage.</returns> |
| 44 | + public override MutationResult<ReleaseGateState> Apply(ReleaseGateState state) |
| 45 | + => Success( |
| 46 | + state with { Stage = "Submitted" }, |
| 47 | + StateChange.Modified("Stage", state.Stage, "Submitted")); |
| 48 | +} |
0 commit comments