Skip to content

Commit

Permalink
fix(review): Fix formatting of code blocks (#3)
Browse files Browse the repository at this point in the history
- Fix HTML formatting of feedback code blocks
- Use GitHub dark theme for code highlighting
- Use Cloudflare CDN with integrity check
- Ignore empty feedbacks
  • Loading branch information
skarllot authored Dec 20, 2024
1 parent 5e2c42d commit ffeda98
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/FlowPair/Agent/ReviewChanges/FeedbackHtmlTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial class FeedbackHtmlTemplate : CodeWriterBase<ImmutableList<Reviewe
/// </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");
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://cdnjs.cloudflare.com/ajax/libs/bulma/1.0.2/css/bulma.min.css\" integrity=\"sha512-RpeJZX3aH5oZN3U3JhE7Sd+HG8XQsqmP3clIbu4G28p668yNsRNj3zMASKe1ATjl/W80wuEtCx2dFA8xaebG5w==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\" />\r\n <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/default.min.css\" integrity=\"sha512-hasIneQUHlh06VNBe7f6ZcHmeRTLIaQWFd43YriJ0UND19bvYRauxthDg8E4eVNPm9bRUhr5JGeqH7FRFXQu5g==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\" />\r\n <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/github-dark.min.css\" integrity=\"sha512-rO+olRTkcf304DQBxSWxln8JXCzTHlKnIdnMUwYvQa9/Jd4cQaNkItIUj6Z4nvW1dqK0SKXLbn9h4KwZTNtAyw==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\" />\r\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/highlight.min.js\" integrity=\"sha512-6QBAC6Sxc4IF04SvIg0k78l5rP5YgVjmHX2NeArelbxM3JGj4imMqfNzEta3n+mi7iG3nupdLnl3QrbfjdXyTg==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\"></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)
{
Expand Down
7 changes: 4 additions & 3 deletions src/FlowPair/Agent/ReviewChanges/FeedbackHtmlTemplate.tt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
<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>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/1.0.2/css/bulma.min.css" integrity="sha512-RpeJZX3aH5oZN3U3JhE7Sd+HG8XQsqmP3clIbu4G28p668yNsRNj3zMASKe1ATjl/W80wuEtCx2dFA8xaebG5w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/default.min.css" integrity="sha512-hasIneQUHlh06VNBe7f6ZcHmeRTLIaQWFd43YriJ0UND19bvYRauxthDg8E4eVNPm9bRUhr5JGeqH7FRFXQu5g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/github-dark.min.css" integrity="sha512-rO+olRTkcf304DQBxSWxln8JXCzTHlKnIdnMUwYvQa9/Jd4cQaNkItIUj6Z4nvW1dqK0SKXLbn9h4KwZTNtAyw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/highlight.min.js" integrity="sha512-6QBAC6Sxc4IF04SvIg0k78l5rP5YgVjmHX2NeArelbxM3JGj4imMqfNzEta3n+mi7iG3nupdLnl3QrbfjdXyTg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body>
<section class="section">
Expand Down
1 change: 1 addition & 0 deletions src/FlowPair/Agent/ReviewChanges/FlowChangesReviewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public Option<Unit> Run(ImmutableList<FileChange> changes)
.Where(g => g.Key.IsSome)
.Select(g => new { Instructions = g.Key.Unwrap(), Diff = g.AggregateToStringLines(c => c.Diff) })
.SelectMany(x => GetFeedback([AllowedModel.Claude35Sonnet, AllowedModel.Gpt4o], x.Diff, x.Instructions))
.Where(f => !string.IsNullOrWhiteSpace(f.Feedback))
.OrderByDescending(x => x.RiskScore).ThenBy(x => x.Path, StringComparer.OrdinalIgnoreCase)
.ToImmutableList();

Expand Down
4 changes: 2 additions & 2 deletions src/FlowPair/Common/HtmlFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ private static string ReplaceLineBreaksExceptInCode(string input)
return result.ToString();
}

[GeneratedRegex(@"```(\S+)?(.*?)```", RegexOptions.Multiline)]
[GeneratedRegex(@"```(\S+)?(.*?)```", RegexOptions.Singleline)]
private static partial Regex CodeDelimiterRegex();

[GeneratedRegex("`(.*?)`", RegexOptions.Singleline)]
[GeneratedRegex("`(.*?)`", RegexOptions.Multiline)]
private static partial Regex CodeBlockDelimiterRegex();
}

0 comments on commit ffeda98

Please sign in to comment.