-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing variable provider concept, decoupling version generation …
…from output a bit
- Loading branch information
Jake Ginnivan
committed
Jan 30, 2014
1 parent
c30a2be
commit f2daf60
Showing
16 changed files
with
125 additions
and
110 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
namespace GitFlowVersion | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public class GitFlowVariableProvider | ||
{ | ||
public static string SemVer = "SemVer"; | ||
public static string LongVersion = "LongVersion"; | ||
public static string NugetVersion = "NugetVersion"; | ||
public static string Major = "Major"; | ||
public static string Minor = "Minor"; | ||
public static string Patch = "Patch"; | ||
|
||
public Dictionary<string, string> GetVariables(VersionAndBranch versionAndBranch) | ||
{ | ||
var variables = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) | ||
{ | ||
{Major, versionAndBranch.Version.Major.ToString()}, | ||
{Minor, versionAndBranch.Version.Minor.ToString()}, | ||
{Patch, versionAndBranch.Version.Patch.ToString()}, | ||
{"Suffix", versionAndBranch.Version.Suffix.JsonEncode()}, | ||
{LongVersion, versionAndBranch.ToLongString().JsonEncode()}, | ||
{NugetVersion, versionAndBranch.GenerateNugetVersion().JsonEncode()}, | ||
{"ShortVersion", versionAndBranch.ToShortString().JsonEncode()}, | ||
{"BranchName", versionAndBranch.BranchName.JsonEncode()}, | ||
{"BranchType", versionAndBranch.BranchType == null ? null : versionAndBranch.BranchType.ToString()}, | ||
{"Sha", versionAndBranch.Sha}, | ||
{SemVer, versionAndBranch.GenerateSemVer()} | ||
}; | ||
|
||
var releaseInformation = ReleaseInformationCalculator.Calculate(versionAndBranch.BranchType, versionAndBranch.Version.Tag); | ||
if (releaseInformation.ReleaseNumber.HasValue) | ||
{ | ||
variables.Add("PreReleasePartOne", releaseInformation.ReleaseNumber.ToString()); | ||
} | ||
if (versionAndBranch.Version.PreReleasePartTwo != null) | ||
{ | ||
variables.Add("PreReleasePartTwo", versionAndBranch.Version.PreReleasePartTwo.ToString()); | ||
} | ||
if (releaseInformation.Stability.HasValue) | ||
{ | ||
variables.Add("Stability", releaseInformation.Stability.ToString()); | ||
} | ||
return variables; | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace GitFlowVersion | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
public static class BuildOutputFormatter | ||
{ | ||
public static IEnumerable<string> GenerateBuildLogOutput(Dictionary<string, string> variables, IBuildServer buildServer) | ||
{ | ||
return variables.Select(variable => buildServer.GenerateSetParameterMessage(variable.Key, variable.Value)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace GitFlowVersion | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
public static class JsonOutputFormatter | ||
{ | ||
public static string ToJson(Dictionary<string, string> variables) | ||
{ | ||
var builder = new StringBuilder(); | ||
builder.AppendLine("{"); | ||
var last = variables.Last().Key; | ||
foreach (var variable in variables) | ||
{ | ||
var isLast = (variable.Key == last); | ||
int value; | ||
if (int.TryParse(variable.Value, out value)) | ||
builder.AppendLineFormat(" \"{0}\":{1}{2}", variable.Key, value, isLast ? string.Empty : ","); | ||
else | ||
builder.AppendLineFormat(" \"{0}\":\"{1}\"{2}", variable.Key, variable.Value, isLast ? string.Empty : ","); | ||
} | ||
|
||
builder.Append("}"); | ||
return builder.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace GitFlowVersion.VersionBuilders | ||
namespace GitFlowVersion | ||
{ | ||
using System; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters