diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 32b8bf63..e9da64c4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,7 @@ jobs: os: [ windows-2022 ] env: - GITTOOLS_GITHUB_TOKEN: ${{ secrets.GITOOLS_GITHUB_TOKEN }} + GITTOOLS_GITHUB_TOKEN: ${{ secrets.GITTOOLS_GITHUB_TOKEN }} NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} NUGET_SOURCE: https://api.nuget.org/v3/index.json CHOCOLATEY_API_KEY: ${{ secrets.CHOCOLATEY_API_KEY }} @@ -43,7 +43,7 @@ jobs: - name: Fetch all tags and branches run: git fetch --prune --unshallow - - name: Install .NET SDK 2.1.x and 5.0.x + - name: Install .NET SDK 2.1.x, 3.1.x, 5.0.x, and 6.0.x uses: actions/setup-dotnet@v3 with: dotnet-version: | diff --git a/nuspec/chocolatey/GitReleaseManager.Portable.nuspec b/nuspec/chocolatey/GitReleaseManager.Portable.nuspec index 9fd8a10b..23b0efde 100644 --- a/nuspec/chocolatey/GitReleaseManager.Portable.nuspec +++ b/nuspec/chocolatey/GitReleaseManager.Portable.nuspec @@ -19,10 +19,8 @@ github release notes create export - - - - + + diff --git a/nuspec/nuget/GitReleaseManager.nuspec b/nuspec/nuget/GitReleaseManager.nuspec index cb39cbff..27de86f7 100644 --- a/nuspec/nuget/GitReleaseManager.nuspec +++ b/nuspec/nuget/GitReleaseManager.nuspec @@ -20,11 +20,9 @@ github release notes create export - - - - - + + + \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 310357cb..22f7beee 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -14,12 +14,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -27,7 +27,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + All diff --git a/src/GitReleaseManager.Cli/GitReleaseManager.Cli.csproj b/src/GitReleaseManager.Cli/GitReleaseManager.Cli.csproj index cc06b907..089f8838 100644 --- a/src/GitReleaseManager.Cli/GitReleaseManager.Cli.csproj +++ b/src/GitReleaseManager.Cli/GitReleaseManager.Cli.csproj @@ -3,7 +3,10 @@ 8.0 Exe GitReleaseManager - net48;net6.0;net7.0 + net6.0 + true + true + win-x64 GitReleaseManager.Cli Create release notes in markdown given a milestone false @@ -20,7 +23,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/src/GitReleaseManager.Cli/Program.cs b/src/GitReleaseManager.Cli/Program.cs index 4c6af781..dc44e89c 100644 --- a/src/GitReleaseManager.Cli/Program.cs +++ b/src/GitReleaseManager.Cli/Program.cs @@ -8,11 +8,13 @@ using GitReleaseManager.Core.Commands; using GitReleaseManager.Core.Configuration; using GitReleaseManager.Core.Helpers; +using GitReleaseManager.Core.Model; using GitReleaseManager.Core.Options; using GitReleaseManager.Core.Provider; using GitReleaseManager.Core.ReleaseNotes; using GitReleaseManager.Core.Templates; using Microsoft.Extensions.DependencyInjection; +using NGitLab; using Octokit; using Serilog; @@ -96,7 +98,6 @@ private static void RegisterServices(BaseSubOptions options) .AddSingleton(fileSystem) .AddSingleton() .AddSingleton() - .AddSingleton() .AddSingleton(); if (options is BaseVcsOptions vcsOptions) @@ -106,9 +107,7 @@ private static void RegisterServices(BaseSubOptions options) throw new Exception("The token option is not defined"); } - var gitHubClient = new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = new Credentials(vcsOptions.Token) }; - serviceCollection = serviceCollection - .AddSingleton(gitHubClient); + RegisterVcsProvider(vcsOptions, serviceCollection); } serviceCollection = serviceCollection @@ -192,10 +191,28 @@ private static Task ExecuteCommand(TOptions options) where TOptions : BaseSubOptions { var command = _serviceProvider.GetRequiredService>(); - return command.Execute(options); + return command.ExecuteAsync(options); } private static void LogOptions(BaseSubOptions options) => Log.Debug("{@Options}", options); + + private static void RegisterVcsProvider(BaseVcsOptions vcsOptions, IServiceCollection serviceCollection) + { + Log.Information("Using {Provider} as VCS Provider", vcsOptions.Provider); + if (vcsOptions.Provider == VcsProvider.GitLab) + { + serviceCollection + .AddSingleton((_) => new GitLabClient("https://gitlab.com", vcsOptions.Token)) + .AddSingleton(); + } + else + { + // default to Github + serviceCollection + .AddSingleton((_) => new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = new Credentials(vcsOptions.Token) }) + .AddSingleton(); + } + } } } \ No newline at end of file diff --git a/src/GitReleaseManager.Core.Tests/Commands/AddAssetsCommandTests.cs b/src/GitReleaseManager.Core.Tests/Commands/AddAssetsCommandTests.cs index 43035efe..abf0f8af 100644 --- a/src/GitReleaseManager.Core.Tests/Commands/AddAssetsCommandTests.cs +++ b/src/GitReleaseManager.Core.Tests/Commands/AddAssetsCommandTests.cs @@ -38,7 +38,7 @@ public async Task Should_Execute_Command() _vcsService.AddAssetsAsync(options.RepositoryOwner, options.RepositoryName, options.TagName, options.AssetPaths). Returns(Task.CompletedTask); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); await _vcsService.Received(1).AddAssetsAsync(options.RepositoryOwner, options.RepositoryName, options.TagName, options.AssetPaths).ConfigureAwait(false); diff --git a/src/GitReleaseManager.Core.Tests/Commands/CloseCommandTests.cs b/src/GitReleaseManager.Core.Tests/Commands/CloseCommandTests.cs index f9a57c89..0f8b7977 100644 --- a/src/GitReleaseManager.Core.Tests/Commands/CloseCommandTests.cs +++ b/src/GitReleaseManager.Core.Tests/Commands/CloseCommandTests.cs @@ -36,7 +36,7 @@ public async Task Should_Execute_Command() _vcsService.CloseMilestoneAsync(options.RepositoryOwner, options.RepositoryName, options.Milestone) .Returns(Task.CompletedTask); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); await _vcsService.Received(1).CloseMilestoneAsync(options.RepositoryOwner, options.RepositoryName, options.Milestone).ConfigureAwait(false); diff --git a/src/GitReleaseManager.Core.Tests/Commands/CreateCommandTests.cs b/src/GitReleaseManager.Core.Tests/Commands/CreateCommandTests.cs index 24c49d95..6853253c 100644 --- a/src/GitReleaseManager.Core.Tests/Commands/CreateCommandTests.cs +++ b/src/GitReleaseManager.Core.Tests/Commands/CreateCommandTests.cs @@ -43,7 +43,7 @@ public async Task Should_Create_Empty_Release() _vcsService.CreateEmptyReleaseAsync(options.RepositoryOwner, options.RepositoryName, options.Name, options.TargetCommitish, options.Prerelease) .Returns(_release); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); await _vcsService.Received(1).CreateEmptyReleaseAsync(options.RepositoryOwner, options.RepositoryName, releaseName, options.TargetCommitish, options.Prerelease).ConfigureAwait(false); @@ -72,7 +72,7 @@ public async Task Should_Create_Release_From_Milestone(string name, int logVerbo _vcsService.CreateReleaseFromMilestoneAsync(options.RepositoryOwner, options.RepositoryName, options.Milestone, releaseName, options.TargetCommitish, options.AssetPaths, options.Prerelease, options.Template) .Returns(_release); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); await _vcsService.Received(1).CreateReleaseFromMilestoneAsync(options.RepositoryOwner, options.RepositoryName, options.Milestone, releaseName, options.TargetCommitish, options.AssetPaths, options.Prerelease, options.Template).ConfigureAwait(false); @@ -98,7 +98,7 @@ public async Task Should_Create_Release_From_InputFile() _vcsService.CreateReleaseFromInputFileAsync(options.RepositoryOwner, options.RepositoryName, options.Name, options.InputFilePath, options.TargetCommitish, options.AssetPaths, options.Prerelease) .Returns(_release); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); await _vcsService.Received(1).CreateReleaseFromInputFileAsync(options.RepositoryOwner, options.RepositoryName, options.Name, options.InputFilePath, options.TargetCommitish, options.AssetPaths, options.Prerelease).ConfigureAwait(false); diff --git a/src/GitReleaseManager.Core.Tests/Commands/DiscardCommandTests.cs b/src/GitReleaseManager.Core.Tests/Commands/DiscardCommandTests.cs index 51de6f0c..66be4f7f 100644 --- a/src/GitReleaseManager.Core.Tests/Commands/DiscardCommandTests.cs +++ b/src/GitReleaseManager.Core.Tests/Commands/DiscardCommandTests.cs @@ -36,7 +36,7 @@ public async Task Should_Execute_Command() _vcsService.DiscardReleaseAsync(options.RepositoryOwner, options.RepositoryName, options.Milestone) .Returns(Task.CompletedTask); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); await _vcsService.Received(1).DiscardReleaseAsync(options.RepositoryOwner, options.RepositoryName, options.Milestone).ConfigureAwait(false); diff --git a/src/GitReleaseManager.Core.Tests/Commands/ExportCommandTests.cs b/src/GitReleaseManager.Core.Tests/Commands/ExportCommandTests.cs index 2eb9e444..b7ed6639 100644 --- a/src/GitReleaseManager.Core.Tests/Commands/ExportCommandTests.cs +++ b/src/GitReleaseManager.Core.Tests/Commands/ExportCommandTests.cs @@ -42,7 +42,7 @@ public async Task Should_Execute_Command() _vcsService.ExportReleasesAsync(options.RepositoryOwner, options.RepositoryName, options.TagName, options.SkipPrereleases) .Returns(releaseText); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); var exportFileExists = File.Exists(_fileOutputPath); diff --git a/src/GitReleaseManager.Core.Tests/Commands/InitCommandTests.cs b/src/GitReleaseManager.Core.Tests/Commands/InitCommandTests.cs index 0305b7b4..8f47f0f8 100644 --- a/src/GitReleaseManager.Core.Tests/Commands/InitCommandTests.cs +++ b/src/GitReleaseManager.Core.Tests/Commands/InitCommandTests.cs @@ -40,7 +40,7 @@ public async Task Should_Execute_Command() { var options = new InitSubOptions { TargetDirectory = _targetDirectory }; - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); var configFilePath = Path.Combine(_targetDirectory, "GitReleaseManager.yml"); @@ -70,7 +70,7 @@ public async Task Should_Not_Execute_Command_For_Legacy_FileName() File.WriteAllText(configFilePath, "s"); var expectedHash = GetHash(configFilePath); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); // Should this perhaps return 1 var actualHash = GetHash(configFilePath); diff --git a/src/GitReleaseManager.Core.Tests/Commands/LabelCommandTests.cs b/src/GitReleaseManager.Core.Tests/Commands/LabelCommandTests.cs index 1762d911..fd185ade 100644 --- a/src/GitReleaseManager.Core.Tests/Commands/LabelCommandTests.cs +++ b/src/GitReleaseManager.Core.Tests/Commands/LabelCommandTests.cs @@ -35,7 +35,7 @@ public async Task Should_Execute_Command() _vcsService.CreateLabelsAsync(options.RepositoryOwner, options.RepositoryName) .Returns(Task.CompletedTask); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); await _vcsService.Received(1).CreateLabelsAsync(options.RepositoryOwner, options.RepositoryName).ConfigureAwait(false); diff --git a/src/GitReleaseManager.Core.Tests/Commands/OpenCommandTests.cs b/src/GitReleaseManager.Core.Tests/Commands/OpenCommandTests.cs index 21c36538..7db1eca0 100644 --- a/src/GitReleaseManager.Core.Tests/Commands/OpenCommandTests.cs +++ b/src/GitReleaseManager.Core.Tests/Commands/OpenCommandTests.cs @@ -36,7 +36,7 @@ public async Task Should_Execute_Command() _vcsService.OpenMilestoneAsync(options.RepositoryOwner, options.RepositoryName, options.Milestone) .Returns(Task.CompletedTask); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); await _vcsService.Received(1).OpenMilestoneAsync(options.RepositoryOwner, options.RepositoryName, options.Milestone).ConfigureAwait(false); diff --git a/src/GitReleaseManager.Core.Tests/Commands/PublishCommandTests.cs b/src/GitReleaseManager.Core.Tests/Commands/PublishCommandTests.cs index 87ebbc98..35e5626a 100644 --- a/src/GitReleaseManager.Core.Tests/Commands/PublishCommandTests.cs +++ b/src/GitReleaseManager.Core.Tests/Commands/PublishCommandTests.cs @@ -36,7 +36,7 @@ public async Task Should_Execute_Command() _vcsService.PublishReleaseAsync(options.RepositoryOwner, options.RepositoryName, options.TagName) .Returns(Task.CompletedTask); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); await _vcsService.Received(1).PublishReleaseAsync(options.RepositoryOwner, options.RepositoryName, options.TagName).ConfigureAwait(false); diff --git a/src/GitReleaseManager.Core.Tests/Commands/ShowConfigCommandTests.cs b/src/GitReleaseManager.Core.Tests/Commands/ShowConfigCommandTests.cs index 7456af05..ff021435 100644 --- a/src/GitReleaseManager.Core.Tests/Commands/ShowConfigCommandTests.cs +++ b/src/GitReleaseManager.Core.Tests/Commands/ShowConfigCommandTests.cs @@ -1,5 +1,7 @@ +using System; using System.Threading.Tasks; using GitReleaseManager.Core.Commands; +using GitReleaseManager.Core.Configuration; using GitReleaseManager.Core.Helpers; using GitReleaseManager.Core.Options; using NSubstitute; @@ -21,7 +23,10 @@ public void Setup() { _fileSystem = Substitute.For(); _logger = Substitute.For(); - _command = new ShowConfigCommand(_fileSystem, _logger); + + var currentDirectory = Environment.CurrentDirectory; + var configuration = ConfigurationProvider.Provide(currentDirectory, _fileSystem); + _command = new ShowConfigCommand(_logger, configuration); } [Test] @@ -29,7 +34,7 @@ public async Task Should_Execute_Command() { var options = new ShowConfigSubOptions(); - var result = await _command.Execute(options).ConfigureAwait(false); + var result = await _command.ExecuteAsync(options).ConfigureAwait(false); result.ShouldBe(0); _logger.Received(1).Information(Arg.Any(), Arg.Any()); diff --git a/src/GitReleaseManager.Core.Tests/GitReleaseManager.Core.Tests.csproj b/src/GitReleaseManager.Core.Tests/GitReleaseManager.Core.Tests.csproj index fd1d2ad8..87fe7f3a 100644 --- a/src/GitReleaseManager.Core.Tests/GitReleaseManager.Core.Tests.csproj +++ b/src/GitReleaseManager.Core.Tests/GitReleaseManager.Core.Tests.csproj @@ -1,7 +1,7 @@ 8.0 - net48;net6.0;net7.0 + net6.0;net7.0 GitReleaseManager.Core.Tests Test Project for GitReleaseManager.Core $(NoWarn);CA1707;Serilog004; @@ -17,16 +17,16 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - + + - + \ No newline at end of file diff --git a/src/GitReleaseManager.Core.Tests/Provider/GitHubProviderTests.cs b/src/GitReleaseManager.Core.Tests/Provider/GitHubProviderTests.cs index 253fa385..a9e1c563 100644 --- a/src/GitReleaseManager.Core.Tests/Provider/GitHubProviderTests.cs +++ b/src/GitReleaseManager.Core.Tests/Provider/GitHubProviderTests.cs @@ -20,6 +20,7 @@ using NotFoundException = GitReleaseManager.Core.Exceptions.NotFoundException; using RateLimit = GitReleaseManager.Core.Model.RateLimit; using Release = GitReleaseManager.Core.Model.Release; +using ReleaseAsset= GitReleaseManager.Core.Model.ReleaseAsset; using ReleaseAssetUpload = GitReleaseManager.Core.Model.ReleaseAssetUpload; namespace GitReleaseManager.Core.Tests.Provider @@ -31,7 +32,8 @@ public class GitHubProviderTests private const string REPOSITORY = "repository"; private const string BASE = "0.1.0"; private const string HEAD = "0.5.0"; - private const int MILESTONE_NUMBER = 1; + private const int MILESTONE_PUBLIC_NUMBER = 1; + private const int MILESTONE_INTERNAL_NUMBER = 123; private const string MILESTONE_NUMBER_STRING = "1"; private const string MILESTONE_TITLE = "0.1.0"; private const int ISSUE_NUMBER = 1; @@ -43,7 +45,11 @@ public class GitHubProviderTests private const string NOT_FOUND_MESSAGE = "NotFound"; private const bool SKIP_PRERELEASES = false; - private readonly Release _release = new Release(); + private readonly Release _release = new Release { Id = RELEASE_ID }; + private readonly Issue _issue = new Issue { PublicNumber = ISSUE_NUMBER }; + private readonly Milestone _milestone = new Milestone { PublicNumber = MILESTONE_PUBLIC_NUMBER, InternalNumber = MILESTONE_INTERNAL_NUMBER }; + private readonly Label _label = new Label { Name = LABEL_NAME }; + private readonly ReleaseAsset _asset = new ReleaseAsset { Id = ASSET_ID }; private readonly ReleaseAssetUpload _releaseAssetUpload = new ReleaseAssetUpload(); private readonly Octokit.NewLabel _newLabel = new Octokit.NewLabel(LABEL_NAME, "ffffff"); private readonly Octokit.NewRelease _newRelease = new Octokit.NewRelease(TAG_NAME); @@ -69,7 +75,7 @@ public async Task Should_Delete_Asset() _gitHubClient.Repository.Release.DeleteAsset(OWNER, REPOSITORY, ASSET_ID) .Returns(Task.FromResult); - await _gitHubProvider.DeleteAssetAsync(OWNER, REPOSITORY, ASSET_ID).ConfigureAwait(false); + await _gitHubProvider.DeleteAssetAsync(OWNER, REPOSITORY, _asset).ConfigureAwait(false); await _gitHubClient.Repository.Release.Received(1).DeleteAsset(OWNER, REPOSITORY, ASSET_ID).ConfigureAwait(false); } @@ -80,7 +86,7 @@ public async Task Should_Throw_An_Exception_On_Deleting_Asset_For_Non_Existing_I _gitHubClient.Repository.Release.DeleteAsset(OWNER, REPOSITORY, ASSET_ID) .Returns(Task.FromException(_notFoundException)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteAssetAsync(OWNER, REPOSITORY, ASSET_ID)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteAssetAsync(OWNER, REPOSITORY, _asset)).ConfigureAwait(false); ex.Message.ShouldBe(_notFoundException.Message); ex.InnerException.ShouldBe(_notFoundException); } @@ -91,7 +97,7 @@ public async Task Should_Throw_An_Exception_On_Deleting_Asset() _gitHubClient.Repository.Release.DeleteAsset(OWNER, REPOSITORY, ASSET_ID) .Returns(Task.FromException(_exception)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteAssetAsync(OWNER, REPOSITORY, ASSET_ID)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteAssetAsync(OWNER, REPOSITORY, _asset)).ConfigureAwait(false); ex.Message.ShouldBe(_exception.Message); ex.InnerException.ShouldBe(_exception); } @@ -161,7 +167,7 @@ public async Task Should_Get_Commits_Count() _gitHubClient.Repository.Commit.Compare(OWNER, REPOSITORY, BASE, HEAD) .Returns(Task.FromResult(new CompareResult(null, null, null, null, null, null, null, null, commitsCount, 0, 0, null, null))); - var result = await _gitHubProvider.GetCommitsCount(OWNER, REPOSITORY, BASE, HEAD).ConfigureAwait(false); + var result = await _gitHubProvider.GetCommitsCountAsync(OWNER, REPOSITORY, BASE, HEAD).ConfigureAwait(false); result.ShouldBe(commitsCount); await _gitHubClient.Repository.Commit.Received(1).Compare(OWNER, REPOSITORY, BASE, HEAD).ConfigureAwait(false); @@ -173,7 +179,7 @@ public async Task Should_Get_Commits_Count_Zero_If_No_Commits_Found() _gitHubClient.Repository.Commit.Compare(OWNER, REPOSITORY, BASE, HEAD) .Returns(Task.FromException(_notFoundException)); - var result = await _gitHubProvider.GetCommitsCount(OWNER, REPOSITORY, BASE, HEAD).ConfigureAwait(false); + var result = await _gitHubProvider.GetCommitsCountAsync(OWNER, REPOSITORY, BASE, HEAD).ConfigureAwait(false); result.ShouldBe(0); await _gitHubClient.Repository.Commit.Received(1).Compare(OWNER, REPOSITORY, BASE, HEAD).ConfigureAwait(false); @@ -185,7 +191,7 @@ public async Task Should_Throw_An_Exception_On_Getting_Commits_Count() _gitHubClient.Repository.Commit.Compare(OWNER, REPOSITORY, BASE, HEAD) .Returns(Task.FromException(_exception)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.GetCommitsCount(OWNER, REPOSITORY, BASE, HEAD)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.GetCommitsCountAsync(OWNER, REPOSITORY, BASE, HEAD)).ConfigureAwait(false); ex.Message.ShouldContain(_exception.Message); ex.InnerException.ShouldBeSameAs(_exception); } @@ -230,7 +236,7 @@ public async Task Should_Create_Issue_Comment() _gitHubClient.Issue.Comment.Create(OWNER, REPOSITORY, ISSUE_NUMBER, ISSUE_COMMENT) .Returns(Task.FromResult(new Octokit.IssueComment())); - await _gitHubProvider.CreateIssueCommentAsync(OWNER, REPOSITORY, ISSUE_NUMBER, ISSUE_COMMENT).ConfigureAwait(false); + await _gitHubProvider.CreateIssueCommentAsync(OWNER, REPOSITORY, _issue, ISSUE_COMMENT).ConfigureAwait(false); await _gitHubClient.Issue.Comment.Received(1).Create(OWNER, REPOSITORY, ISSUE_NUMBER, ISSUE_COMMENT).ConfigureAwait(false); } @@ -241,7 +247,7 @@ public async Task Should_Throw_An_Exception_On_Creating_Issue_Comment_For_Non_Ex _gitHubClient.Issue.Comment.Create(OWNER, REPOSITORY, ISSUE_NUMBER, ISSUE_COMMENT) .Returns(Task.FromException(_notFoundException)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.CreateIssueCommentAsync(OWNER, REPOSITORY, ISSUE_NUMBER, ISSUE_COMMENT)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.CreateIssueCommentAsync(OWNER, REPOSITORY, _issue, ISSUE_COMMENT)).ConfigureAwait(false); ex.Message.ShouldBe(_notFoundException.Message); ex.InnerException.ShouldBe(_notFoundException); } @@ -252,7 +258,7 @@ public async Task Should_Throw_An_Exception_On_Creating_Issue_Comment() _gitHubClient.Issue.Comment.Create(OWNER, REPOSITORY, ISSUE_NUMBER, ISSUE_COMMENT) .Returns(Task.FromException(_exception)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.CreateIssueCommentAsync(OWNER, REPOSITORY, ISSUE_NUMBER, ISSUE_COMMENT)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.CreateIssueCommentAsync(OWNER, REPOSITORY, _issue, ISSUE_COMMENT)).ConfigureAwait(false); ex.Message.ShouldBe(_exception.Message); ex.InnerException.ShouldBe(_exception); } @@ -270,7 +276,7 @@ public async Task Should_Get_Issues_For_Milestone(ItemStateFilter itemStateFilte _mapper.Map>(Arg.Any()) .Returns(issues); - var result = await _gitHubProvider.GetIssuesAsync(OWNER, REPOSITORY, MILESTONE_NUMBER, itemStateFilter).ConfigureAwait(false); + var result = await _gitHubProvider.GetIssuesAsync(OWNER, REPOSITORY, _milestone, itemStateFilter).ConfigureAwait(false); result.ShouldBeSameAs(issues); await _gitHubClient.Issue.Received(1).GetAllForRepository( @@ -288,7 +294,7 @@ public async Task Should_Throw_An_Exception_On_Getting_Issues_For_Non_Existent_M _gitHubClient.Issue.GetAllForRepository(OWNER, REPOSITORY, Arg.Any(), Arg.Any()) .Returns(Task.FromException>(_exception)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.GetIssuesAsync(OWNER, REPOSITORY, 1)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.GetIssuesAsync(OWNER, REPOSITORY, _milestone)).ConfigureAwait(false); ex.Message.ShouldBe(_exception.Message); ex.InnerException.ShouldBe(_exception); } @@ -304,7 +310,7 @@ public async Task Should_Get_Issue_Comments() _mapper.Map>(Arg.Any()) .Returns(comments); - var result = await _gitHubProvider.GetIssueCommentsAsync(OWNER, REPOSITORY, ISSUE_NUMBER).ConfigureAwait(false); + var result = await _gitHubProvider.GetIssueCommentsAsync(OWNER, REPOSITORY, _issue).ConfigureAwait(false); result.ShouldBeSameAs(comments); await _gitHubClient.Issue.Comment.Received(1).GetAllForIssue(OWNER, REPOSITORY, ISSUE_NUMBER, Arg.Any()).ConfigureAwait(false); @@ -317,7 +323,7 @@ public async Task Should_Throw_An_Exception_On_Getting_Issue_Comments_For_Non_Ex _gitHubClient.Issue.Comment.GetAllForIssue(OWNER, REPOSITORY, ISSUE_NUMBER, Arg.Any()) .Returns(Task.FromException>(_notFoundException)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.GetIssueCommentsAsync(OWNER, REPOSITORY, ISSUE_NUMBER)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.GetIssueCommentsAsync(OWNER, REPOSITORY, _issue)).ConfigureAwait(false); ex.Message.ShouldBe(_notFoundException.Message); ex.InnerException.ShouldBe(_notFoundException); } @@ -328,7 +334,7 @@ public async Task Should_Throw_An_Exception_On_Getting_Issue_Comments() _gitHubClient.Issue.Comment.GetAllForIssue(OWNER, REPOSITORY, ISSUE_NUMBER, Arg.Any()) .Returns(Task.FromException>(_exception)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.GetIssueCommentsAsync(OWNER, REPOSITORY, ISSUE_NUMBER)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.GetIssueCommentsAsync(OWNER, REPOSITORY, _issue)).ConfigureAwait(false); ex.Message.ShouldBe(_exception.Message); ex.InnerException.ShouldBe(_exception); } @@ -371,7 +377,7 @@ public async Task Should_Delete_Label() _gitHubClient.Issue.Labels.Delete(OWNER, REPOSITORY, LABEL_NAME) .Returns(Task.FromResult); - await _gitHubProvider.DeleteLabelAsync(OWNER, REPOSITORY, LABEL_NAME).ConfigureAwait(false); + await _gitHubProvider.DeleteLabelAsync(OWNER, REPOSITORY, _label).ConfigureAwait(false); await _gitHubClient.Issue.Labels.Received(1).Delete(OWNER, REPOSITORY, LABEL_NAME).ConfigureAwait(false); } @@ -382,7 +388,7 @@ public async Task Should_Throw_An_Exception_On_Deleting_Label_For_Non_Existing_L _gitHubClient.Issue.Labels.Delete(OWNER, REPOSITORY, LABEL_NAME) .Returns(Task.FromException>(_notFoundException)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteLabelAsync(OWNER, REPOSITORY, LABEL_NAME)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteLabelAsync(OWNER, REPOSITORY, _label)).ConfigureAwait(false); ex.Message.ShouldBe(_notFoundException.Message); ex.InnerException.ShouldBe(_notFoundException); } @@ -393,7 +399,7 @@ public async Task Should_Throw_An_Exception_On_Deleting_Label() _gitHubClient.Issue.Labels.Delete(OWNER, REPOSITORY, LABEL_NAME) .Returns(Task.FromException>(_exception)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteLabelAsync(OWNER, REPOSITORY, LABEL_NAME)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteLabelAsync(OWNER, REPOSITORY, _label)).ConfigureAwait(false); ex.Message.ShouldBe(_exception.Message); ex.InnerException.ShouldBe(_exception); } @@ -508,21 +514,21 @@ public async Task Should_Throw_An_Exception_On_Getting_Milestones() [TestCase(ItemState.Open)] public async Task Should_Set_Milestone_State(ItemState itemState) { - _gitHubClient.Issue.Milestone.Update(OWNER, REPOSITORY, MILESTONE_NUMBER, Arg.Any()) + _gitHubClient.Issue.Milestone.Update(OWNER, REPOSITORY, MILESTONE_PUBLIC_NUMBER, Arg.Any()) .Returns(Task.FromResult(new Octokit.Milestone())); - await _gitHubProvider.SetMilestoneStateAsync(OWNER, REPOSITORY, MILESTONE_NUMBER, itemState).ConfigureAwait(false); + await _gitHubProvider.SetMilestoneStateAsync(OWNER, REPOSITORY, _milestone, itemState).ConfigureAwait(false); - await _gitHubClient.Issue.Milestone.Received(1).Update(OWNER, REPOSITORY, MILESTONE_NUMBER, Arg.Is(o => o.State == (Octokit.ItemState)itemState)).ConfigureAwait(false); + await _gitHubClient.Issue.Milestone.Received(1).Update(OWNER, REPOSITORY, MILESTONE_PUBLIC_NUMBER, Arg.Is(o => o.State == (Octokit.ItemState)itemState)).ConfigureAwait(false); } [Test] public async Task Should_Throw_An_Exception_On_Setting_Milestone_State_For_Non_Existent_Number() { - _gitHubClient.Issue.Milestone.Update(OWNER, REPOSITORY, MILESTONE_NUMBER, Arg.Any()) + _gitHubClient.Issue.Milestone.Update(OWNER, REPOSITORY, MILESTONE_PUBLIC_NUMBER, Arg.Any()) .Returns(Task.FromException(_notFoundException)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.SetMilestoneStateAsync(OWNER, REPOSITORY, MILESTONE_NUMBER, ItemState.Closed)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.SetMilestoneStateAsync(OWNER, REPOSITORY, _milestone, ItemState.Closed)).ConfigureAwait(false); ex.Message.ShouldBe(_notFoundException.Message); ex.InnerException.ShouldBeSameAs(_notFoundException); } @@ -530,10 +536,10 @@ public async Task Should_Throw_An_Exception_On_Setting_Milestone_State_For_Non_E [Test] public async Task Should_Throw_An_Exception_On_Setting_Milestone_State() { - _gitHubClient.Issue.Milestone.Update(OWNER, REPOSITORY, MILESTONE_NUMBER, Arg.Any()) + _gitHubClient.Issue.Milestone.Update(OWNER, REPOSITORY, MILESTONE_PUBLIC_NUMBER, Arg.Any()) .Returns(Task.FromException(_exception)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.SetMilestoneStateAsync(OWNER, REPOSITORY, MILESTONE_NUMBER, ItemState.Closed)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.SetMilestoneStateAsync(OWNER, REPOSITORY, _milestone, ItemState.Closed)).ConfigureAwait(false); ex.Message.ShouldBe(_exception.Message); ex.InnerException.ShouldBeSameAs(_exception); } @@ -581,25 +587,21 @@ public async Task Should_Throw_An_Exception_On_Creating_Release() [Test] public async Task Should_Delete_Release() { - var id = 1; - - _gitHubClient.Repository.Release.Delete(OWNER, REPOSITORY, id) + _gitHubClient.Repository.Release.Delete(OWNER, REPOSITORY, RELEASE_ID) .Returns(Task.CompletedTask); - await _gitHubProvider.DeleteReleaseAsync(OWNER, REPOSITORY, id).ConfigureAwait(false); + await _gitHubProvider.DeleteReleaseAsync(OWNER, REPOSITORY, _release).ConfigureAwait(false); - await _gitHubClient.Repository.Release.Received(1).Delete(OWNER, REPOSITORY, id).ConfigureAwait(false); + await _gitHubClient.Repository.Release.Received(1).Delete(OWNER, REPOSITORY, RELEASE_ID).ConfigureAwait(false); } [Test] public async Task Should_Throw_An_Exception_On_Deleting_Release_For_Non_Existent_Id() { - var id = 1; - - _gitHubClient.Repository.Release.Delete(OWNER, REPOSITORY, id) + _gitHubClient.Repository.Release.Delete(OWNER, REPOSITORY, RELEASE_ID) .Returns(Task.FromException(_notFoundException)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteReleaseAsync(OWNER, REPOSITORY, id)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteReleaseAsync(OWNER, REPOSITORY, _release)).ConfigureAwait(false); ex.Message.ShouldBe(_notFoundException.Message); ex.InnerException.ShouldBeSameAs(_notFoundException); } @@ -607,12 +609,10 @@ public async Task Should_Throw_An_Exception_On_Deleting_Release_For_Non_Existent [Test] public async Task Should_Throw_An_Exception_On_Deleting_Release() { - var id = 1; - - _gitHubClient.Repository.Release.Delete(OWNER, REPOSITORY, id) + _gitHubClient.Repository.Release.Delete(OWNER, REPOSITORY, RELEASE_ID) .Returns(Task.FromException(_exception)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteReleaseAsync(OWNER, REPOSITORY, id)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.DeleteReleaseAsync(OWNER, REPOSITORY, _release)).ConfigureAwait(false); ex.Message.ShouldBe(_exception.Message); ex.InnerException.ShouldBeSameAs(_exception); } @@ -688,7 +688,7 @@ public async Task Should_Publish_Release() _gitHubClient.Repository.Release.Edit(OWNER, REPOSITORY, RELEASE_ID, Arg.Any()) .Returns(Task.FromResult(new Octokit.Release())); - await _gitHubProvider.PublishReleaseAsync(OWNER, REPOSITORY, TAG_NAME, RELEASE_ID).ConfigureAwait(false); + await _gitHubProvider.PublishReleaseAsync(OWNER, REPOSITORY, TAG_NAME, _release).ConfigureAwait(false); await _gitHubClient.Repository.Release.Received(1).Edit(OWNER, REPOSITORY, RELEASE_ID, Arg.Is(o => o.Draft == false && @@ -701,7 +701,7 @@ public async Task Should_Throw_An_Exception_On_Publishing_Release_For_Non_Existe _gitHubClient.Repository.Release.Edit(OWNER, REPOSITORY, RELEASE_ID, Arg.Any()) .Returns(Task.FromException(_notFoundException)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.PublishReleaseAsync(OWNER, REPOSITORY, TAG_NAME, RELEASE_ID)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.PublishReleaseAsync(OWNER, REPOSITORY, TAG_NAME, _release)).ConfigureAwait(false); ex.Message.ShouldBe(_notFoundException.Message); ex.InnerException.ShouldBe(_notFoundException); } @@ -712,7 +712,7 @@ public async Task Should_Throw_An_Exception_On_Publishing_Release() _gitHubClient.Repository.Release.Edit(OWNER, REPOSITORY, RELEASE_ID, Arg.Any()) .Returns(Task.FromException(_exception)); - var ex = await Should.ThrowAsync(() => _gitHubProvider.PublishReleaseAsync(OWNER, REPOSITORY, TAG_NAME, RELEASE_ID)).ConfigureAwait(false); + var ex = await Should.ThrowAsync(() => _gitHubProvider.PublishReleaseAsync(OWNER, REPOSITORY, TAG_NAME, _release)).ConfigureAwait(false); ex.Message.ShouldBe(_exception.Message); ex.InnerException.ShouldBe(_exception); } diff --git a/src/GitReleaseManager.Core.Tests/VcsServiceTests.cs b/src/GitReleaseManager.Core.Tests/VcsServiceTests.cs index 202c370e..86306af7 100644 --- a/src/GitReleaseManager.Core.Tests/VcsServiceTests.cs +++ b/src/GitReleaseManager.Core.Tests/VcsServiceTests.cs @@ -26,7 +26,8 @@ public class VcsServiceTests { private const string OWNER = "owner"; private const string REPOSITORY = "repository"; - private const int MILESTONE_NUMBER = 1; + private const int MILESTONE_PUBLIC_NUMBER = 1; + private const int MILESTONE_INTERNAL_NUMBER = 123; private const string MILESTONE_TITLE = "0.1.0"; private const string TAG_NAME = "0.1.0"; private const string RELEASE_NOTES = "Release Notes"; @@ -126,7 +127,7 @@ public async Task Should_Add_Assets() await _vcsService.AddAssetsAsync(OWNER, REPOSITORY, TAG_NAME, _assets).ConfigureAwait(false); await _vcsProvider.Received(1).GetReleaseAsync(OWNER, REPOSITORY, TAG_NAME).ConfigureAwait(false); - await _vcsProvider.DidNotReceive().DeleteAssetAsync(OWNER, REPOSITORY, Arg.Any()).ConfigureAwait(false); + await _vcsProvider.DidNotReceive().DeleteAssetAsync(OWNER, REPOSITORY, Arg.Any()).ConfigureAwait(false); await _vcsProvider.Received(assetsCount).UploadAssetAsync(release, Arg.Any()).ConfigureAwait(false); _logger.DidNotReceive().Warning(Arg.Any(), Arg.Any()); @@ -149,7 +150,7 @@ public async Task Should_Add_Assets_With_Deleting_Existing_Assets() await _vcsService.AddAssetsAsync(OWNER, REPOSITORY, TAG_NAME, _assets).ConfigureAwait(false); await _vcsProvider.Received(1).GetReleaseAsync(OWNER, REPOSITORY, TAG_NAME).ConfigureAwait(false); - await _vcsProvider.Received(releaseAssetsCount).DeleteAssetAsync(OWNER, REPOSITORY, releaseAsset.Id).ConfigureAwait(false); + await _vcsProvider.Received(releaseAssetsCount).DeleteAssetAsync(OWNER, REPOSITORY, releaseAsset).ConfigureAwait(false); await _vcsProvider.Received(assetsCount).UploadAssetAsync(release, Arg.Any()).ConfigureAwait(false); _logger.Received(releaseAssetsCount).Warning(Arg.Any(), Arg.Any()); @@ -172,7 +173,7 @@ public async Task Should_Throw_Exception_On_Adding_Assets_When_Asset_File_Not_Ex ex.Message.ShouldContain(assetFilePath); await _vcsProvider.Received(1).GetReleaseAsync(OWNER, REPOSITORY, TAG_NAME).ConfigureAwait(false); - await _vcsProvider.DidNotReceive().DeleteAssetAsync(OWNER, REPOSITORY, Arg.Any()).ConfigureAwait(false); + await _vcsProvider.DidNotReceive().DeleteAssetAsync(OWNER, REPOSITORY, Arg.Any()).ConfigureAwait(false); await _vcsProvider.DidNotReceive().UploadAssetAsync(release, Arg.Any()).ConfigureAwait(false); } @@ -182,7 +183,7 @@ public async Task Should_Do_Nothing_On_Missing_Assets(IList assets) await _vcsService.AddAssetsAsync(OWNER, REPOSITORY, TAG_NAME, assets).ConfigureAwait(false); await _vcsProvider.DidNotReceive().GetReleaseAsync(OWNER, REPOSITORY, TAG_NAME).ConfigureAwait(false); - await _vcsProvider.DidNotReceive().DeleteAssetAsync(OWNER, REPOSITORY, Arg.Any()).ConfigureAwait(false); + await _vcsProvider.DidNotReceive().DeleteAssetAsync(OWNER, REPOSITORY, Arg.Any()).ConfigureAwait(false); await _vcsProvider.DidNotReceive().UploadAssetAsync(Arg.Any(), Arg.Any()).ConfigureAwait(false); } @@ -205,7 +206,7 @@ public async Task Should_Create_Labels() _vcsProvider.GetLabelsAsync(OWNER, REPOSITORY) .Returns(Task.FromResult((IEnumerable