Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#476) Add validation of input file path handler #577

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/GitReleaseManager.Core.Tests/Commands/CreateCommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using GitReleaseManager.Core.Commands;
Expand Down Expand Up @@ -106,5 +107,28 @@ public async Task Should_Create_Release_From_InputFile()
_logger.Received(1).Information(Arg.Any<string>(), _release.HtmlUrl);
_logger.Received(1).Verbose(Arg.Any<string>(), _release.Body);
}

[Test]
public async Task Throws_Exception_When_Both_Milestone_And_Input_File_Specified()
{
var options = new CreateSubOptions
{
RepositoryName = "repository",
RepositoryOwner = "owner",
InputFilePath = "file.path",
TargetCommitish = "target commitish",
AssetPaths = new List<string>(),
Prerelease = false,
Milestone = "0.5.0",
};

Func<Task> action = async () => await _command.ExecuteAsync(options).ConfigureAwait(false);

var ex = await action.ShouldThrowAsync<InvalidOperationException>().ConfigureAwait(false);
ex.Message.ShouldBe("Both a milestone and an input file path have been specified. Only one of these arguments may be used at the same time when creating a release!");

_vcsService.ReceivedCalls().ShouldBeEmpty();
_logger.ReceivedCalls().ShouldHaveSingleItem();
}
}
}
6 changes: 6 additions & 0 deletions src/GitReleaseManager.Core/Commands/CreateCommand.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using GitReleaseManager.Core.Model;
using GitReleaseManager.Core.Options;
Expand Down Expand Up @@ -29,6 +30,11 @@ public async Task<int> ExecuteAsync(CreateSubOptions options)
}
else if (!string.IsNullOrEmpty(options.Milestone))
{
if (!string.IsNullOrWhiteSpace(options.InputFilePath))
{
throw new InvalidOperationException("Both a milestone and an input file path have been specified. Only one of these arguments may be used at the same time when creating a release!");
}

_logger.Verbose("Milestone {Milestone} was specified", options.Milestone);
var releaseName = options.Name;

Expand Down
4 changes: 2 additions & 2 deletions src/GitReleaseManager.Core/Options/CreateSubOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
public class CreateSubOptions : BaseVcsOptions
{
[Option('a', "assets", Separator = ',', HelpText = "Paths to the files to include in the release.", Required = false)]
public IList<string> AssetPaths { get; set; }

Check warning on line 10 in src/GitReleaseManager.Core/Options/CreateSubOptions.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Change 'AssetPaths' to be read-only by removing the property setter (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2227)

[Option('c', "targetcommitish", HelpText = "The commit to tag. Can be a branch or SHA. Defaults to repository's default branch.", Required = false)]
public string TargetCommitish { get; set; }

[Option('m', "milestone", HelpText = "The milestone to use.", Required = false)]
[Option('m', "milestone", HelpText = "The milestone to use. (Can't be used together with a release notes file path).", Required = false)]
public string Milestone { get; set; }

[Option('n', "name", HelpText = "The name of the release (Typically this is the generated SemVer Version Number).", Required = false)]
public string Name { get; set; }

[Option('i', "inputFilePath", HelpText = "The path to the file to be used as the content of the release notes.", Required = false)]
[Option('i', "inputFilePath", HelpText = "The path to the file to be used as the content of the release notes. (Can't be used together with a milestone)", Required = false)]
public string InputFilePath { get; set; }

[Option('t', "template", HelpText = "The name of the template file to use. Can also be a relative or absolute path (relative paths are resolved from yaml template-dir configuration). Defaults to 'default'")]
Expand Down
Loading