Skip to content

Commit 89dce6a

Browse files
Jerichogep13
authored andcommitted
(#495) Make use of new empty Scriban template
When creating a release a new template is used when a milestone does not have any associated issues AND the developer has indicated they want to allow milestones without issues. The decision on which template to use has had to be moved. It can still be overridden when required, but the calculated value is based on how many issues have been found, whether to include contributors, etc.
1 parent c2e0f3a commit 89dce6a

File tree

8 files changed

+77
-19
lines changed

8 files changed

+77
-19
lines changed

src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public ReleaseNotesBuilder(IVcsProvider vcsProvider, ILogger logger, IFileSystem
3535
_templateFactory = templateFactory;
3636
}
3737

38-
public async Task<string> BuildReleaseNotesAsync(string user, string repository, string milestoneTitle, string template)
38+
public async Task<string> BuildReleaseNotesAsync(string user, string repository, string milestoneTitle, string customTemplate)
3939
{
4040
_user = user;
4141
_repository = repository;
@@ -64,6 +64,25 @@ public async Task<string> BuildReleaseNotesAsync(string user, string repository,
6464
throw new InvalidOperationException(logMessage);
6565
}
6666

67+
// By default we use the custom template, if it was provided.
68+
// Otherwise, we determine which template we should use.
69+
var template = customTemplate;
70+
if (string.IsNullOrWhiteSpace(template))
71+
{
72+
if (issues.Count == 0)
73+
{
74+
template = ReleaseTemplates.NO_ISSUES_NAME;
75+
}
76+
else if (_configuration.Create.IncludeContributors)
77+
{
78+
template = ReleaseTemplates.CONTRIBUTORS_NAME;
79+
}
80+
else
81+
{
82+
template = ReleaseTemplates.DEFAULT_NAME;
83+
}
84+
}
85+
6786
var commitsLink = _vcsProvider.GetCommitsUrl(_user, _repository, _targetMilestone?.Title, previousMilestone?.Title);
6887

6988
var issuesDict = GetIssuesDict(issues);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{ if config.create.include_footer }}
2+
3+
### {{ config.create.footer_heading }}
4+
5+
{{ if config.create.milestone_replace_text
6+
replace_milestone_title config.create.footer_content config.create.milestone_replace_text milestone.target.title
7+
else
8+
config.create.footer_content
9+
end
10+
end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{-
2+
include 'release-info'
3+
if milestone.target.description
4+
include 'milestone'
5+
end
6+
include 'issues' | string.rstrip
7+
if template_kind == "CREATE"
8+
include 'create/footer'
9+
end
10+
~}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
This release had no issues associated with it.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
{{ milestone.target.description }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{
2+
if commits.count > 0
3+
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}).
4+
{{ end -}}

src/GitReleaseManager.Core/VcsService.cs

+2-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using GitReleaseManager.Core.Model;
1414
using GitReleaseManager.Core.Provider;
1515
using GitReleaseManager.Core.ReleaseNotes;
16-
using GitReleaseManager.Core.Templates;
1716
using Serilog;
1817

1918
namespace GitReleaseManager.Core
@@ -46,16 +45,7 @@ public async Task<Release> CreateEmptyReleaseAsync(string owner, string reposito
4645

4746
public async Task<Release> CreateReleaseFromMilestoneAsync(string owner, string repository, string milestone, string releaseName, string targetCommitish, IList<string> assets, bool prerelease, string templateFilePath)
4847
{
49-
var templatePath = _configuration.Create.IncludeContributors
50-
? ReleaseTemplates.CONTRIBUTORS_NAME
51-
: ReleaseTemplates.DEFAULT_NAME;
52-
53-
if (!string.IsNullOrWhiteSpace(templateFilePath))
54-
{
55-
templatePath = templateFilePath;
56-
}
57-
58-
var releaseNotes = await _releaseNotesBuilder.BuildReleaseNotesAsync(owner, repository, milestone, templatePath).ConfigureAwait(false);
48+
var releaseNotes = await _releaseNotesBuilder.BuildReleaseNotesAsync(owner, repository, milestone, templateFilePath).ConfigureAwait(false);
5949
var release = await CreateReleaseAsync(owner, repository, releaseName, milestone, releaseNotes, prerelease, targetCommitish, assets).ConfigureAwait(false);
6050

6151
return release;
@@ -67,7 +57,7 @@ public async Task<Release> CreateReleaseFromInputFileAsync(string owner, string
6757

6858
_logger.Verbose("Reading release notes from: '{FilePath}'", inputFilePath);
6959

70-
var releaseNotes = File.ReadAllText(inputFilePath);
60+
var releaseNotes = await File.ReadAllTextAsync(inputFilePath).ConfigureAwait(false);
7161
var release = await CreateReleaseAsync(owner, repository, name, name, releaseNotes, prerelease, targetCommitish, assets).ConfigureAwait(false);
7262

7363
return release;

src/GitReleaseManager.IntegrationTests/ReleaseNotesBuilderIntegrationTests.cs

+27-6
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,38 @@ public async Task SingleMilestone()
7474
var configuration = ConfigurationProvider.Provide(currentDirectory, fileSystem);
7575
configuration.IssueLabelsExclude.Add("Internal Refactoring"); // This is necessary to generate the release notes for GitReleaseManager version 0.12.0
7676

77-
// Indicate whether you want to include the 'Contributors' section in the release notes
77+
// Indicate that we want to include the 'Contributors' section in the release notes
7878
configuration.Create.IncludeContributors = true;
7979

80-
// Pick the template based on whether you want to include the 'Contributors' section in the release notes
81-
var templatePath = configuration.Create.IncludeContributors
82-
? ReleaseTemplates.CONTRIBUTORS_NAME
83-
: ReleaseTemplates.DEFAULT_NAME;
80+
var vcsProvider = new GitHubProvider(_gitHubClient, _mapper, _graphQlClient);
81+
var releaseNotesBuilder = new ReleaseNotesBuilder(vcsProvider, _logger, fileSystem, configuration, new TemplateFactory(fileSystem, configuration, TemplateKind.Create));
82+
var result = await releaseNotesBuilder.BuildReleaseNotesAsync("GitTools", "GitReleaseManager", "0.12.0", string.Empty).ConfigureAwait(false); // 0.12.0 contains a mix of issues and PRs
83+
Debug.WriteLine(result);
84+
ClipBoardHelper.SetClipboard(result);
85+
}
86+
}
87+
88+
[Test]
89+
[Explicit]
90+
public async Task MilestoneWithoutIssues()
91+
{
92+
if (string.IsNullOrWhiteSpace(_token))
93+
{
94+
Assert.Inconclusive("Unable to locate credentials for accessing GitHub API");
95+
}
96+
else
97+
{
98+
var fileSystem = new FileSystem(new CreateSubOptions());
99+
var currentDirectory = Environment.CurrentDirectory;
100+
101+
var configuration = ConfigurationProvider.Provide(currentDirectory, fileSystem);
102+
103+
// Indicate that we allow milestones without issues
104+
configuration.Create.AllowMilestonesWithoutIssues = true;
84105

85106
var vcsProvider = new GitHubProvider(_gitHubClient, _mapper, _graphQlClient);
86107
var releaseNotesBuilder = new ReleaseNotesBuilder(vcsProvider, _logger, fileSystem, configuration, new TemplateFactory(fileSystem, configuration, TemplateKind.Create));
87-
var result = await releaseNotesBuilder.BuildReleaseNotesAsync("GitTools", "GitReleaseManager", "0.12.0", templatePath).ConfigureAwait(false); // 0.12.0 contains a mix of issues and PRs
108+
var result = await releaseNotesBuilder.BuildReleaseNotesAsync("jericho", "_testing", "0.1.0", string.Empty).ConfigureAwait(false); // There are no issues associated with milestone 0.1.0 in my testing repo.
88109
Debug.WriteLine(result);
89110
ClipBoardHelper.SetClipboard(result);
90111
}

0 commit comments

Comments
 (0)