Skip to content

Commit 543961e

Browse files
committed
(GH-17) Add support for loading generic reporter dynamically
1 parent fb4bb1a commit 543961e

File tree

5 files changed

+128
-19
lines changed

5 files changed

+128
-19
lines changed

Cake.Issues.Recipe/Content/addins.cake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
#addin nuget:?package=Cake.Issues.InspectCode&version=0.8.0
99
#addin nuget:?package=Cake.Issues.Markdownlint&version=0.8.2
1010
#addin nuget:?package=Cake.Issues.Reporting&version=0.8.0
11-
#addin nuget:?package=Cake.Issues.Reporting.Generic&version=0.8.2
1211
#addin nuget:?package=Cake.Issues.PullRequests&version=0.8.1
1312
#addin nuget:?package=Cake.Issues.PullRequests.AppVeyor&version=0.8.0
1413
#addin nuget:?package=Cake.Issues.PullRequests.AzureDevOps&version=0.8.0
15-
#addin nuget:?package=Cake.AzureDevOps&version=0.4.4
14+
#addin nuget:?package=Cake.AzureDevOps&version=0.4.4
15+
16+
public const string CakeIssuesReportingGenericVersion = "0.8.2";

Cake.Issues.Recipe/Content/build.cake

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#load IssuesBuildTasksDefinitions.cake
33
#load version.cake
44
#load data/data.cake
5+
#load loader/loader.cake
56
#load parameters/parameters.cake
7+
#load reporters/reporters.cake
68

79
///////////////////////////////////////////////////////////////////////////////
810
// GLOBAL VARIABLES
@@ -113,16 +115,31 @@ IssuesBuildTasks.CreateFullIssuesReportTask = Task("Create-FullIssuesReport")
113115
IssuesParameters.OutputDirectory.CombineWithFilePath(reportFileName);
114116
EnsureDirectoryExists(IssuesParameters.OutputDirectory);
115117

118+
IIssueReportFormat issueFormat = null;
119+
120+
if (!Context.Environment.Runtime.IsCoreClr)
121+
{
122+
Information("Loading Generic Reporter");
123+
var genericReporter = new GenericReporterData(Context);
124+
var settings = genericReporter.FromEmbeddedTemplate(genericReporter.GenericIssueReportTemplateEnum("HtmlDxDataGrid"));
125+
genericReporter.WithOption(settings, genericReporter.HtmlDxDataGridOptionEnum("Theme"), genericReporter.DevXtremeEnum("MaterialBlueLight"));
126+
127+
issueFormat = genericReporter.GenericIssueReportFormat(settings);
128+
}
129+
116130
// Create HTML report using DevExpress template.
117-
var settings =
118-
GenericIssueReportFormatSettings
119-
.FromEmbeddedTemplate(GenericIssueReportTemplate.HtmlDxDataGrid)
120-
.WithOption(HtmlDxDataGridOption.Theme, DevExtremeTheme.MaterialBlueLight);
121-
CreateIssueReport(
122-
data.Issues,
123-
GenericIssueReportFormat(settings),
124-
data.RepositoryRootDirectory,
125-
data.FullIssuesReport);
131+
if (issueFormat != null)
132+
{
133+
CreateIssueReport(
134+
data.Issues,
135+
issueFormat,
136+
data.RepositoryRootDirectory,
137+
data.FullIssuesReport);
138+
}
139+
else
140+
{
141+
Warning("No issue report format was found, ignoring...");
142+
}
126143
});
127144

128145
IssuesBuildTasks.PublishIssuesArtifactsTask = Task("Publish-IssuesArtifacts")
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
public class GenericReporterData : AddinData
2+
{
3+
public Func<string, object> DevXtremeEnum { get; private set; }
4+
public Func<string, object> GenericIssueReportTemplateEnum { get; private set; }
5+
public Func<string, object> HtmlDxDataGridOptionEnum { get; private set; }
6+
7+
public Func<object, object> FromEmbeddedTemplate { get; private set; }
8+
9+
public Func<object, object, object, object> WithOption { get; private set; }
10+
11+
public Func<object, IIssueReportFormat> GenericIssueReportFormat { get; private set; }
12+
public Func<FilePath, IIssueReportFormat> GenericIssueReportFormatFromFilePath { get; private set; }
13+
14+
public GenericReporterData(ICakeContext context)
15+
: base(context, "Cake.Issues.Reporting.Generic", CakeIssuesReportingGenericVersion)
16+
{
17+
}
18+
19+
protected override void AliasFound(ICakeContext context, MethodInfo method)
20+
{
21+
switch (method.Name.ToUpperInvariant())
22+
{
23+
case "GENERICISSUEREPORTFORMAT":
24+
var parameters = method.GetParameters();
25+
if (parameters.Length == 2 && parameters[1].ParameterType.Name.ToUpperInvariant() == "GENERICISSUEREPORTFORMATSETTINGS")
26+
{
27+
GenericIssueReportFormat = (settings) => (IIssueReportFormat)method.Invoke(null, new object[] { context, settings });
28+
}
29+
break;
30+
case "GENERICISSUEREPORTFORMATFROMFILEPATH":
31+
GenericIssueReportFormatFromFilePath = (path) => (IIssueReportFormat)method.Invoke(null, new object[] { context, path });
32+
break;
33+
}
34+
}
35+
36+
protected override void EnumerationFound(ICakeContext context, Type enumType)
37+
{
38+
switch (enumType.Name.ToUpperInvariant())
39+
{
40+
case "DEVEXTREMETHEME":
41+
DevXtremeEnum = (value) => Enum.Parse(enumType, value);
42+
break;
43+
case "GENERICISSUEREPORTTEMPLATE":
44+
GenericIssueReportTemplateEnum = (value) => Enum.Parse(enumType, value);
45+
break;
46+
case "HTMLDXDATAGRIDOPTION":
47+
HtmlDxDataGridOptionEnum = (value) => Enum.Parse(enumType, value);
48+
break;
49+
default:
50+
// Ignore on purpose
51+
break;
52+
}
53+
}
54+
55+
protected override void MethodFound(ICakeContext context, MethodInfo method)
56+
{
57+
switch (method.Name.ToUpperInvariant())
58+
{
59+
case "FROMEMBEDDEDTEMPLATE":
60+
FromEmbeddedTemplate = (obj) => {
61+
return method.Invoke(null, new object[] { obj });
62+
};
63+
break;
64+
case "WITHOPTION":
65+
var parameters = method.GetParameters();
66+
if (parameters.Length == 3 && parameters[1].ParameterType == typeof(Enum))
67+
{
68+
WithOption = (settings, key, value) => {
69+
return method.Invoke(null, new object[] { settings, key, value });
70+
};
71+
}
72+
break;
73+
}
74+
}
75+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#load ./GenericReporterData.cake

Cake.Issues.Recipe/Content/tasks/buildservers/AzureDevOpsBuildServer.cake

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,30 @@ public class AzureDevOpsBuildServer : BaseBuildServer
9797
summaryFileName += ".md";
9898
var summaryFilePath = IssuesParameters.OutputDirectory.CombineWithFilePath(summaryFileName);
9999

100+
IIssueReportFormat issueFormat = null;
101+
if (!context.Environment.Runtime.IsCoreClr)
102+
{
103+
var genericReporter = new GenericReporterData(context);
104+
105+
var reportPath = new FilePath(sourceFilePath).GetDirectory().Combine("tasks").Combine("buildservers").CombineWithFilePath("AzurePipelinesSummary.cshtml");
106+
issueFormat = genericReporter.GenericIssueReportFormatFromFilePath(reportPath);
107+
}
108+
109+
if (issueFormat != null)
110+
{
100111
// Create summary for Azure Pipelines using custom template.
101-
context.CreateIssueReport(
102-
data.Issues,
103-
context.GenericIssueReportFormatFromFilePath(
104-
new FilePath(sourceFilePath).GetDirectory().Combine("tasks").Combine("buildservers").CombineWithFilePath("AzurePipelineSummary.cshtml")),
105-
data.RepositoryRootDirectory,
106-
summaryFilePath);
107-
108-
context.TFBuild().Commands.UploadTaskSummary(summaryFilePath);
112+
context.CreateIssueReport(
113+
data.Issues,
114+
issueFormat,
115+
data.RepositoryRootDirectory,
116+
summaryFilePath);
117+
118+
context.TFBuild().Commands.UploadTaskSummary(summaryFilePath);
119+
}
120+
else
121+
{
122+
context.Warning("No issue report format was found, ignoring...");
123+
}
109124
}
110125

111126
/// <inheritdoc />

0 commit comments

Comments
 (0)