Skip to content

Commit 776b55c

Browse files
authored
Merge pull request #370 from gep13/feature/GH-112
2 parents ded0ef6 + a606dce commit 776b55c

File tree

7 files changed

+57
-2
lines changed

7 files changed

+57
-2
lines changed

docs/input/docs/commands/create.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ Title: Create
66
This is the main command of GitReleaseManager and it is used to create a draft
77
set of release notes based on a milestone, which has been set up in GitHub.
88

9-
There are two modes of operation when creating a Release. GitReleaseManager can
9+
There are three modes of operation when creating a Release. GitReleaseManager can
1010
take as an input the name of the milestone to generate the release notes from.
1111
Or, it can take as an input the name of a file which contains the release notes
1212
to include in the Release.
13+
Or, it can create a release that doesn't contain any release notes, i.e. it is empty.
1314

1415
## **Required Parameters**
1516

@@ -35,6 +36,8 @@ to include in the Release.
3536
logging to console.
3637
- `-t, --template`: The path to the file to be used as the template for the
3738
release notes.
39+
- `--allowEmpty`: Allow the creation of an empty set of release notes. In this
40+
mode, milestone and input file path will be ignored.
3841

3942
## **Template**
4043

@@ -61,3 +64,9 @@ gitreleasemanager.exe create -i c:\temp\releasenotes.md -n 0.1.0 --token fsdfsf6
6164

6265
gitreleasemanager.exe create --inputFilePath c:\temp\releasenotes.md --name 0.1.0 --token fsdfsf67657sdf5s7d5f --owner repoOwner --repository repo
6366
```
67+
68+
Use GitReleaseManager to create an empty release:
69+
70+
```bash
71+
gitreleasemanager.exe create -n 0.1.0 --token fsdfsf67657sdf5s7d5f -o repoOwner -r repo --allowEmpty
72+
```

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@ public void Setup()
2727
_command = new CreateCommand(_vcsService, _logger);
2828
}
2929

30+
public async Task Should_Create_Empty_Release()
31+
{
32+
var options = new CreateSubOptions
33+
{
34+
RepositoryOwner = "owner",
35+
RepositoryName = "repository",
36+
TargetCommitish = "target commitish",
37+
Prerelease = false,
38+
AllowEmpty = true,
39+
};
40+
41+
var releaseName = options.Name ?? options.Milestone;
42+
43+
_vcsService.CreateEmptyReleaseAsync(options.RepositoryOwner, options.RepositoryName, options.Name, options.TargetCommitish, options.Prerelease)
44+
.Returns(_release);
45+
46+
var result = await _command.Execute(options).ConfigureAwait(false);
47+
result.ShouldBe(0);
48+
49+
await _vcsService.Received(1).CreateEmptyReleaseAsync(options.RepositoryOwner, options.RepositoryName, releaseName, options.TargetCommitish, options.Prerelease).ConfigureAwait(false);
50+
_logger.Received(1).Information(Arg.Any<string>());
51+
_logger.Received(1).Information(Arg.Any<string>(), _release.HtmlUrl);
52+
_logger.Received(1).Verbose(Arg.Any<string>(), _release.Body);
53+
}
54+
3055
[TestCase(null, 2)]
3156
[TestCase("release", 1)]
3257
public async Task Should_Create_Release_From_Milestone(string name, int logVerboseCount)

src/GitReleaseManager.Core/Commands/CreateCommand.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ public async Task<int> Execute(CreateSubOptions options)
2222

2323
Release release;
2424

25-
if (!string.IsNullOrEmpty(options.Milestone))
25+
if (options.AllowEmpty)
26+
{
27+
_logger.Verbose("The AllowEmpty option has been passed, so an empty release will now be created");
28+
release = await _vcsService.CreateEmptyReleaseAsync(options.RepositoryOwner, options.RepositoryName, options.Name, options.TargetCommitish, options.Prerelease).ConfigureAwait(false);
29+
}
30+
else if (!string.IsNullOrEmpty(options.Milestone))
2631
{
2732
_logger.Verbose("Milestone {Milestone} was specified", options.Milestone);
2833
var releaseName = options.Name;

src/GitReleaseManager.Core/IVcsService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace GitReleaseManager.Core
66
{
77
public interface IVcsService
88
{
9+
Task<Release> CreateEmptyReleaseAsync(string owner, string repository, string name, string targetCommitish, bool prerelease);
10+
911
Task<Release> CreateReleaseFromMilestoneAsync(string owner, string repository, string milestone, string releaseName, string targetCommitish, IList<string> assets, bool prerelease, string templateFilePath);
1012

1113
Task<Release> CreateReleaseFromInputFileAsync(string owner, string repository, string name, string inputFilePath, string targetCommitish, IList<string> assets, bool prerelease);

src/GitReleaseManager.Core/Options/CreateSubOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ public class CreateSubOptions : BaseVcsOptions
2626

2727
[Option('e', "pre", Required = false, HelpText = "Creates the release as a pre-release.")]
2828
public bool Prerelease { get; set; }
29+
30+
[Option("allowEmpty", Required = false, HelpText = "Allow the creation of an empty set of release notes. In this mode, milestone and input file path will be ignored.")]
31+
public bool AllowEmpty { get; set; }
2932
}
3033
}

src/GitReleaseManager.Core/VcsService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public VcsService(IVcsProvider vcsProvider, ILogger logger, IReleaseNotesBuilder
3737
_configuration = configuration;
3838
}
3939

40+
public async Task<Release> CreateEmptyReleaseAsync(string owner, string repository, string name, string targetCommitish, bool prerelease)
41+
{
42+
var release = await CreateReleaseAsync(owner, repository, name, name, string.Empty, prerelease, targetCommitish, null).ConfigureAwait(false);
43+
return release;
44+
}
45+
4046
public async Task<Release> CreateReleaseFromMilestoneAsync(string owner, string repository, string milestone, string releaseName, string targetCommitish, IList<string> assets, bool prerelease, string templateFilePath)
4147
{
4248
var templatePath = ReleaseTemplates.DEFAULT_NAME;

src/GitReleaseManager.Tests/VcsServiceMock.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public VcsServiceMock()
2525

2626
public int NumberOfCommits { get; set; }
2727

28+
public Task<Release> CreateEmptyReleaseAsync(string owner, string repository, string name, string targetCommitish, bool prerelease)
29+
{
30+
throw new System.NotImplementedException();
31+
}
32+
2833
public Task<Release> CreateReleaseFromMilestoneAsync(string owner, string repository, string milestone, string releaseName, string targetCommitish, IList<string> assets, bool prerelease, string templateFilePath)
2934
{
3035
throw new System.NotImplementedException();

0 commit comments

Comments
 (0)