Skip to content

Commit 3303c4c

Browse files
authored
Merge pull request GitTools#577 from AdmiringWorm/AdmiringWorm/issue476
(GitTools#476) Add validation of input file path handler
2 parents 80a02fc + 641cf22 commit 3303c4c

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/GitReleaseManager.Core.Tests/Commands/CreateCommandTests.cs

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Threading.Tasks;
34
using GitReleaseManager.Core.Commands;
@@ -106,5 +107,28 @@ public async Task Should_Create_Release_From_InputFile()
106107
_logger.Received(1).Information(Arg.Any<string>(), _release.HtmlUrl);
107108
_logger.Received(1).Verbose(Arg.Any<string>(), _release.Body);
108109
}
110+
111+
[Test]
112+
public async Task Throws_Exception_When_Both_Milestone_And_Input_File_Specified()
113+
{
114+
var options = new CreateSubOptions
115+
{
116+
RepositoryName = "repository",
117+
RepositoryOwner = "owner",
118+
InputFilePath = "file.path",
119+
TargetCommitish = "target commitish",
120+
AssetPaths = new List<string>(),
121+
Prerelease = false,
122+
Milestone = "0.5.0",
123+
};
124+
125+
Func<Task> action = async () => await _command.ExecuteAsync(options).ConfigureAwait(false);
126+
127+
var ex = await action.ShouldThrowAsync<InvalidOperationException>().ConfigureAwait(false);
128+
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!");
129+
130+
_vcsService.ReceivedCalls().ShouldBeEmpty();
131+
_logger.ReceivedCalls().ShouldHaveSingleItem();
132+
}
109133
}
110134
}

src/GitReleaseManager.Core/Commands/CreateCommand.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Threading.Tasks;
23
using GitReleaseManager.Core.Model;
34
using GitReleaseManager.Core.Options;
@@ -29,6 +30,11 @@ public async Task<int> ExecuteAsync(CreateSubOptions options)
2930
}
3031
else if (!string.IsNullOrEmpty(options.Milestone))
3132
{
33+
if (!string.IsNullOrWhiteSpace(options.InputFilePath))
34+
{
35+
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!");
36+
}
37+
3238
_logger.Verbose("Milestone {Milestone} was specified", options.Milestone);
3339
var releaseName = options.Name;
3440

src/GitReleaseManager.Core/Options/CreateSubOptions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ public class CreateSubOptions : BaseVcsOptions
1212
[Option('c', "targetcommitish", HelpText = "The commit to tag. Can be a branch or SHA. Defaults to repository's default branch.", Required = false)]
1313
public string TargetCommitish { get; set; }
1414

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

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

21-
[Option('i', "inputFilePath", HelpText = "The path to the file to be used as the content of the release notes.", Required = false)]
21+
[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)]
2222
public string InputFilePath { get; set; }
2323

2424
[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'")]

0 commit comments

Comments
 (0)