Skip to content

Commit 4c0952c

Browse files
committed
Starting a gitversion init config helper/wizard
1 parent b2f3468 commit 4c0952c

16 files changed

+367
-47
lines changed

GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,6 @@ public void CanReadDefaultDocument()
124124
config.NextVersion.ShouldBe(null);
125125
}
126126

127-
[Test]
128-
public void VerifyInit()
129-
{
130-
var config = typeof(Config);
131-
var aliases = config.GetProperties()
132-
.Where(p => p.GetCustomAttribute<ObsoleteAttribute>() == null)
133-
.Select(p => ((YamlMemberAttribute) p.GetCustomAttribute(typeof(YamlMemberAttribute))).Alias);
134-
var writer = new StringWriter();
135-
136-
ConfigSerialiser.WriteSample(writer);
137-
var initFile = writer.GetStringBuilder().ToString();
138-
139-
foreach (var alias in aliases)
140-
{
141-
initFile.ShouldContain(alias);
142-
}
143-
}
144-
145127
[Test]
146128
public void VerifyAliases()
147129
{

GitVersionCore/Configuration/ConfigSerialiser.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,5 @@ public static void Write(Config config, TextWriter writer)
2222
var serializer = new Serializer(SerializationOptions.None, new HyphenatedNamingConvention());
2323
serializer.Serialize(writer, config);
2424
}
25-
26-
public static void WriteSample(TextWriter writer)
27-
{
28-
writer.WriteLine("# assembly-versioning-scheme: MajorMinorPatchTag | MajorMinorPatch | MajorMinor | Major");
29-
writer.WriteLine("# tag-prefix: '[vV|version-] # regex to match git tag prefix");
30-
writer.WriteLine("# next-version: 1.0.0");
31-
writer.WriteLine("# mode: ContinuousDelivery | ContinuousDeployment");
32-
writer.WriteLine("# continuous-delivery-fallback-tag: ci");
33-
writer.WriteLine("#branches:");
34-
writer.WriteLine("# release[/-]:\n mode: ContinuousDelivery | ContinuousDeployment\n tag: rc");
35-
writer.WriteLine("# develop:\n# mode: ContinuousDelivery | ContinuousDeployment\n# tag: alpha");
36-
}
3725
}
3826
}

GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,22 @@ public static string GetEffectiveConfigAsString(string gitDirectory, IFileSystem
3333
return stringBuilder.ToString();
3434
}
3535

36-
public static void WriteSample(string workingDirectory, IFileSystem fileSystem)
36+
static string GetConfigFilePath(string workingDirectory)
37+
{
38+
return Path.Combine(workingDirectory, "GitVersionConfig.yaml");
39+
}
40+
41+
public static void Init(string workingDirectory, IFileSystem fileSystem)
3742
{
3843
var configFilePath = GetConfigFilePath(workingDirectory);
44+
var config = new ConfigInitWizard().Run(Provide(workingDirectory, fileSystem));
45+
if (config == null) return;
3946

40-
if (!fileSystem.Exists(configFilePath))
41-
{
42-
using (var stream = fileSystem.OpenWrite(configFilePath))
43-
using (var writer = new StreamWriter(stream))
44-
{
45-
ConfigSerialiser.WriteSample(writer);
46-
}
47-
}
48-
else
47+
using (var stream = fileSystem.OpenWrite(configFilePath))
48+
using (var writer = new StreamWriter(stream))
4949
{
50-
Logger.WriteError("Cannot write sample, GitVersionConfig.yaml already exists");
50+
ConfigSerialiser.Write(config, writer);
5151
}
5252
}
53-
54-
static string GetConfigFilePath(string workingDirectory)
55-
{
56-
return Path.Combine(workingDirectory, "GitVersionConfig.yaml");
57-
}
5853
}
5954
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
6+
public class ConfigInitWizard
7+
{
8+
public Config Run(Config config)
9+
{
10+
Console.WriteLine("GitVersion init will guide you through setting GitVersion up to work for you");
11+
var steps = new Queue<ConfigInitWizardStep>();
12+
steps.Enqueue(new SimpleOrTutorialStep());
13+
14+
while (steps.Count > 0)
15+
{
16+
var currentStep = steps.Dequeue();
17+
if (!currentStep.Apply(steps, config))
18+
{
19+
return null;
20+
}
21+
}
22+
23+
return config;
24+
}
25+
}
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
6+
public abstract class ConfigInitWizardStep
7+
{
8+
public bool Apply(Queue<ConfigInitWizardStep> steps, Config config)
9+
{
10+
Console.WriteLine(Prompt);
11+
var input = Console.ReadLine();
12+
if (input == null)
13+
{
14+
return false;
15+
}
16+
var resultWithDefaultApplied = string.IsNullOrEmpty(input) ? DefaultResult : input;
17+
var stepResult = HandleResult(resultWithDefaultApplied, steps, config);
18+
if (stepResult.InvalidResponse)
19+
{
20+
Console.WriteLine();
21+
Console.ForegroundColor = ConsoleColor.Red;
22+
Console.WriteLine("Invalid response!");
23+
Console.ResetColor();
24+
steps.Enqueue(this);
25+
}
26+
return true;
27+
}
28+
29+
protected abstract StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config);
30+
protected abstract string Prompt { get; }
31+
protected abstract string DefaultResult { get; }
32+
}
33+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
6+
public class ExpressSetupStep : ConfigInitWizardStep
7+
{
8+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
9+
{
10+
Console.WriteLine("Not done yet...");
11+
return StepResult.Ok();
12+
}
13+
14+
protected override string Prompt
15+
{
16+
get { return "Not done yet"; }
17+
}
18+
19+
protected override string DefaultResult
20+
{
21+
get { return null; }
22+
}
23+
}
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace GitVersion
2+
{
3+
using System.Collections.Generic;
4+
5+
public class GitFlowSetupStep : ConfigInitWizardStep
6+
{
7+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
8+
{
9+
throw new System.NotImplementedException();
10+
}
11+
12+
protected override string Prompt
13+
{
14+
get { throw new System.NotImplementedException(); }
15+
}
16+
17+
protected override string DefaultResult
18+
{
19+
get { throw new System.NotImplementedException(); }
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace GitVersion
2+
{
3+
using System.Collections.Generic;
4+
5+
public class GitHubFlowStep : ConfigInitWizardStep
6+
{
7+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
8+
{
9+
throw new System.NotImplementedException();
10+
}
11+
12+
protected override string Prompt
13+
{
14+
get { throw new System.NotImplementedException(); }
15+
}
16+
17+
protected override string DefaultResult
18+
{
19+
get { throw new System.NotImplementedException(); }
20+
}
21+
}
22+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
6+
public class PickBranchingStrategy1Step : ConfigInitWizardStep
7+
{
8+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
9+
{
10+
switch (result.ToLower())
11+
{
12+
case "y":
13+
Console.Write(@"Because you need to maintain multiple versions of your product in production at the same time, GitFlow is likely a good fit.
14+
15+
GitFlow allows you to have new development happening on the 'develop' branch, patch issues in old minor versions with 'hotfix/' branches and support old major versions with 'support/' branches");
16+
steps.Enqueue(new PickBranchingStrategyStep());
17+
return StepResult.Ok();
18+
case "n":
19+
steps.Enqueue(new PickBranchingStrategy2Step());
20+
return StepResult.Ok();
21+
}
22+
23+
return StepResult.InvalidResponseSelected();
24+
}
25+
26+
protected override string Prompt
27+
{
28+
get { return @"GitVersion can try to recommend you a branching strategy based on a few questions.
29+
30+
Do you need to maintain mutliple versions of your application simultanously in production? (y/n)"; }
31+
}
32+
33+
protected override string DefaultResult
34+
{
35+
get { return null; }
36+
}
37+
}
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
6+
public class PickBranchingStrategy2Step : ConfigInitWizardStep
7+
{
8+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config)
9+
{
10+
switch (result.ToLower())
11+
{
12+
case "y":
13+
Console.WriteLine("GitFlow is likely a good fit, the 'develop' branch can be used " +
14+
"for active development while stabilising the next release.");
15+
Console.WriteLine();
16+
Console.WriteLine("GitHubFlow is designed for a lightwieght workflow where master is always " +
17+
"good to deploy to production and feature branches are used to stabilise " +
18+
"features, once stable they can be released in the next release");
19+
steps.Enqueue(new PickBranchingStrategyStep());
20+
return StepResult.Ok();
21+
case "n":
22+
steps.Enqueue(new PickBranchingStrategy3Step());
23+
return StepResult.Ok();
24+
}
25+
26+
return StepResult.InvalidResponseSelected();
27+
}
28+
29+
protected override string Prompt
30+
{
31+
get { return "Do you stabilise releases while continuing work on the next version? (y/n)"; }
32+
}
33+
34+
protected override string DefaultResult
35+
{
36+
get { return null; }
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)