diff --git a/src/Cli/AppRunner.cs b/src/Cli/AppRunner.cs index ad8e7de..de8845f 100644 --- a/src/Cli/AppRunner.cs +++ b/src/Cli/AppRunner.cs @@ -26,7 +26,8 @@ namespace Cli var chosenService = await ChooseService(repoBasePath); var selection = await SelectVersion(repoBasePath, chosenService); await AddVersionTagToRepo(repoBasePath, selection.Version.ToString()); - await PushToRemote(repoBasePath); + await PushTagsToRemote(repoBasePath); + await PushCommitsToRemote(repoBasePath); } private async Task GetRepoBasePath(string workingDir) @@ -112,11 +113,27 @@ namespace Cli return selection; } - private async Task PushToRemote(string workingDir) + private async Task PushTagsToRemote(string workingDir) { try { - await _mediator.Send(new PushCommitsToRemote.Command(workingDir)); + 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); } catch (Exception ex) { diff --git a/src/Cli/Cli.csproj b/src/Cli/Cli.csproj index 368d594..60dd655 100644 --- a/src/Cli/Cli.csproj +++ b/src/Cli/Cli.csproj @@ -9,7 +9,7 @@ Novaloop.UpdateTag Updates the tag of a repo to the next chosen version according the semver symantic. semver;update-tag;tag;git - 0.1.5 + 0.1.7 Matthias Langhard Novaloop AG https://gitlab.com/novaloop-oss/novaloop.update-tag diff --git a/src/Core/Interfaces/IGitRepoWriteService.cs b/src/Core/Interfaces/IGitRepoWriteService.cs index 4fd4722..b64566b 100644 --- a/src/Core/Interfaces/IGitRepoWriteService.cs +++ b/src/Core/Interfaces/IGitRepoWriteService.cs @@ -1,3 +1,4 @@ +using System.Threading; using System.Threading.Tasks; namespace Application.Interfaces @@ -5,6 +6,7 @@ namespace Application.Interfaces public interface IGitRepoWriteService { void AddTag(string repoPath, string tag); - Task Push(string repoPath); + Task PushTags(string repoPath, CancellationToken cancellationToken); + Task Push(string repoPath, CancellationToken ct); } } \ No newline at end of file diff --git a/src/Core/Commands/PushCommitsToRemote.cs b/src/Core/Queries/PushCommitsToRemote.cs similarity index 62% rename from src/Core/Commands/PushCommitsToRemote.cs rename to src/Core/Queries/PushCommitsToRemote.cs index 80daed5..ddff9b5 100644 --- a/src/Core/Commands/PushCommitsToRemote.cs +++ b/src/Core/Queries/PushCommitsToRemote.cs @@ -3,9 +3,9 @@ using System.Threading.Tasks; using Application.Interfaces; using MediatR; -namespace Application.Commands +namespace Application.Queries { - public class PushCommitsToRemote : AsyncRequestHandler + public class PushCommitsToRemote : IRequestHandler { private readonly IGitRepoWriteService _gitRepoWriteService; @@ -14,7 +14,7 @@ namespace Application.Commands _gitRepoWriteService = gitRepoWriteService; } - public class Command : IRequest + public class Command : IRequest { public string RepoPath { get; } @@ -24,9 +24,10 @@ namespace Application.Commands } } - protected override async Task Handle(Command request, CancellationToken cancellationToken) + + public async Task Handle(Command request, CancellationToken ct) { - await _gitRepoWriteService.Push(request.RepoPath); + return await _gitRepoWriteService.Push(request.RepoPath, ct); } } } \ No newline at end of file diff --git a/src/Core/Queries/PushTagsToRemote.cs b/src/Core/Queries/PushTagsToRemote.cs new file mode 100644 index 0000000..6cd1c66 --- /dev/null +++ b/src/Core/Queries/PushTagsToRemote.cs @@ -0,0 +1,33 @@ +using System.Threading; +using System.Threading.Tasks; +using Application.Interfaces; +using MediatR; + +namespace Application.Queries +{ + public class PushTagsToRemote : IRequestHandler + { + private readonly IGitRepoWriteService _gitRepoWriteService; + + public PushTagsToRemote(IGitRepoWriteService gitRepoWriteService) + { + _gitRepoWriteService = gitRepoWriteService; + } + + public class Command : IRequest + { + public string RepoPath { get; } + + public Command(string repoPath) + { + RepoPath = repoPath; + } + } + + + public async Task Handle(Command request, CancellationToken ct) + { + return await _gitRepoWriteService.PushTags(request.RepoPath, ct); + } + } +} \ No newline at end of file diff --git a/src/Infrastructure/Services/GitRepoWriteService.cs b/src/Infrastructure/Services/GitRepoWriteService.cs index dc7a1e8..abc8e50 100644 --- a/src/Infrastructure/Services/GitRepoWriteService.cs +++ b/src/Infrastructure/Services/GitRepoWriteService.cs @@ -1,3 +1,4 @@ +using System.Threading; using System.Threading.Tasks; using Application.Interfaces; using CliWrap; @@ -14,12 +15,23 @@ namespace Infrastructure.Services repo.ApplyTag(tag); } - public async Task Push(string repoPath) + public async Task PushTags(string repoPath, CancellationToken ct) { - await Cli.Wrap("git") + var result = await Cli.Wrap("git") .WithArguments("push --tags") .WithWorkingDirectory(repoPath) - .ExecuteBufferedAsync(); + .ExecuteBufferedAsync(ct); + return result.StandardOutput.Trim(); + } + + public async Task Push(string repoPath, CancellationToken ct) + { + var result = await Cli.Wrap("git") + .WithArguments("push") + .WithWorkingDirectory(repoPath) + .ExecuteBufferedAsync(ct); + + return result.StandardOutput.Trim(); } } } \ No newline at end of file