Skip to content

Commit 98dca9b

Browse files
committed
Merge branch 'release/0.17.0'
* 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
2 parents 58b6fb9 + 48b10b4 commit 98dca9b

14 files changed

+77
-12
lines changed

src/GitReleaseManager.Cli/GitReleaseManager.Cli.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
<PrivateAssets>all</PrivateAssets>
2525
</PackageReference>
26-
<PackageReference Include="Octokit" Version="9.0.0" />
26+
<PackageReference Include="Octokit" Version="10.0.0" />
2727
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
2828
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" PrivateAssets="All" />
2929
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />

src/GitReleaseManager.Cli/Logging/LogConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private static void CreateConsoleFullLogger(LoggerConfiguration config, string c
4343
.Filter.ByExcluding((logEvent) => !options.Verbose && logEvent.Level == LogEventLevel.Verbose)
4444
.WriteTo.Console(
4545
outputTemplate: consoleTemplate,
46-
standardErrorFromLevel: LogEventLevel.Warning,
46+
standardErrorFromLevel: options.IsCISystem ? LogEventLevel.Error : LogEventLevel.Warning,
4747
theme: consoleTheme));
4848
}
4949

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

Lines changed: 24 additions & 0 deletions
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.Tests/GitReleaseManager.Core.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<PackageReference Include="NSubstitute" Version="5.1.0" />
2727
<PackageReference Include="NUnit" Version="3.14.0" />
2828
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
29-
<PackageReference Include="Octokit" Version="9.0.0" />
29+
<PackageReference Include="Octokit" Version="10.0.0" />
3030
<PackageReference Include="Shouldly" Version="4.2.1" />
3131
</ItemGroup>
3232
</Project>

src/GitReleaseManager.Core/Commands/CreateCommand.cs

Lines changed: 6 additions & 0 deletions
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/GitReleaseManager.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<PrivateAssets>all</PrivateAssets>
2525
</PackageReference>
2626
<PackageReference Include="NGitLab" Version="6.39.0" />
27-
<PackageReference Include="Octokit" Version="9.0.0" />
27+
<PackageReference Include="Octokit" Version="10.0.0" />
2828
<PackageReference Include="Scriban" Version="5.9.0" />
2929
<PackageReference Include="seriloganalyzer" Version="0.15.0" />
3030
<PackageReference Include="YamlDotNet" Version="13.7.1" />

src/GitReleaseManager.Core/Model/Issue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public sealed class Issue
66
{
77
public string Title { get; set; }
88

9-
public int InternalNumber { get; set; }
9+
public long InternalNumber { get; set; }
1010

1111
public int PublicNumber { get; set; }
1212

src/GitReleaseManager.Core/Options/BaseSubOptions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
using System;
12
using CommandLine;
23

34
namespace GitReleaseManager.Core.Options
45
{
56
public abstract class BaseSubOptions
67
{
8+
protected BaseSubOptions()
9+
{
10+
var ciEnvironmentVariable = Environment.GetEnvironmentVariable("CI");
11+
12+
bool isCiSystem;
13+
if (!string.IsNullOrEmpty(ciEnvironmentVariable) && bool.TryParse(ciEnvironmentVariable, out isCiSystem))
14+
{
15+
IsCISystem = isCiSystem;
16+
}
17+
}
18+
719
[Option("debug", HelpText = "Enable debugging console output")]
820
public bool Debug { get; set; }
921

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

1931
[Option("verbose", HelpText = "Enable verbose console output")]
2032
public bool Verbose { get; set; }
33+
34+
[Option("ci", HelpText = "Configure GitReleaseManager to be compatible with CI systems")]
35+
public bool IsCISystem { get; set; }
2136
}
2237
}

src/GitReleaseManager.Core/Options/CreateSubOptions.cs

Lines changed: 2 additions & 2 deletions
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'")]

src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ public async Task<string> BuildReleaseNotesAsync(string user, string repository,
101101
private Dictionary<string, List<Issue>> GetIssuesDict(List<Issue> issues)
102102
{
103103
var issueLabels = _configuration.IssueLabelsInclude;
104+
var excludedIssueLabels = _configuration.IssueLabelsExclude;
105+
104106
var issuesByLabel = issues
107+
.Where(o => !o.Labels.Any(l => excludedIssueLabels.Any(eil => string.Equals(eil, l.Name, StringComparison.OrdinalIgnoreCase))))
105108
.SelectMany(o => o.Labels, (issue, label) => new { Label = label.Name, Issue = issue })
106109
.Where(o => issueLabels.Any(il => string.Equals(il, o.Label, StringComparison.OrdinalIgnoreCase)))
107110
.GroupBy(o => o.Label, o => o.Issue)
@@ -136,16 +139,21 @@ private string GetValidLabel(string label, int issuesCount)
136139
foreach (var issue in issues)
137140
{
138141
var includedIssuesCount = 0;
139-
var excludedIssuesCount = 0;
142+
var isExcluded = false;
140143

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

145-
excludedIssuesCount += _configuration.IssueLabelsExclude.Count(issueToExclude => issueLabel.Name.ToUpperInvariant() == issueToExclude.ToUpperInvariant());
148+
isExcluded = isExcluded || _configuration.IssueLabelsExclude.Any(issueToExclude => issueLabel.Name.ToUpperInvariant() == issueToExclude.ToUpperInvariant());
149+
}
150+
151+
if (isExcluded)
152+
{
153+
continue;
146154
}
147155

148-
if (includedIssuesCount + excludedIssuesCount != 1)
156+
if (includedIssuesCount != 1)
149157
{
150158
var allIssueLabels = _configuration.IssueLabelsInclude.Union(_configuration.IssueLabelsExclude).ToList();
151159
var allIssuesExceptLast = allIssueLabels.Take(allIssueLabels.Count - 1);

0 commit comments

Comments
 (0)