Skip to content

Commit

Permalink
Merge pull request #577 from AdmiringWorm/AdmiringWorm/issue476
Browse files Browse the repository at this point in the history
(#476) Add validation of input file path handler
  • Loading branch information
gep13 authored Feb 12, 2024
2 parents 80a02fc + 641cf22 commit 3303c4c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
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 @@ -12,13 +12,13 @@ public class CreateSubOptions : BaseVcsOptions
[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

0 comments on commit 3303c4c

Please sign in to comment.