Files
Website/BlazorApp/Services/DeveloperTicketParsingService.cs
SysAdmin cd2994d7eb
All checks were successful
Build and Deploy / deploy (push) Successful in 18s
fix(developers): add Mattermost team membership and role-aware Gitea provisioning
New users are now added to the SilverLABS Mattermost team after account
creation. Gitea provisioning is skipped for Testers (only Developers get
repo access). Role is parsed from ticket description and threaded through
the entire approval/confirmation flow. Gitea API token is now configured.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 15:10:45 +00:00

54 lines
1.9 KiB
C#

using System.Text.Json;
using System.Text.RegularExpressions;
namespace SilverLabs.Website.Services;
public class DeveloperTicketParsingService
{
private readonly HttpClient _httpClient;
private readonly ILogger<DeveloperTicketParsingService> _logger;
public DeveloperTicketParsingService(HttpClient httpClient, ILogger<DeveloperTicketParsingService> logger)
{
_httpClient = httpClient;
_logger = logger;
}
public async Task<JsonElement?> FetchTicketAsync(string ticketId)
{
try
{
var response = await _httpClient.GetAsync($"/api/tickets/{ticketId}");
if (!response.IsSuccessStatusCode)
{
_logger.LogError("Failed to fetch ticket {TicketId}: {Status}", ticketId, response.StatusCode);
return null;
}
var json = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<JsonElement>(json);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error fetching ticket {TicketId}", ticketId);
return null;
}
}
public (string? FullName, string? Email, string? DesiredUsername, string? Role) ParseApplicationFromDescription(string description)
{
var fullName = ExtractField(description, @"\*\*Full Name:\*\*\s*(.+)");
var email = ExtractField(description, @"\*\*Email:\*\*\s*(.+)");
var desiredUsername = ExtractField(description, @"\*\*Desired Username:\*\*\s*(.+)");
var role = ExtractField(description, @"\*\*Role:\*\*\s*(.+)");
return (fullName, email, desiredUsername, role);
}
private static string? ExtractField(string text, string pattern)
{
var match = Regex.Match(text, pattern);
return match.Success ? match.Groups[1].Value.Trim() : null;
}
}