Skip to content

Commit

Permalink
Merge pull request #2 from rubberduck-vba/xmldoc
Browse files Browse the repository at this point in the history
Backend Tweaks
  • Loading branch information
retailcoder authored Nov 10, 2024
2 parents fb32199 + e9c4097 commit 14a3ae7
Show file tree
Hide file tree
Showing 169 changed files with 3,244 additions and 2,286 deletions.
33 changes: 8 additions & 25 deletions .github/workflows/dotnet-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:

jobs:
build:
runs-on: windows-latest
runs-on: self-hosted

steps:
- uses: actions/checkout@v4
Expand All @@ -29,31 +29,14 @@ jobs:
- name: dotnet publish
run: dotnet publish "rubberduckvba.Server\rubberduckvba.Server.csproj" --configuration Release --output ${{env.DOTNET_ROOT}}\pub

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: webapi
path: ${{env.DOTNET_ROOT}}/pub

deploy:
environment:
name: AZ-Test
url: https://test.rubberduckvba.com
permissions:
contents: none
runs-on: windows-latest
runs-on: self-hosted
needs: build
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: webapi
- name: Deploy to IIS
id: deploy-to-iis
uses: ChristopheLav/iis-deploy@v1
with:
website-name: 'api'
msdeploy-service-url: ${{ secrets.MSDEPLOY_URL }}
msdeploy-username: ${{ secrets.MSDEPLOY_USERNAME }}
msdeploy-password: ${{ secrets.MSDEPLOY_PASSWORD }}
source-path: ${{ github.workspace }}\website\publish
run: |
stop-webapppool rubberduckvba
stop-iissite -Name api -Confirm: $false
Copy-Item ${{env.DOTNET_ROOT}}\pub\* C:/inetpub/wwwroot -Recurse -Force
start-webapppool rubberduckvba
start-iissite api
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,5 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
/rubberduckvba.Server/appsettings.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The task can be launched manually from the back-end API with an authenticated PO
## Update XmlDoc content
Similarly, this job creates a TPL DataFlow pipeline that can be documented as follows:

![diagram](https://github.com/user-attachments/assets/519e1d61-514f-4186-a694-4db69d7e8da9)
![diagram](https://github.com/user-attachments/assets/dac3020c-9335-4573-b1ef-f4984cdf56b4)

This pipeline hits GitHub to download the code inspections' default configuration from the **rubberduck-vba/Rubberduck** repository, fetches the current-latest tags from the database to compare against the current-latest tags from GitHub, then downloads the .xml assets and parses them into "feature items" and proceeds to merge the contents:
- Items that exist in **next** but not **main** are considered/marked as NEW
Expand Down
26 changes: 13 additions & 13 deletions RubberduckServices/SyntaxHighlighterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface ISyntaxHighlighterService
/// </summary>
/// <param name="code">A fragment of VBA code that can be parsed by Rubberduck.</param>
/// <returns>The provided code, syntax-formatted.</returns>
Task<string> FormatAsync(string code);
string Format(string code);
}

public class SyntaxHighlighterService : ISyntaxHighlighterService
Expand Down Expand Up @@ -52,7 +52,7 @@ public SyntaxHighlighterService(
_attributeValueClass = cssAttributeValues;
}

public async Task<string> FormatAsync(string code)
public string Format(string code)
{
var indenter = new SimpleIndenter();

Expand Down Expand Up @@ -96,10 +96,10 @@ public async Task<string> FormatAsync(string code)
var lines = builder.ToString().Split("\n").ToArray();
var indent = lines.LastOrDefault()?.TakeWhile(char.IsWhiteSpace)?.Count() ?? 0;
var formattedLines = from line in lines
let trimmed = line.Substring(indent)
let trimmed = line[indent..]
select FormatIndents(trimmed);

return await Task.FromResult(string.Join("<br/>", formattedLines));
return string.Join("<br/>", formattedLines);
}

private void FormatTokens(StringBuilder builder, ITokenStream tokens, IntervalListener[] listeners)
Expand All @@ -119,13 +119,13 @@ private void FormatTokens(StringBuilder builder, ITokenStream tokens, IntervalLi
builder.Append($"<span class=\"{listener.Class}\">{tokens.GetText(listener.Interval)}</span>");
i = listener.Interval.b;
}
else if (listener is NewLineListener)
{
if (token.Type == VBAParser.NEWLINE)
{
builder.Append(Environment.NewLine);
}
}
//else if (listener is NewLineListener)
//{
// if (token.Type == VBAParser.NEWLINE)
// {
// builder.Append(Environment.NewLine);
// }
//}
else
{
if (TokenKinds.StringLiterals.Contains(token.Type))
Expand All @@ -148,7 +148,7 @@ private void FormatTokens(StringBuilder builder, ITokenStream tokens, IntervalLi
}
}

private static ITokenStream Tokenize(string code)
private static CommonTokenStream Tokenize(string code)
{
AntlrInputStream input;
using (var reader = new StringReader(code))
Expand All @@ -165,7 +165,7 @@ private static string FormatIndents(string line)
var indent = line.TakeWhile(char.IsWhiteSpace).Count();
if (indent > 0)
{
formatted = line.Substring(0, indent).Replace(" ", "&nbsp;") + line.Substring(indent);
formatted = string.Concat(line[..indent].Replace(" ", "&nbsp;"), line.AsSpan(indent));
}
return formatted;
}
Expand Down
15 changes: 8 additions & 7 deletions rubberduckvba.Server/Api/Admin/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using rubberduckvba.com.Server.ContentSynchronization;
using rubberduckvba.com.Server.Hangfire;
using rubberduckvba.Server;
using rubberduckvba.Server.ContentSynchronization;
using rubberduckvba.Server.Hangfire;
using rubberduckvba.Server.Services;

namespace rubberduckvba.com.Server.Api.Admin;
namespace rubberduckvba.Server.Api.Admin;


[Authorize("github")]
[ApiController]
public class AdminController(ConfigurationOptions options, IBackgroundJobClient backgroundJob, ILogger<AdminController> logger) : ControllerBase
{
Expand All @@ -20,7 +21,7 @@ public class AdminController(ConfigurationOptions options, IBackgroundJobClient
[HttpPost("admin/update/xmldoc")]
public async ValueTask<IActionResult> UpdateXmldocContent()
{
var parameters = new XmldocSyncRequestParameters { RepositoryId = Services.RepositoryId.Rubberduck, RequestId = Guid.NewGuid() };
var parameters = new XmldocSyncRequestParameters { RepositoryId = RepositoryId.Rubberduck, RequestId = Guid.NewGuid() };
var jobId = backgroundJob.Enqueue(HangfireConstants.ManualQueueName, () => QueuedUpdateOrchestrator.UpdateXmldocContent(parameters, null!));
logger.LogInformation("JobId {jobId} was enqueued (queue: {queueName}) for xmldoc sync request {requestId}", jobId, HangfireConstants.ManualQueueName, parameters.RequestId);

Expand All @@ -35,14 +36,13 @@ public async ValueTask<IActionResult> UpdateXmldocContent()
[HttpPost("admin/update/tags")]
public async ValueTask<IActionResult> UpdateTagMetadata()
{
var parameters = new TagSyncRequestParameters { RepositoryId = Services.RepositoryId.Rubberduck, RequestId = Guid.NewGuid() };
var parameters = new TagSyncRequestParameters { RepositoryId = RepositoryId.Rubberduck, RequestId = Guid.NewGuid() };
var jobId = backgroundJob.Enqueue(HangfireConstants.ManualQueueName, () => QueuedUpdateOrchestrator.UpdateInstallerDownloadStats(parameters, null!));
logger.LogInformation("JobId {jobId} was enqueued (queue: {queueName}) for tag sync request {requestId}", jobId, HangfireConstants.ManualQueueName, parameters.RequestId);

return await ValueTask.FromResult(Ok(jobId));
}

[Authorize("github")]
[HttpGet("admin/config/current")]
public async ValueTask<IActionResult> Config()
{
Expand All @@ -52,6 +52,7 @@ public async ValueTask<IActionResult> Config()

public record class ConfigurationOptions(
IOptions<ConnectionSettings> ConnectionOptions,
IOptions<GitHubSettings> GitHubOptions,
IOptions<HangfireSettings> HangfireOptions)
{

Expand Down
2 changes: 1 addition & 1 deletion rubberduckvba.Server/Api/Auth/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Security.Claims;
using System.Text;

namespace rubberduckvba.com.Server.Api.Auth;
namespace rubberduckvba.Server.Api.Auth;

public record class UserViewModel
{
Expand Down
4 changes: 2 additions & 2 deletions rubberduckvba.Server/Api/Auth/ClaimsPrincipalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
using System.Security.Claims;
using System.Text;

namespace rubberduckvba.com.Server.Api.Auth;
namespace rubberduckvba.Server.Api.Auth;

public static class ClaimsPrincipalExtensions
{
public static string AsJWT(this ClaimsPrincipal principal, string secret, string issuer, string audience)
{
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secret));
var token = new JwtSecurityToken(issuer, audience,
var token = new JwtSecurityToken(issuer, audience,
claims: principal?.Claims,
notBefore: new DateTimeOffset(DateTime.UtcNow).UtcDateTime,
expires: new DateTimeOffset(DateTime.UtcNow.AddMinutes(60)).UtcDateTime,
Expand Down
4 changes: 2 additions & 2 deletions rubberduckvba.Server/Api/Downloads/AvailableDownload.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using rubberduckvba.com.Server.Data;
using rubberduckvba.Server.Model;

namespace rubberduckvba.com.Server.Api.Downloads;
namespace rubberduckvba.Server.Api.Downloads;

public record class AvailableDownload
{
Expand Down
4 changes: 2 additions & 2 deletions rubberduckvba.Server/Api/Downloads/DownloadsController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using rubberduckvba.com.Server.Services;
using rubberduckvba.Server.Services;
using System.Collections.Immutable;

namespace rubberduckvba.com.Server.Api.Downloads;
namespace rubberduckvba.Server.Api.Downloads;


[ApiController]
Expand Down
12 changes: 6 additions & 6 deletions rubberduckvba.Server/Api/Features/FeatureEditViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using rubberduckvba.com.Server.Data;
using rubberduckvba.com.Server.Services;
using rubberduckvba.Server.Model;
using rubberduckvba.Server.Services;

namespace rubberduckvba.com.Server.Api.Features;
namespace rubberduckvba.Server.Api.Features;

public class FeatureEditViewModel
{
Expand Down Expand Up @@ -30,7 +30,7 @@ public Feature ToFeature()
{
Id = Id ?? default,
ParentId = ParentId,
RepositoryId = (int)RepositoryId,
RepositoryId = RepositoryId,
Name = Name,
Title = Title,
ShortDescription = ShortDescription,
Expand All @@ -44,8 +44,8 @@ public FeatureEditViewModel(Feature model, FeatureOptionViewModel[] features, Re
{
Id = model.Id;
ParentId = model.ParentId;
RepositoryId = (RepositoryId)model.RepositoryId;
RepositoryId = model.RepositoryId;

Name = model.Name;
Title = model.Title;
ShortDescription = model.ShortDescription;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace rubberduckvba.com.Server.Api.Features;
namespace rubberduckvba.Server.Api.Features;

public class FeatureOptionViewModel
{
Expand Down
21 changes: 7 additions & 14 deletions rubberduckvba.Server/Api/Features/FeatureViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using rubberduckvba.com.Server.Data;
using System.Text.Json;
using rubberduckvba.Server.Model;

namespace rubberduckvba.com.Server.Api.Features;
namespace rubberduckvba.Server.Api.Features;

public class FeatureViewModel
{
Expand All @@ -21,13 +20,8 @@ public FeatureViewModel(Feature model)

if (model is FeatureGraph graph)
{
FeatureId = graph.ParentId;
FeatureName = graph.ParentName;
FeatureTitle = graph.ParentTitle;

Features = graph.Features.Select(e => new FeatureViewModel(e)).ToArray();
Items = graph.Items.Select(e => e with { FeatureId = graph.ParentId!.Value, FeatureName = graph.ParentName, FeatureTitle = graph.ParentTitle }).ToArray();
Inspections = graph.Items.Select(e => JsonSerializer.Deserialize<XmlDocInspectionInfo>(e.Serialized)!).ToArray();
Features = graph.Features.Select(e => new FeatureViewModel(e) { FeatureId = e.ParentId, FeatureName = graph.Name, FeatureTitle = graph.Title }).ToArray();
Inspections = graph.Inspections.ToArray();
}
}

Expand All @@ -36,8 +30,8 @@ public FeatureViewModel(Feature model)
public DateTime? DateUpdated { get; init; }

public int? FeatureId { get; init; }
public string FeatureName { get; init; }
public string FeatureTitle { get; init; }
public string? FeatureName { get; init; }
public string? FeatureTitle { get; init; }

public string Name { get; init; }
public string Title { get; init; }
Expand All @@ -48,8 +42,7 @@ public FeatureViewModel(Feature model)
public bool HasImage { get; init; }

public FeatureViewModel[] Features { get; init; } = [];
public FeatureXmlDoc[] Items { get; init; } = [];
public XmlDocInspectionInfo[] Inspections { get; init; } = [];
public Inspection[] Inspections { get; init; } = []; // InspectionViewModel[]
}

public class FeatureXmlDocViewModel
Expand Down
Loading

0 comments on commit 14a3ae7

Please sign in to comment.