Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d404034f9 |
@@ -26,8 +26,7 @@ namespace Cli
|
||||
var chosenService = await ChooseService(repoBasePath);
|
||||
var selection = await SelectVersion(repoBasePath, chosenService);
|
||||
await AddVersionTagToRepo(repoBasePath, selection.Version.ToString());
|
||||
await PushTagsToRemote(repoBasePath);
|
||||
await PushCommitsToRemote(repoBasePath);
|
||||
await PushToRemote(repoBasePath);
|
||||
}
|
||||
|
||||
private async Task<string> GetRepoBasePath(string workingDir)
|
||||
@@ -103,15 +102,6 @@ namespace Cli
|
||||
new Selection("no", null)
|
||||
)
|
||||
);
|
||||
var serviceName = AnsiConsole.Prompt(
|
||||
new TextPrompt<string>("[grey][[Optional]][/] Enter [green]service name[/]:")
|
||||
.AllowEmpty()
|
||||
);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(serviceName))
|
||||
{
|
||||
selection.Version.SetService(serviceName.Trim());
|
||||
}
|
||||
}
|
||||
|
||||
if (selection.Version == null)
|
||||
@@ -122,27 +112,11 @@ namespace Cli
|
||||
return selection;
|
||||
}
|
||||
|
||||
private async Task PushTagsToRemote(string workingDir)
|
||||
private async Task PushToRemote(string workingDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
var output = await _mediator.Send(new PushTagsToRemote.Command(workingDir));
|
||||
AnsiConsole.Write(output);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AnsiConsole.Markup("[red]Error:[/] Tag was written but unable to push to remote\n\n");
|
||||
AnsiConsole.WriteException(ex);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PushCommitsToRemote(string workingDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
var output = await _mediator.Send(new PushCommitsToRemote.Command(workingDir));
|
||||
AnsiConsole.Write(output);
|
||||
await _mediator.Send(new PushCommitsToRemote.Command(workingDir));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<PackageId>Novaloop.UpdateTag</PackageId>
|
||||
<title>Updates the tag of a repo to the next chosen version according the semver symantic.</title>
|
||||
<PackageTags>semver;update-tag;tag;git</PackageTags>
|
||||
<Version>0.2.1</Version>
|
||||
<Version>0.1.5</Version>
|
||||
<Authors>Matthias Langhard</Authors>
|
||||
<Company>Novaloop AG</Company>
|
||||
<PackageProjectUrl>https://gitlab.com/novaloop-oss/novaloop.update-tag</PackageProjectUrl>
|
||||
|
||||
@@ -3,9 +3,9 @@ using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Queries
|
||||
namespace Application.Commands
|
||||
{
|
||||
public class PushCommitsToRemote : IRequestHandler<PushCommitsToRemote.Command, string>
|
||||
public class PushCommitsToRemote : AsyncRequestHandler<PushCommitsToRemote.Command>
|
||||
{
|
||||
private readonly IGitRepoWriteService _gitRepoWriteService;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Application.Queries
|
||||
_gitRepoWriteService = gitRepoWriteService;
|
||||
}
|
||||
|
||||
public class Command : IRequest<string>
|
||||
public class Command : IRequest
|
||||
{
|
||||
public string RepoPath { get; }
|
||||
|
||||
@@ -24,10 +24,10 @@ namespace Application.Queries
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> Handle(Command request, CancellationToken ct)
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _gitRepoWriteService.Push(request.RepoPath, ct);
|
||||
await _gitRepoWriteService.PushTags(request.RepoPath);
|
||||
await _gitRepoWriteService.Push(request.RepoPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Application.Interfaces
|
||||
@@ -6,7 +5,7 @@ namespace Application.Interfaces
|
||||
public interface IGitRepoWriteService
|
||||
{
|
||||
void AddTag(string repoPath, string tag);
|
||||
Task<string> PushTags(string repoPath, CancellationToken cancellationToken);
|
||||
Task<string> Push(string repoPath, CancellationToken ct);
|
||||
Task<string> PushTags(string repoPath);
|
||||
Task<string> Push(string repoPath);
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace Application.Models
|
||||
public int Minor { get; private set; }
|
||||
public int Patch { get; private set; }
|
||||
public int? Rc { get; private set; }
|
||||
public string Service { get; private set; }
|
||||
public string Service { get; }
|
||||
|
||||
|
||||
public override string ToString()
|
||||
@@ -198,10 +198,5 @@ namespace Application.Models
|
||||
{
|
||||
return Rc != null;
|
||||
}
|
||||
|
||||
public void SetService(string service)
|
||||
{
|
||||
Service = service;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using Application.Models;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Queries
|
||||
{
|
||||
public class GetVersionInformationFromRepo : IRequestHandler<GetVersionInformationFromRepo.Query, VersionInformation>
|
||||
public class GetVersionInformationFromRepo : RequestHandler<GetVersionInformationFromRepo.Query, VersionInformation>
|
||||
{
|
||||
public class Query : IRequest<VersionInformation>
|
||||
{
|
||||
@@ -29,7 +27,7 @@ namespace Application.Queries
|
||||
_gitRepoReadService = gitRepoReadService;
|
||||
}
|
||||
|
||||
public async Task<VersionInformation> Handle(Query request, CancellationToken cancellationToken)
|
||||
protected override VersionInformation Handle(Query request)
|
||||
{
|
||||
var versions = _gitRepoReadService
|
||||
.GetAllVersions(request.RepositoryPath);
|
||||
@@ -44,11 +42,10 @@ namespace Application.Queries
|
||||
.OrderByDescending(v => v.Major)
|
||||
.ThenByDescending(v => v.Minor)
|
||||
.ThenByDescending(v => v.Patch)
|
||||
.ThenByDescending(v => v.Rc == null)
|
||||
.ThenByDescending(v => v.Rc)
|
||||
.FirstOrDefault();
|
||||
|
||||
return await Task.FromResult(currentVersion == null ? null : new VersionInformation(currentVersion));
|
||||
return currentVersion == null ? null : new VersionInformation(currentVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Queries
|
||||
{
|
||||
public class PushTagsToRemote : IRequestHandler<PushTagsToRemote.Command, string>
|
||||
{
|
||||
private readonly IGitRepoWriteService _gitRepoWriteService;
|
||||
|
||||
public PushTagsToRemote(IGitRepoWriteService gitRepoWriteService)
|
||||
{
|
||||
_gitRepoWriteService = gitRepoWriteService;
|
||||
}
|
||||
|
||||
public class Command : IRequest<string>
|
||||
{
|
||||
public string RepoPath { get; }
|
||||
|
||||
public Command(string repoPath)
|
||||
{
|
||||
RepoPath = repoPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> Handle(Command request, CancellationToken ct)
|
||||
{
|
||||
return await _gitRepoWriteService.PushTags(request.RepoPath, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
using CliWrap;
|
||||
@@ -15,21 +14,21 @@ namespace Infrastructure.Services
|
||||
repo.ApplyTag(tag);
|
||||
}
|
||||
|
||||
public async Task<string> PushTags(string repoPath, CancellationToken ct)
|
||||
public async Task<string> PushTags(string repoPath)
|
||||
{
|
||||
var result = await Cli.Wrap("git")
|
||||
.WithArguments("push --tags")
|
||||
.WithWorkingDirectory(repoPath)
|
||||
.ExecuteBufferedAsync(ct);
|
||||
.ExecuteBufferedAsync();
|
||||
return result.StandardOutput.Trim();
|
||||
}
|
||||
|
||||
public async Task<string> Push(string repoPath, CancellationToken ct)
|
||||
public async Task<string> Push(string repoPath)
|
||||
{
|
||||
var result = await Cli.Wrap("git")
|
||||
.WithArguments("push")
|
||||
.WithWorkingDirectory(repoPath)
|
||||
.ExecuteBufferedAsync(ct);
|
||||
.ExecuteBufferedAsync();
|
||||
|
||||
return result.StandardOutput.Trim();
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Application.Interfaces;
|
||||
using Application.Models;
|
||||
using Application.Queries;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace UpdateTag.Tests
|
||||
{
|
||||
public class GetVersionInformationFromRepoTests
|
||||
{
|
||||
[Fact]
|
||||
public async void DoesReadCurrentVersionCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var mockedVersionList = new List<Version>
|
||||
{
|
||||
new Version(0, 1, 5),
|
||||
new Version(0, 1, 7),
|
||||
new Version(0, 2, 0),
|
||||
new Version(0, 2, 0, 0),
|
||||
new Version(0, 2, 0, 1),
|
||||
new Version(0, 2, 0, 2)
|
||||
};
|
||||
var gitRepoMock = new Mock<IGitRepoReadService>();
|
||||
gitRepoMock.Setup(m => m.GetAllVersions(It.IsAny<string>()))
|
||||
.Returns(mockedVersionList);
|
||||
var handler = new GetVersionInformationFromRepo(gitRepoMock.Object);
|
||||
var query = new GetVersionInformationFromRepo.Query("");
|
||||
|
||||
// Act
|
||||
var versionInformation = await handler.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("0.2.0", versionInformation.CurrentVersion.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
Reference in New Issue
Block a user