-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3451 from arturcic/feature/abstractions
Added GitVersion.Abstractions module
- Loading branch information
Showing
142 changed files
with
1,052 additions
and
1,050 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
src/GitVersion.Abstractions/GitVersion.Abstractions.csproj
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,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<PackageId>GitVersion.Abstractions</PackageId> | ||
<Title>GitVersion</Title> | ||
<Description>Derives SemVer information from a repository following GitFlow or GitHubFlow. This is the Core library which both GitVersion cli and Task use allowing programatic usage of GitVersion.</Description> | ||
|
||
<Product>$(AssemblyName)</Product> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" /> | ||
<PackageReference Include="Microsoft.Extensions.Options" /> | ||
<PackageReference Include="Polly" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<InternalsVisibleTo Include="GitVersion.Core" /> | ||
<InternalsVisibleTo Include="GitVersion.Output" /> | ||
<InternalsVisibleTo Include="GitVersion.Schema" /> | ||
<InternalsVisibleTo Include="GitVersion.Core.Tests" /> | ||
<InternalsVisibleTo Include="GitVersion.App.Tests" /> | ||
<InternalsVisibleTo Include="GitVersion.MsBuild.Tests" /> | ||
</ItemGroup> | ||
|
||
</Project> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#nullable enable |
Oops, something went wrong.