Skip to content

Commit 46b7762

Browse files
committed
(#146) Remove hard-coded values in create template
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.
1 parent daf2b7c commit 46b7762

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

src/GitReleaseManager.Core/Provider/GitHubProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ public RateLimit GetRateLimit()
345345
}
346346
}
347347

348+
public string GetMilestoneQueryString()
349+
{
350+
return "closed=1";
351+
}
352+
348353
private async Task ExecuteAsync(Func<Task> action)
349354
{
350355
try

src/GitReleaseManager.Core/Provider/IVcsProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@ public interface IVcsProvider
4545
Task UpdateReleaseAsync(string owner, string repository, Release release);
4646

4747
RateLimit GetRateLimit();
48+
49+
string GetMilestoneQueryString();
4850
}
4951
}

src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public async Task<string> BuildReleaseNotesAsync(string user, string repository,
6868

6969
var issuesDict = GetIssuesDict(issues);
7070

71+
var milestoneQueryString = _vcsProvider.GetMilestoneQueryString();
72+
7173
var templateModel = new
7274
{
7375
Issues = new
@@ -84,6 +86,7 @@ public async Task<string> BuildReleaseNotesAsync(string user, string repository,
8486
{
8587
Target = _targetMilestone,
8688
Previous = previousMilestone,
89+
QueryString = milestoneQueryString,
8790
},
8891
IssueLabels = issuesDict.Keys.ToList(),
8992
};

src/GitReleaseManager.Core/Templates/default/release-info.sbn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{{
22
if issues.count > 0
33
if commits.count > 0
4-
}}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.
4+
}}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.query_string }}) being closed.
55
{{ else
6-
}}As part of this release we had [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?closed=1) closed.
6+
}}As part of this release we had [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?{{ milestone.query_string }}) closed.
77
{{ end
88
else if commits.count > 0
99
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}).

src/GitReleaseManager.Tests/ReleaseNotesBuilderTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ private static void AcceptTest(int commits, Config config, Milestone milestone,
237237
vcsProvider.GetMilestonesAsync(owner, repository, Arg.Any<ItemStateFilter>())
238238
.Returns(Task.FromResult((IEnumerable<Milestone>)vcsService.Milestones));
239239

240+
vcsProvider.GetMilestoneQueryString()
241+
.Returns("closed=1");
242+
240243
var builder = new ReleaseNotesBuilder(vcsProvider, logger, fileSystem, configuration, new TemplateFactory(fileSystem, configuration, TemplateKind.Create));
241244
var notes = builder.BuildReleaseNotesAsync(owner, repository, milestone.Title, ReleaseTemplates.DEFAULT_NAME).Result;
242245

0 commit comments

Comments
 (0)