mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Added metrics badge
This commit is contained in:
parent
7d1a77e754
commit
eefcbfaada
19
Wabbajack.Server/Badge.cs
Normal file
19
Wabbajack.Server/Badge.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using Wabbajack.Common.Serialization.Json;
|
||||
|
||||
namespace Wabbajack.Server
|
||||
{
|
||||
[JsonName("Badge")]
|
||||
public class Badge
|
||||
{
|
||||
public int schemaVersion { get; set; } = 1;
|
||||
public string label { get; set; }
|
||||
public string message { get; set; }
|
||||
public string color { get; set; }
|
||||
|
||||
public Badge(string _label, string _message)
|
||||
{
|
||||
label = _label;
|
||||
message = _message;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ using Nettle;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.Serialization.Json;
|
||||
using Wabbajack.Lib.ModListRegistry;
|
||||
using Wabbajack.Server;
|
||||
using Wabbajack.Server.DataLayer;
|
||||
using Wabbajack.Server.DTOs;
|
||||
using Wabbajack.Server.Services;
|
||||
@ -139,21 +140,6 @@ namespace Wabbajack.BuildServer.Controllers
|
||||
.FirstOrDefault(d => d.MachineName == Name);
|
||||
}
|
||||
|
||||
[JsonName("Badge")]
|
||||
public class Badge
|
||||
{
|
||||
public int schemaVersion { get; set; } = 1;
|
||||
public string label { get; set; }
|
||||
public string message { get; set; }
|
||||
public string color { get; set; }
|
||||
|
||||
public Badge(string _label, string _message)
|
||||
{
|
||||
label = _label;
|
||||
message = _message;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("status/badge.json")]
|
||||
public async Task<IActionResult> HandleGitHubBadge()
|
||||
|
@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Nettle;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Server;
|
||||
using Wabbajack.Server.DataLayer;
|
||||
using Wabbajack.Server.DTOs;
|
||||
using WebSocketSharp;
|
||||
@ -52,6 +53,29 @@ namespace Wabbajack.BuildServer.Controllers
|
||||
return Ok(results.ToList());
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("badge/{name}/badge.json")]
|
||||
public async Task<IActionResult> MetricsGitHubBadge(string name)
|
||||
{
|
||||
var results = (await _sql.MetricsReport("finish_install"))
|
||||
.GroupBy(m => m.Subject)
|
||||
.Select(g => new MetricResult
|
||||
{
|
||||
SeriesName = g.Key,
|
||||
Labels = g.Select(m => m.Date.ToString(CultureInfo.InvariantCulture)).ToList(),
|
||||
Values = g.Select(m => m.Count).ToList()
|
||||
}).ToList();
|
||||
|
||||
Response.ContentType = "application/json";
|
||||
|
||||
var modlist =
|
||||
results.FirstOrDefault(x => x.SeriesName.Equals(name, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
return Ok(modlist == null
|
||||
? new Badge($"Modlist {name} not found!", "Error") {color = "red"}.ToJson()
|
||||
: new Badge("Installations: ", $"{modlist.Values.Aggregate((x, y) => x + y)}").ToJson());
|
||||
}
|
||||
|
||||
private static readonly Func<object, string> ReportTemplate = NettleEngine.GetCompiler().Compile(@"
|
||||
<html><body>
|
||||
<h2>Tar Report for {{$.key}}</h2>
|
||||
|
Loading…
Reference in New Issue
Block a user