feat: implements first version
This commit is contained in:
16
src/Infrastructure/DependencyInjection.cs
Normal file
16
src/Infrastructure/DependencyInjection.cs
Normal 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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/Infrastructure/Infrastructure.csproj
Normal file
17
src/Infrastructure/Infrastructure.csproj
Normal 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>
|
||||
37
src/Infrastructure/Services/GitRepoReadService.cs
Normal file
37
src/Infrastructure/Services/GitRepoReadService.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/Infrastructure/Services/GitRepoWriteService.cs
Normal file
20
src/Infrastructure/Services/GitRepoWriteService.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user