1
+ using System ;
2
+ using System . Threading . Tasks ;
3
+ using Nuke . Common ;
4
+ using Nuke . Common . Git ;
5
+ using static Nuke . Common . Tools . Git . GitTasks ;
6
+ using static Serilog . Log ;
7
+
8
+ namespace Candoumbe . Pipelines . Components . Workflows ;
9
+
10
+ /// <summary>
11
+ /// Represents an interface for chore branch workflows in a Git repository.
12
+ /// </summary>
13
+ /// <remarks>
14
+ /// This interface extends the <see cref="IWorkflow"/> interface and adds properties and methods specific to feature branch workflows.
15
+ /// </remarks>
16
+ public interface IDoChoreWorkflow : IDoFeatureWorkflow
17
+ {
18
+ /// <summary>
19
+ /// Gets the prefix used to name feature branches.
20
+ /// </summary>
21
+ [ Parameter ( "The name of the chore branch prefix" ) ]
22
+ public string ChoreBranchPrefix => TryGetValue ( ( ) => ChoreBranchPrefix ) ?? "chore" ;
23
+
24
+ /// <summary>
25
+ /// Gets the name of the branch to use when starting a new feature.
26
+ /// </summary>
27
+ /// <remarks>
28
+ /// This property should never return <see langword="null"/>.
29
+ /// </remarks>
30
+ [ Parameter ( "The name of the chore branch source" ) ]
31
+ string ChoreBranchSourceName => TryGetValue ( ( ) => ChoreBranchPrefix ) ?? FeatureBranchSourceName ;
32
+
33
+ /// <summary>
34
+ /// Merges a chore branch back to <see cref="ChoreBranchSourceName"/>.
35
+ /// </summary>
36
+ /// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
37
+ ValueTask FinishChore ( ) => ValueTask . CompletedTask ;
38
+
39
+ /// <summary>
40
+ /// Starts a new chore development by creating the associated branch {FeatureBranchPrefix}/{{feature-name}} from {FeatureBranchSourceName}.
41
+ /// </summary>
42
+ /// <remarks>
43
+ /// This target will instead end a feature if the current branch is a feature/* branch with no pending changes.
44
+ /// </remarks>
45
+ /// <returns>A <see cref="Target"/> representing the feature development.</returns>
46
+ public Target Chore => _ => _
47
+ . Description ( $ "Starts a new chore development by creating the associated branch { ChoreBranchPrefix } /{{chore-name}} from { ChoreBranchSourceName } ")
48
+ . Requires ( ( ) => IsLocalBuild )
49
+ . Requires ( ( ) => ! GitRepository . IsOnFeatureBranch ( ) || GitHasCleanWorkingCopy ( ) )
50
+ . Executes ( async ( ) =>
51
+ {
52
+ if ( ! GitRepository . Branch . Like ( $ "{ ChoreBranchPrefix } /*", true ) || ! GitHasCleanWorkingCopy ( ) )
53
+ {
54
+ Information ( "Enter the name of the chore. It will be used as the name of the chore/branch (leave empty to exit) :" ) ;
55
+ AskBranchNameAndSwitchToIt ( ChoreBranchPrefix , sourceBranch : ChoreBranchSourceName ) ;
56
+ Information ( "Good bye !" ) ;
57
+ }
58
+ else
59
+ {
60
+ await FinishChore ( ) ;
61
+ }
62
+ } ) ;
63
+ }
0 commit comments