Skip to content

Commit

Permalink
(#146) Remove hard-coded values in create template
Browse files Browse the repository at this point in the history
Within the scriban templates used for creating release notes, there is a
hard-coded query string portion, which is used when linking to
milestones from the generated release notes.  When there was a single
VCS provider, i.e. GitHub, this was fine.  Now that we are introducing
another provider, we need to make this configurable.

This commit introduces a new method, GetMilestoneUrlQueryString(), which
each VCS provider will need to implement, to return the correct value.
In addition, the scriban template has been updated to make use of this,
as well as the model that is passed into the generation of the template.
  • Loading branch information
gep13 committed Sep 26, 2023
1 parent d19164b commit 400fbec
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/GitReleaseManager.Core/Provider/GitHubProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ public RateLimit GetRateLimit()
}
}

public string GetMilestoneQueryString()
{
return "closed=1";
}

private async Task ExecuteAsync(Func<Task> action)
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/GitReleaseManager.Core/Provider/IVcsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ public interface IVcsProvider
Task UpdateReleaseAsync(string owner, string repository, Release release);

RateLimit GetRateLimit();

string GetMilestoneQueryString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public async Task<string> BuildReleaseNotesAsync(string user, string repository,

var issuesDict = GetIssuesDict(issues);

var milestoneQueryString = _vcsProvider.GetMilestoneQueryString();

var templateModel = new
{
Issues = new
Expand All @@ -84,6 +86,7 @@ public async Task<string> BuildReleaseNotesAsync(string user, string repository,
{
Target = _targetMilestone,
Previous = previousMilestone,
QueryString = milestoneQueryString,
},
IssueLabels = issuesDict.Keys.ToList(),
};
Expand Down
4 changes: 2 additions & 2 deletions src/GitReleaseManager.Core/Templates/default/release-info.sbn
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{
if issues.count > 0
if commits.count > 0
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}) which resulted in [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?closed=1) being closed.
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}) which resulted in [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?{{ milestone.url_query_string }}) being closed.
{{ else
}}As part of this release we had [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?closed=1) closed.
}}As part of this release we had [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?{{ milestone.query_string }}) closed.
{{ end
else if commits.count > 0
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}).
Expand Down
3 changes: 3 additions & 0 deletions src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ private static void AcceptTest(int commits, Config config, Milestone milestone,
vcsProvider.GetMilestonesAsync(owner, repository, Arg.Any<ItemStateFilter>())
.Returns(Task.FromResult((IEnumerable<Milestone>)vcsService.Milestones));

vcsProvider.GetMilestoneQueryString()
.Returns("closed=1");

var builder = new ReleaseNotesBuilder(vcsProvider, logger, fileSystem, configuration, new TemplateFactory(fileSystem, configuration, TemplateKind.Create));
var notes = builder.BuildReleaseNotesAsync(owner, repository, milestone.Title, ReleaseTemplates.DEFAULT_NAME).Result;

Expand Down

0 comments on commit 400fbec

Please sign in to comment.