-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
354 additions
and
11 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
94 changes: 94 additions & 0 deletions
94
src/FlowReviewer/Agent/ReviewChanges/FeedbackHtmlTemplate.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,94 @@ | ||
// ------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by a tool. | ||
// Runtime Version: 16.0.0.0 | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
// ------------------------------------------------------------------------------ | ||
namespace Ciandt.FlowTools.FlowReviewer.Agent.ReviewChanges | ||
{ | ||
using System.Collections.Immutable; | ||
using System.Text; | ||
using Ciandt.FlowTools.FlowReviewer.Agent.ReviewChanges.v1; | ||
using Ciandt.FlowTools.FlowReviewer.Common; | ||
using Raiqub.Generators.T4CodeWriter; | ||
using System; | ||
|
||
/// <summary> | ||
/// Class to produce the template output | ||
/// </summary> | ||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")] | ||
public partial class FeedbackHtmlTemplate : CodeWriterBase<ImmutableList<ReviewerFeedbackResponse>> | ||
{ | ||
/// <summary> | ||
/// Create the template output | ||
/// </summary> | ||
public override string TransformText() | ||
{ | ||
this.Write("<!DOCTYPE html>\r\n<html>\r\n <head>\r\n <meta charset=\"utf-8\">\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\r\n <title>Code Review Feedback</title>\r\n <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/bulma@1.0.2/css/bulma.min.css\">\r\n <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/styles/default.min.css\">\r\n <script src=\"https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/highlight.min.js\"></script>\r\n </head>\r\n <body>\r\n <section class=\"section\">\r\n <div class=\"container\">\r\n <h1 class=\"title\">Code Review Feedback</h1>\r\n <div class=\"content\">\r\n"); | ||
|
||
foreach (var response in Model) | ||
{ | ||
|
||
this.Write(" <div class=\"box\">\r\n <h2 class=\"subtitle\">\r\n <span class=\"tag"); | ||
|
||
this.Write(this.ToStringHelper.ToStringWithCulture(GetRiskLevelCssClass(response.RiskScore))); | ||
|
||
#line default | ||
#line hidden | ||
this.Write("\">Risk Score: "); | ||
|
||
this.Write(this.ToStringHelper.ToStringWithCulture(response.RiskScore)); | ||
|
||
#line default | ||
#line hidden | ||
this.Write("</span> "); | ||
|
||
this.Write(this.ToStringHelper.ToStringWithCulture(response.RiskDescription)); | ||
|
||
#line default | ||
#line hidden | ||
this.Write("\r\n </h2>\r\n <p><strong>File:</strong> "); | ||
|
||
this.Write(this.ToStringHelper.ToStringWithCulture(response.Path)); | ||
|
||
#line default | ||
#line hidden | ||
this.Write(":"); | ||
|
||
this.Write(this.ToStringHelper.ToStringWithCulture(response.Line)); | ||
|
||
#line default | ||
#line hidden | ||
this.Write("</p>\r\n <div class=\"notification\">\r\n "); | ||
|
||
this.Write(this.ToStringHelper.ToStringWithCulture(HtmlFormatter.EncodeToHtml(response.Feedback))); | ||
|
||
#line default | ||
#line hidden | ||
this.Write("\r\n </div>\r\n </div>\r\n"); | ||
|
||
} | ||
|
||
this.Write(" </div>\r\n </div>\r\n </section>\r\n <script>hljs.highlightAll();</script>\r\n </body>\r\n</html>\r\n"); | ||
return this.GenerationEnvironment.ToString(); | ||
} | ||
|
||
public FeedbackHtmlTemplate(ImmutableList<ReviewerFeedbackResponse> model) : base(new StringBuilder()) | ||
{ | ||
Model = model; | ||
} | ||
|
||
public override string GetFileName() => Guid.NewGuid().ToString("N"); | ||
|
||
private static string GetRiskLevelCssClass(int number) => number switch{ | ||
0 => " is-white", | ||
1 => " is-success", | ||
2 => " is-warning", | ||
3 => " is-danger", | ||
_ => ""}; | ||
|
||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/FlowReviewer/Agent/ReviewChanges/FeedbackHtmlTemplate.tt
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,58 @@ | ||
<#@ template language="C#" debug="false" linePragmas="false" hostspecific="false" inherits="CodeWriterBase<ImmutableList<ReviewerFeedbackResponse>>" #> | ||
<#@ import namespace="System.Collections.Immutable" #> | ||
<#@ import namespace="System.Text" #> | ||
<#@ import namespace="Ciandt.FlowTools.FlowReviewer.Agent.ReviewChanges.v1" #> | ||
<#@ import namespace="Ciandt.FlowTools.FlowReviewer.Common" #> | ||
<#@ import namespace="Raiqub.Generators.T4CodeWriter" #> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Code Review Feedback</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.2/css/bulma.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/styles/default.min.css"> | ||
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/highlight.min.js"></script> | ||
</head> | ||
<body> | ||
<section class="section"> | ||
<div class="container"> | ||
<h1 class="title">Code Review Feedback</h1> | ||
<div class="content"> | ||
<# | ||
foreach (var response in Model) | ||
{ | ||
#> | ||
<div class="box"> | ||
<h2 class="subtitle"> | ||
<span class="tag<#= GetRiskLevelCssClass(response.RiskScore) #>">Risk Score: <#= response.RiskScore #></span> <#= response.RiskDescription #> | ||
</h2> | ||
<p><strong>File:</strong> <#= response.Path #>:<#= response.Line #></p> | ||
<div class="notification"> | ||
<#= HtmlFormatter.EncodeToHtml(response.Feedback) #> | ||
</div> | ||
</div> | ||
<# | ||
} | ||
#> | ||
</div> | ||
</div> | ||
</section> | ||
<script>hljs.highlightAll();</script> | ||
</body> | ||
</html> | ||
<#+ | ||
public FeedbackHtmlTemplate(ImmutableList<ReviewerFeedbackResponse> model) : base(new StringBuilder()) | ||
{ | ||
Model = model; | ||
} | ||
|
||
public override string GetFileName() => Guid.NewGuid().ToString("N"); | ||
|
||
private static string GetRiskLevelCssClass(int number) => number switch{ | ||
0 => " is-white", | ||
1 => " is-success", | ||
2 => " is-warning", | ||
3 => " is-danger", | ||
_ => ""}; | ||
#> |
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
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
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,58 @@ | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Web; | ||
|
||
namespace Ciandt.FlowTools.FlowReviewer.Common; | ||
|
||
public static partial class HtmlFormatter | ||
{ | ||
public static string EncodeToHtml(string text) | ||
{ | ||
text = HttpUtility.HtmlEncode(text); | ||
text = CodeDelimiterRegex().Replace(text, """<pre><code class="language-$1">$2</code></pre>"""); | ||
text = CodeBlockDelimiterRegex().Replace(text, "<code>$1</code>"); | ||
text = ReplaceLineBreaksExceptInCode(text); | ||
return text; | ||
} | ||
|
||
private static string ReplaceLineBreaksExceptInCode(string input) | ||
{ | ||
if (string.IsNullOrEmpty(input)) | ||
return input; | ||
|
||
var result = new StringBuilder(); | ||
var insideCodeBlock = false; | ||
var lastSize = 0; | ||
|
||
foreach (var line in input.AsSpan().EnumerateLines()) | ||
{ | ||
if (line.Contains("<code", StringComparison.OrdinalIgnoreCase)) | ||
insideCodeBlock = true; | ||
|
||
if (!insideCodeBlock) | ||
{ | ||
result.Append(line.TrimEnd()); | ||
result.Append("<br>"); | ||
lastSize = 4; | ||
} | ||
else | ||
{ | ||
result.Append(line); | ||
result.Append('\n'); | ||
lastSize = 1; | ||
} | ||
|
||
if (line.Contains("</code>", StringComparison.OrdinalIgnoreCase)) | ||
insideCodeBlock = false; | ||
} | ||
|
||
result.Length -= lastSize; | ||
return result.ToString(); | ||
} | ||
|
||
[GeneratedRegex(@"```(\S+)?(.*?)```", RegexOptions.Multiline)] | ||
private static partial Regex CodeDelimiterRegex(); | ||
|
||
[GeneratedRegex("`(.*?)`", RegexOptions.Singleline)] | ||
private static partial Regex CodeBlockDelimiterRegex(); | ||
} |
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
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
Oops, something went wrong.