-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
decoupled modules from core and use abstractions instead
- Loading branch information
Showing
24 changed files
with
101 additions
and
94 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
using GitVersion.Extensions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace GitVersion; | ||
|
||
public interface IGitVersionModule | ||
{ | ||
void RegisterTypes(IServiceCollection services); | ||
|
||
static IEnumerable<Type> FindAllDerivedTypes<T>(Assembly? assembly) | ||
{ | ||
assembly.NotNull(); | ||
|
||
var derivedType = typeof(T); | ||
return assembly.GetTypes().Where(t => t != derivedType && derivedType.IsAssignableFrom(t)); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions
52
src/GitVersion.Abstractions/Extensions/GitVersionVariablesExtensions.cs
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,52 @@ | ||
using System.Text.Encodings.Web; | ||
using GitVersion.OutputVariables; | ||
|
||
namespace GitVersion.Extensions; | ||
|
||
public static class GitVersionVariablesExtensions | ||
{ | ||
public static string ToJsonString(this GitVersionVariables gitVersionVariables) | ||
{ | ||
var variablesType = typeof(VersionVariablesJsonModel); | ||
var variables = new VersionVariablesJsonModel(); | ||
|
||
foreach (var (key, value) in gitVersionVariables.OrderBy(x => x.Key)) | ||
{ | ||
var propertyInfo = variablesType.GetProperty(key); | ||
propertyInfo?.SetValue(variables, ChangeType(value, propertyInfo.PropertyType)); | ||
} | ||
|
||
var serializeOptions = GetJsonSerializerOptions(); | ||
|
||
return JsonSerializer.Serialize(variables, serializeOptions); | ||
} | ||
|
||
public static JsonSerializerOptions GetJsonSerializerOptions() | ||
{ | ||
var serializeOptions = new JsonSerializerOptions | ||
{ | ||
WriteIndented = true, | ||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, | ||
Converters = | ||
{ | ||
new VersionVariablesJsonStringConverter() | ||
} | ||
}; | ||
return serializeOptions; | ||
} | ||
|
||
private static object? ChangeType(object? value, Type type) | ||
{ | ||
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) | ||
{ | ||
if (value == null || value.ToString()?.Length == 0) | ||
{ | ||
return null; | ||
} | ||
|
||
type = Nullable.GetUnderlyingType(type)!; | ||
} | ||
|
||
return Convert.ChangeType(value, type); | ||
} | ||
} |
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
File renamed without changes.
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
2 changes: 1 addition & 1 deletion
2
src/GitVersion.Core.Tests/VersionCalculation/JsonVersionBuilderTests.cs
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
2 changes: 1 addition & 1 deletion
2
src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs
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 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
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