Skip to content

Commit

Permalink
#651 Added setting to add custom prefix to generated history files
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Feb 14, 2024
1 parent c1cacbf commit 189f149
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ For further details take a look at LICENSE.txt.

CHANGELOG

5.2.2.0

* New: #651 Added setting to add custom prefix to generated history files

5.2.1.0

* New: Added 'Crap Score' metric for Coberatura coverage files (contrbuted by @rikrak)
Expand Down
2 changes: 1 addition & 1 deletion src/ReportGenerator.Core/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public void GenerateReport(

if (historyStorage != null)
{
new HistoryReportGenerator(historyStorage)
new HistoryReportGenerator(historyStorage, settings.HistoryFileNamePrefix)
.CreateReport(parserResult.Assemblies, executionTime, reportConfiguration.Tag);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ internal class HistoryReportGenerator
/// </summary>
private readonly IHistoryStorage historyStorage;

/// <summary>
/// Optional custom file prefix.
/// </summary>
private readonly string customfilePrefix;

/// <summary>
/// Initializes a new instance of the <see cref="HistoryReportGenerator" /> class.
/// </summary>
/// <param name="historyStorage">The history storage.</param>
internal HistoryReportGenerator(IHistoryStorage historyStorage)
/// <param name="customfilePrefix">Optional custom file prefix.</param>
internal HistoryReportGenerator(IHistoryStorage historyStorage, string customfilePrefix)
{
this.historyStorage = historyStorage ?? throw new ArgumentNullException(nameof(historyStorage));
this.customfilePrefix = string.IsNullOrWhiteSpace(customfilePrefix) ? string.Empty : "_" + customfilePrefix;
}

/// <summary>
Expand Down Expand Up @@ -86,7 +93,7 @@ internal void CreateReport(IEnumerable<Assembly> assemblies, DateTime executionT
}

var document = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), rootElement);
string fileName = date + "_CoverageHistory.xml";
string fileName = date + this.customfilePrefix + "_CoverageHistory.xml";
try
{
using (var stream = new MemoryStream())
Expand Down
5 changes: 5 additions & 0 deletions src/ReportGenerator.Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@ public int CachingDuringOfRemoteFilesInMinutes
/// Gets or sets the maximum decimal places for coverage quotas / percentages.
/// </summary>
public int MaximumDecimalPlacesForCoverageQuotas { get; set; } = 1;

/// <summary>
/// Gets or sets the prefix for history files.
/// </summary>
public string HistoryFileNamePrefix { get; set; }
}
}
4 changes: 3 additions & 1 deletion src/ReportGenerator.Core/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"excludeTestProjects": false,
"createSubdirectoryForAllReportTypes": false,
"customHeadersForRemoteFiles": null,
"defaultAssemblyName": "Default"
"defaultAssemblyName": "Default",
"maximumDecimalPlacesForCoverageQuotas": 1,
"historyFileNamePrefix": null
}
}

0 comments on commit 189f149

Please sign in to comment.