Skip to content

Commit

Permalink
Merge branch 'release/0.17.0'
Browse files Browse the repository at this point in the history
* release/0.17.0:
  (#578) Make the issue ID a long
  (GH-578) Bump Octokit to 10.0.0 to fix oversized ints
  (#574) Exclude all issues with label
  (#476) Add validation of input file path handler
  (#439) Add option to disable warning to stderr
  • Loading branch information
gep13 committed Mar 9, 2024
2 parents 58b6fb9 + 48b10b4 commit 98dca9b
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/GitReleaseManager.Cli/GitReleaseManager.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Octokit" Version="9.0.0" />
<PackageReference Include="Octokit" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/GitReleaseManager.Cli/Logging/LogConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static void CreateConsoleFullLogger(LoggerConfiguration config, string c
.Filter.ByExcluding((logEvent) => !options.Verbose && logEvent.Level == LogEventLevel.Verbose)
.WriteTo.Console(
outputTemplate: consoleTemplate,
standardErrorFromLevel: LogEventLevel.Warning,
standardErrorFromLevel: options.IsCISystem ? LogEventLevel.Error : LogEventLevel.Warning,
theme: consoleTheme));
}

Expand Down
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Octokit" Version="9.0.0" />
<PackageReference Include="Octokit" Version="10.0.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
</ItemGroup>
</Project>
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
2 changes: 1 addition & 1 deletion src/GitReleaseManager.Core/GitReleaseManager.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NGitLab" Version="6.39.0" />
<PackageReference Include="Octokit" Version="9.0.0" />
<PackageReference Include="Octokit" Version="10.0.0" />
<PackageReference Include="Scriban" Version="5.9.0" />
<PackageReference Include="seriloganalyzer" Version="0.15.0" />
<PackageReference Include="YamlDotNet" Version="13.7.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/GitReleaseManager.Core/Model/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public sealed class Issue
{
public string Title { get; set; }

public int InternalNumber { get; set; }
public long InternalNumber { get; set; }

public int PublicNumber { get; set; }

Expand Down
15 changes: 15 additions & 0 deletions src/GitReleaseManager.Core/Options/BaseSubOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
using System;
using CommandLine;

namespace GitReleaseManager.Core.Options
{
public abstract class BaseSubOptions
{
protected BaseSubOptions()
{
var ciEnvironmentVariable = Environment.GetEnvironmentVariable("CI");

bool isCiSystem;
if (!string.IsNullOrEmpty(ciEnvironmentVariable) && bool.TryParse(ciEnvironmentVariable, out isCiSystem))
{
IsCISystem = isCiSystem;
}
}

[Option("debug", HelpText = "Enable debugging console output")]
public bool Debug { get; set; }

Expand All @@ -18,5 +30,8 @@ public abstract class BaseSubOptions

[Option("verbose", HelpText = "Enable verbose console output")]
public bool Verbose { get; set; }

[Option("ci", HelpText = "Configure GitReleaseManager to be compatible with CI systems")]
public bool IsCISystem { get; set; }
}
}
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
14 changes: 11 additions & 3 deletions src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ public async Task<string> BuildReleaseNotesAsync(string user, string repository,
private Dictionary<string, List<Issue>> GetIssuesDict(List<Issue> issues)
{
var issueLabels = _configuration.IssueLabelsInclude;
var excludedIssueLabels = _configuration.IssueLabelsExclude;

var issuesByLabel = issues
.Where(o => !o.Labels.Any(l => excludedIssueLabels.Any(eil => string.Equals(eil, l.Name, StringComparison.OrdinalIgnoreCase))))
.SelectMany(o => o.Labels, (issue, label) => new { Label = label.Name, Issue = issue })
.Where(o => issueLabels.Any(il => string.Equals(il, o.Label, StringComparison.OrdinalIgnoreCase)))
.GroupBy(o => o.Label, o => o.Issue)
Expand Down Expand Up @@ -136,16 +139,21 @@ private string GetValidLabel(string label, int issuesCount)
foreach (var issue in issues)
{
var includedIssuesCount = 0;
var excludedIssuesCount = 0;
var isExcluded = false;

foreach (var issueLabel in issue.Labels)
{
includedIssuesCount += _configuration.IssueLabelsInclude.Count(issueToInclude => issueLabel.Name.ToUpperInvariant() == issueToInclude.ToUpperInvariant());

excludedIssuesCount += _configuration.IssueLabelsExclude.Count(issueToExclude => issueLabel.Name.ToUpperInvariant() == issueToExclude.ToUpperInvariant());
isExcluded = isExcluded || _configuration.IssueLabelsExclude.Any(issueToExclude => issueLabel.Name.ToUpperInvariant() == issueToExclude.ToUpperInvariant());
}

if (isExcluded)
{
continue;
}

if (includedIssuesCount + excludedIssuesCount != 1)
if (includedIssuesCount != 1)
{
var allIssueLabels = _configuration.IssueLabelsInclude.Union(_configuration.IssueLabelsExclude).ToList();
var allIssuesExceptLast = allIssueLabels.Take(allIssueLabels.Count - 1);
Expand Down
2 changes: 1 addition & 1 deletion src/GitReleaseManager.Tests/GitReleaseManager.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Octokit" Version="9.0.0" />
<PackageReference Include="Octokit" Version="10.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
As part of this release we had [10 commits](https://github.com/TestUser/FakeRepository/commits/1.2.3) which resulted in [2 issues](https://github.com/gep13/FakeRepository/issues?q=milestone%3A1.2.3?closed=1) being closed.

__Feature__

- [__#3__](http://example.com/3) Issue 3
7 changes: 7 additions & 0 deletions src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ public void CorrectlyExcludeIssues()
Assert.True(true); // Just to make sonarlint happy
}

[Test]
public void CorrectlyExcludeIssuesWhenBothIncludeAndExcludeLabelIsSet()
{
AcceptTest(10, CreateIssue(5, "Improvement", "Build"), CreateIssue(3, "Feature"));
Assert.True(true);
}

private static void AcceptTest(int commits, params Issue[] issues)
{
AcceptTest(commits, null, null, issues);
Expand Down
2 changes: 1 addition & 1 deletion src/GitReleaseManager.Tool/GitReleaseManager.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NGitLab" Version="6.39.0" />
<PackageReference Include="Octokit" Version="9.0.0" />
<PackageReference Include="Octokit" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
Expand Down

0 comments on commit 98dca9b

Please sign in to comment.