This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support custom templates for commits + PRs
This commit introduces mustache templates for commit messages, and pull request titles and bodies. The design consists of templates with predefined properties. A custom template can be provided. Stubble has been chosen as the template renderer. It is possible to define additional context for the templates, this also includes delegates. These can be provided as the value of a "_delegates" key in the context.
- Loading branch information
1 parent
18d6cdb
commit 1dd5f23
Showing
65 changed files
with
2,553 additions
and
1,034 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
NuKeeper.Abstractions/CollaborationModels/CommitUpdateMessageTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using NuKeeper.Abstractions.CollaborationPlatform; | ||
|
||
namespace NuKeeper.Abstractions.CollaborationModels | ||
{ | ||
public class CommitUpdateMessageTemplate : UpdateMessageTemplate | ||
{ | ||
private const string CommitEmoji = "📦"; | ||
|
||
public CommitUpdateMessageTemplate() | ||
: base(new StubbleTemplateRenderer()) | ||
{ | ||
PackageEmoji = CommitEmoji; | ||
} | ||
|
||
public static string DefaultTemplate { get; } = | ||
"{{#packageEmoji}}{{packageEmoji}} {{/packageEmoji}}Automatic update of {{^multipleChanges}}{{#packages}}{{Name}} to {{Version}}{{/packages}}{{/multipleChanges}}{{#multipleChanges}}{{packageCount}} packages{{/multipleChanges}}"; | ||
|
||
public override string Value | ||
{ | ||
get | ||
{ | ||
return CustomTemplate ?? DefaultTemplate; | ||
} | ||
} | ||
|
||
public string CustomTemplate { get; set; } | ||
|
||
public object PackageEmoji | ||
{ | ||
get | ||
{ | ||
Context.TryGetValue(Constants.Template.PackageEmoji, out var packageEmoji); | ||
return packageEmoji; | ||
} | ||
set | ||
{ | ||
Context[Constants.Template.PackageEmoji] = value; | ||
} | ||
} | ||
|
||
public override void Clear() | ||
{ | ||
base.Clear(); | ||
PackageEmoji = CommitEmoji; | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
NuKeeper.Abstractions/CollaborationModels/DefaultPullRequestBodyTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using NuKeeper.Abstractions.CollaborationPlatform; | ||
|
||
namespace NuKeeper.Abstractions.CollaborationModels | ||
{ | ||
public class DefaultPullRequestBodyTemplate : UpdateMessageTemplate | ||
{ | ||
public DefaultPullRequestBodyTemplate() | ||
: base(new StubbleTemplateRenderer()) { } | ||
|
||
public static string DefaultTemplate { get; } = | ||
@"{{#multipleChanges}}{{packageCount}} packages were updated in {{projectsUpdated}} project{{#multipleProjects}}s{{/multipleProjects}}: | ||
{{#packages}}`{{Name}}`{{^Last}}, {{/Last}}{{/packages}} | ||
<details> | ||
<summary>Details of updated packages</summary> | ||
{{/multipleChanges}} | ||
{{#packages}}NuKeeper has generated a {{ActualChange}} update of `{{Name}}` to `{{Version}}`{{^MultipleUpdates}} from `{{FromVersion}}`{{/MultipleUpdates}} | ||
{{#MultipleUpdates}}{{ProjectsUpdated}} versions of `{{Name}}` were found in use: {{#Updates}}`{{FromVersion}}`{{^Last}}, {{/Last}}{{/Updates}}{{/MultipleUpdates}} | ||
{{#Publication}}`{{Name}} {{Version}}` was published at `{{Date}}`, {{Ago}}{{/Publication}} | ||
{{#LatestVersion}}There is also a higher version, `{{Name}} {{Version}}`{{#Publication}} published at `{{Date}}`, {{Ago}}{{/Publication}}, but this was not applied as only `{{AllowedChange}}` version changes are allowed. | ||
{{/LatestVersion}} | ||
{{ProjectsUpdated}} project update{{#MultipleProjectsUpdated}}s{{/MultipleProjectsUpdated}}: | ||
{{#Updates}} | ||
Updated `{{SourceFilePath}}` to `{{Name}}` `{{ToVersion}}` from `{{FromVersion}}` | ||
{{/Updates}} | ||
{{#IsFromNuget}} | ||
[{{Name}} {{Version}} on NuGet.org]({{Url}}) | ||
{{/IsFromNuget}} | ||
{{/packages}} | ||
{{#multipleChanges}} | ||
</details> | ||
{{/multipleChanges}} | ||
{{#footer}} | ||
{{WarningMessage}} | ||
**NuKeeper**: {{NuKeeperUrl}} | ||
{{/footer}} | ||
"; | ||
|
||
public string CustomTemplate { get; set; } | ||
|
||
public override string Value => CustomTemplate ?? DefaultTemplate; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
NuKeeper.Abstractions/CollaborationModels/DefaultPullRequestTitleTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using NuKeeper.Abstractions.CollaborationPlatform; | ||
|
||
namespace NuKeeper.Abstractions.CollaborationModels | ||
{ | ||
public class DefaultPullRequestTitleTemplate : UpdateMessageTemplate | ||
{ | ||
public DefaultPullRequestTitleTemplate() | ||
: base(new StubbleTemplateRenderer()) { } | ||
|
||
public static string DefaultTemplate { get; } = | ||
"Automatic update of {{^multipleChanges}}{{#packages}}{{Name}} to {{Version}}{{/packages}}{{/multipleChanges}}{{#multipleChanges}}{{packageCount}} packages{{/multipleChanges}}"; | ||
|
||
public string CustomTemplate { get; set; } | ||
|
||
public override string Value => CustomTemplate ?? DefaultTemplate; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
NuKeeper.Abstractions/CollaborationModels/FooterTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace NuKeeper.Abstractions.CollaborationModels | ||
{ | ||
public class FooterTemplate | ||
{ | ||
#pragma warning disable CA1056 // Uri properties should not be strings | ||
public string NuKeeperUrl { get; set; } | ||
#pragma warning restore CA1056 // Uri properties should not be strings | ||
public string WarningMessage { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
NuKeeper.Abstractions/CollaborationModels/LatestPackageTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace NuKeeper.Abstractions.CollaborationModels | ||
{ | ||
public class LatestPackageTemplate | ||
{ | ||
public string Version { get; set; } | ||
#pragma warning disable CA1056 // Uri properties should not be strings | ||
public string Url { get; set; } | ||
#pragma warning restore CA1056 // Uri properties should not be strings | ||
public PublicationTemplate Publication { get; set; } | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
NuKeeper.Abstractions/CollaborationModels/PackageTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma warning disable CA1819 // Properties should not return arrays | ||
#pragma warning disable CA1056 // Uri properties should not be strings | ||
|
||
using System; | ||
using System.Linq; | ||
|
||
namespace NuKeeper.Abstractions.CollaborationModels | ||
{ | ||
public class PackageTemplate | ||
{ | ||
public string Name { get; set; } | ||
public string Version { get; set; } | ||
public string FromVersion => MultipleUpdates ? | ||
string.Empty | ||
: Updates.FirstOrDefault()?.FromVersion; | ||
public string AllowedChange { get; set; } | ||
public string ActualChange { get; set; } | ||
public PublicationTemplate Publication { get; set; } | ||
public int ProjectsUpdated => | ||
Updates?.Length ?? 0; | ||
public LatestPackageTemplate LatestVersion { get; set; } | ||
public string Url { get; set; } | ||
public string SourceUrl { get; set; } | ||
public bool IsFromNuget { get; set; } | ||
public UpdateTemplate[] Updates { get; set; } | ||
public bool MultipleProjectsUpdated => Updates?.Length > 1; | ||
public bool MultipleUpdates => Updates? | ||
.Select(u => u.FromVersion) | ||
.Distinct(StringComparer.InvariantCultureIgnoreCase) | ||
.Count() > 1; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
NuKeeper.Abstractions/CollaborationModels/PublicationTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace NuKeeper.Abstractions.CollaborationModels | ||
{ | ||
public class PublicationTemplate | ||
{ | ||
public string Date { get; set; } | ||
public string Ago { get; set; } | ||
} | ||
} |
Oops, something went wrong.