feat: implements first version

This commit is contained in:
Matthias Langhard
2021-10-31 07:44:49 +01:00
parent 915e23cf24
commit 69f872082d
25 changed files with 979 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
using Application.Interfaces;
using Infrastructure.Services;
using Microsoft.Extensions.DependencyInjection;
namespace Infrastructure
{
public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services)
{
return services
.AddSingleton<IGitRepoReadService, GitRepoReadService>()
.AddSingleton<IGitRepoWriteService, GitRepoWriteService>();
}
}
}

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="semver" Version="2.0.6" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,37 @@
using System.Collections.Generic;
using Application.Interfaces;
using LibGit2Sharp;
using Semver;
using Version = Application.Models.Version;
namespace Infrastructure.Services
{
public class GitRepoReadService : IGitRepoReadService
{
public IEnumerable<Version> GetAllVersions(string repoPath)
{
using var repo = new Repository(repoPath);
foreach (var tag in repo.Tags)
{
if (TryParse(tag.FriendlyName, out var semver))
{
yield return new Version(semver.Major, semver.Minor, semver.Patch, semver.Prerelease, semver.Build);
}
}
}
private static bool TryParse(string version, out SemVersion semverVersion)
{
try
{
semverVersion = SemVersion.Parse(version.TrimStart('v').TrimStart('V'));
return true;
}
catch
{
semverVersion = null;
return false;
}
}
}
}

View File

@@ -0,0 +1,20 @@
using Application.Interfaces;
using LibGit2Sharp;
namespace Infrastructure.Services
{
public class GitRepoWriteService : IGitRepoWriteService
{
public void AddTag(string repoPath, string tag)
{
using var repo = new Repository(repoPath);
repo.ApplyTag(tag);
}
public void Push(string repoPath)
{
using var repo = new Repository(repoPath);
repo.Network.Push(repo.Head);
}
}
}