Skip to content

Commit

Permalink
Merge branch 'develop' into release/0.12.0
Browse files Browse the repository at this point in the history
* develop:
  (build) Remove error action preference from build script
  Bump YamlDotNet from 11.0.1 to 11.1.1 in /src
  (#112) Updated docs with new command option
  (#112) Add new method for creating empty release
  • Loading branch information
gep13 committed May 10, 2021
2 parents 6a19b8b + 8f3f7f6 commit 7f1a9ae
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 6 deletions.
4 changes: 1 addition & 3 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
$ErrorActionPreference = 'Stop'

$SCRIPT_NAME = "recipe.cake"
$SCRIPT_NAME = "recipe.cake"

Write-Host "Restoring .NET Core tools"
dotnet tool restore
Expand Down
11 changes: 10 additions & 1 deletion docs/input/docs/commands/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Title: Create
This is the main command of GitReleaseManager and it is used to create a draft
set of release notes based on a milestone, which has been set up in GitHub.

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

## **Required Parameters**

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

## **Template**

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

gitreleasemanager.exe create --inputFilePath c:\temp\releasenotes.md --name 0.1.0 --token fsdfsf67657sdf5s7d5f --owner repoOwner --repository repo
```

Use GitReleaseManager to create an empty release:

```bash
gitreleasemanager.exe create -n 0.1.0 --token fsdfsf67657sdf5s7d5f -o repoOwner -r repo --allowEmpty
```
25 changes: 25 additions & 0 deletions src/GitReleaseManager.Core.Tests/Commands/CreateCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ public void Setup()
_command = new CreateCommand(_vcsService, _logger);
}

public async Task Should_Create_Empty_Release()
{
var options = new CreateSubOptions
{
RepositoryOwner = "owner",
RepositoryName = "repository",
TargetCommitish = "target commitish",
Prerelease = false,
AllowEmpty = true,
};

var releaseName = options.Name ?? options.Milestone;

_vcsService.CreateEmptyReleaseAsync(options.RepositoryOwner, options.RepositoryName, options.Name, options.TargetCommitish, options.Prerelease)
.Returns(_release);

var result = await _command.Execute(options).ConfigureAwait(false);
result.ShouldBe(0);

await _vcsService.Received(1).CreateEmptyReleaseAsync(options.RepositoryOwner, options.RepositoryName, releaseName, options.TargetCommitish, options.Prerelease).ConfigureAwait(false);
_logger.Received(1).Information(Arg.Any<string>());
_logger.Received(1).Information(Arg.Any<string>(), _release.HtmlUrl);
_logger.Received(1).Verbose(Arg.Any<string>(), _release.Body);
}

[TestCase(null, 2)]
[TestCase("release", 1)]
public async Task Should_Create_Release_From_Milestone(string name, int logVerboseCount)
Expand Down
7 changes: 6 additions & 1 deletion src/GitReleaseManager.Core/Commands/CreateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ public async Task<int> Execute(CreateSubOptions options)

Release release;

if (!string.IsNullOrEmpty(options.Milestone))
if (options.AllowEmpty)
{
_logger.Verbose("The AllowEmpty option has been passed, so an empty release will now be created");
release = await _vcsService.CreateEmptyReleaseAsync(options.RepositoryOwner, options.RepositoryName, options.Name, options.TargetCommitish, options.Prerelease).ConfigureAwait(false);
}
else if (!string.IsNullOrEmpty(options.Milestone))
{
_logger.Verbose("Milestone {Milestone} was specified", options.Milestone);
var releaseName = options.Name;
Expand Down
2 changes: 1 addition & 1 deletion src/GitReleaseManager.Core/GitReleaseManager.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PackageReference Include="Octokit" Version="0.50.0" />
<PackageReference Include="Scriban" Version="3.6.0" />
<PackageReference Include="seriloganalyzer" Version="0.15.0" />
<PackageReference Include="YamlDotNet" Version="11.0.1" />
<PackageReference Include="YamlDotNet" Version="11.1.1" />
<PackageReference Include="AutoMapper" Version="10.1.1" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/GitReleaseManager.Core/IVcsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace GitReleaseManager.Core
{
public interface IVcsService
{
Task<Release> CreateEmptyReleaseAsync(string owner, string repository, string name, string targetCommitish, bool prerelease);

Task<Release> CreateReleaseFromMilestoneAsync(string owner, string repository, string milestone, string releaseName, string targetCommitish, IList<string> assets, bool prerelease, string templateFilePath);

Task<Release> CreateReleaseFromInputFileAsync(string owner, string repository, string name, string inputFilePath, string targetCommitish, IList<string> assets, bool prerelease);
Expand Down
3 changes: 3 additions & 0 deletions src/GitReleaseManager.Core/Options/CreateSubOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ public class CreateSubOptions : BaseVcsOptions

[Option('e', "pre", Required = false, HelpText = "Creates the release as a pre-release.")]
public bool Prerelease { get; set; }

[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.")]
public bool AllowEmpty { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/GitReleaseManager.Core/VcsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public VcsService(IVcsProvider vcsProvider, ILogger logger, IReleaseNotesBuilder
_configuration = configuration;
}

public async Task<Release> CreateEmptyReleaseAsync(string owner, string repository, string name, string targetCommitish, bool prerelease)
{
var release = await CreateReleaseAsync(owner, repository, name, name, string.Empty, prerelease, targetCommitish, null).ConfigureAwait(false);
return release;
}

public async Task<Release> CreateReleaseFromMilestoneAsync(string owner, string repository, string milestone, string releaseName, string targetCommitish, IList<string> assets, bool prerelease, string templateFilePath)
{
var templatePath = ReleaseTemplates.DEFAULT_NAME;
Expand Down
5 changes: 5 additions & 0 deletions src/GitReleaseManager.Tests/VcsServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public VcsServiceMock()

public int NumberOfCommits { get; set; }

public Task<Release> CreateEmptyReleaseAsync(string owner, string repository, string name, string targetCommitish, bool prerelease)
{
throw new System.NotImplementedException();
}

public Task<Release> CreateReleaseFromMilestoneAsync(string owner, string repository, string milestone, string releaseName, string targetCommitish, IList<string> assets, bool prerelease, string templateFilePath)
{
throw new System.NotImplementedException();
Expand Down

0 comments on commit 7f1a9ae

Please sign in to comment.