Skip to content

Commit

Permalink
Fix some changelog inconsistencies
Browse files Browse the repository at this point in the history
* Add TestingChangelog property to manifest, to get the most recent testing changelog
* Patch in database changelogs instead of always using the manifest ones for our generated PluginMaster
  • Loading branch information
goaaats committed Apr 15, 2024
1 parent fd00aee commit f6dd251
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 136 deletions.
10 changes: 8 additions & 2 deletions XLWebServices/Controllers/PlogonController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics;
using Discord;
using Microsoft.AspNetCore.Mvc;
using Sentry;
using XLWebServices.Data;
using XLWebServices.Data.Models;
using XLWebServices.Services;
Expand Down Expand Up @@ -247,11 +248,14 @@ private async ValueTask BuildCommitWorkItemAsync(CancellationToken token, IServi
var dbPlugin = db.Plugins.FirstOrDefault(x => x.InternalName == pluginInfo.InternalName);
if (dbPlugin != null)
{
if (!Version.TryParse(pluginInfo.Version, out var versionNum))
throw new Exception($"Could not parse plugin version ({pluginInfo.Version}");

var version = new PluginVersion
{
Plugin = dbPlugin,
Dip17Track = pluginInfo.Dip17Track,
Version = pluginInfo.Version,
Version = versionNum,
PrNumber = pluginInfo.PrNumber,
Changelog = pluginInfo.Changelog,
PublishedAt = DateTime.Now,
Expand All @@ -272,7 +276,7 @@ private async ValueTask BuildCommitWorkItemAsync(CancellationToken token, IServi
// Send discord notification
if (pluginInfo.Changelog == null || !shallExplicitlyHideChangelog)
{
var isOtherRepo = pluginInfo.Dip17Track != Dip17SystemDefine.MainTrack;
var isOtherRepo = pluginInfo.Dip17Track != Dip17SystemDefine.StableTrack;

var embed = new EmbedBuilder()
.WithTitle($"{manifest.Name} (v{pluginInfo.Version})")
Expand All @@ -286,12 +290,14 @@ private async ValueTask BuildCommitWorkItemAsync(CancellationToken token, IServi
}

await db.SaveChangesAsync(token);
await data.PostProcessD17Masters();

_logger.LogInformation("Committed {NumPlogons} in {Secs}s", staged.Count, stopwatch.Elapsed.TotalSeconds);
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not process plogon commit job");
SentrySdk.CaptureException(ex);
}
}

Expand Down
52 changes: 24 additions & 28 deletions XLWebServices/Controllers/PluginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public PluginController(ILogger<PluginController> logger, FallibleService<RedisS
}

[HttpGet("{internalName}")]
public async Task<IActionResult> Download(string internalName, [FromQuery(Name = "isTesting")] bool isTesting = false, [FromQuery(Name = "isDip17")] bool isDip17 = false)
public async Task<IActionResult> Download(string internalName,
[FromQuery(Name = "isTesting")] bool isTesting = false,
[FromQuery(Name = "isUpdate")] bool isUpdate = false,
[FromQuery(Name = "isDip17")] bool isDip17 = false)
{
if (this.pluginData.HasFailed&& this.pluginData.Get()?.PluginMaster == null)
return StatusCode(500, "Precondition failed");
Expand All @@ -52,34 +55,27 @@ public async Task<IActionResult> Download(string internalName, [FromQuery(Name =
if (manifest == null)
return BadRequest("Invalid plugin");

DownloadsOverTime.WithLabels(internalName.ToLower(), isTesting.ToString()).Inc();

if (!this.redis.HasFailed)
if (!isUpdate)
{
await this.redis.Get()!.IncrementCount(internalName);
await this.redis.Get()!.IncrementCount(RedisCumulativeKey);
DownloadsOverTime.WithLabels(internalName.ToLower(), isTesting.ToString()).Inc();

if (!this.redis.HasFailed)
{
await this.redis.Get()!.IncrementCount(internalName);
await this.redis.Get()!.IncrementCount(RedisCumulativeKey);
}
}

if (isDip17)
{
const string githubPath = "https://raw.githubusercontent.com/goatcorp/PluginDistD17/{0}/{1}/{2}/latest.zip";
var folder = isTesting ? "testing-live" : "stable";
var version = isTesting && manifest.TestingAssemblyVersion != null ? manifest.TestingAssemblyVersion : manifest.AssemblyVersion;
var cachedFile = await this.cache.CacheFile(internalName, $"{version}-{folder}-{this.pluginData.Get()!.RepoShaDip17}",
string.Format(githubPath, this.pluginData.Get()!.RepoShaDip17, folder, internalName), FileCacheService.CachedFile.FileCategory.Plugin);
if (!isDip17)
return BadRequest("Legacy plugin downloads are no longer available");

return new RedirectResult($"{this.configuration["HostedUrl"]}/File/Get/{cachedFile.Id}");
}
else
{
const string githubPath = "https://raw.githubusercontent.com/goatcorp/DalamudPlugins/{0}/{1}/{2}/latest.zip";
var folder = isTesting ? "testing" : "plugins";
var version = isTesting && manifest.TestingAssemblyVersion != null ? manifest.TestingAssemblyVersion : manifest.AssemblyVersion;
var cachedFile = await this.cache.CacheFile(internalName, $"{version}-{folder}-{this.pluginData.Get()!.RepoSha}",
string.Format(githubPath, this.pluginData.Get()!.RepoSha, folder, internalName), FileCacheService.CachedFile.FileCategory.Plugin);
const string githubPath = "https://raw.githubusercontent.com/goatcorp/PluginDistD17/{0}/{1}/{2}/latest.zip";
var folder = isTesting ? "testing-live" : "stable";
var version = isTesting && manifest.TestingAssemblyVersion != null ? manifest.TestingAssemblyVersion : manifest.AssemblyVersion;
var cachedFile = await this.cache.CacheFile(internalName, $"{version}-{folder}-{this.pluginData.Get()!.RepoShaDip17}",
string.Format(githubPath, this.pluginData.Get()!.RepoShaDip17, folder, internalName), FileCacheService.CachedFile.FileCategory.Plugin);

return new RedirectResult($"{this.configuration["HostedUrl"]}/File/Get/{cachedFile.Id}");
}
return new RedirectResult($"{this.configuration["HostedUrl"]}/File/Get/{cachedFile.Id}");
}

[HttpGet]
Expand Down Expand Up @@ -115,7 +111,9 @@ public IActionResult PluginMaster([FromQuery] bool proxy = true, [FromQuery] int
pluginMaster = this.pluginData.Get()!.PluginMaster;
}

pluginMaster ??= Array.Empty<PluginManifest>();
if (pluginMaster == null)
return StatusCode(500, "No plugin data");

if (minApiLevel > 0)
{
pluginMaster = pluginMaster.Where(manifest => manifest.DalamudApiLevel >= minApiLevel).ToArray();
Expand Down Expand Up @@ -160,7 +158,7 @@ public IActionResult History(string internalName, [FromQuery(Name = "track")] st

if (string.IsNullOrEmpty(dip17Track))
{
dip17Track = Dip17SystemDefine.MainTrack;
dip17Track = Dip17SystemDefine.StableTrack;
}

var dbPlugin = _dbContext.Plugins.Include(x => x.VersionHistory).FirstOrDefault(x => x.InternalName == internalName);
Expand Down Expand Up @@ -202,7 +200,6 @@ public async Task<IActionResult> Meta()
NumPlugins = this.pluginData.Get()!.PluginMaster!.Count,
LastUpdate = this.pluginData.Get()!.LastUpdate,
CumulativeDownloads = await this.redis.Get()!.GetCount(RedisCumulativeKey),
Sha = this.pluginData.Get()!.RepoSha,
Dip17Sha = this.pluginData.Get()!.RepoShaDip17,
});
}
Expand All @@ -212,7 +209,6 @@ public class PluginMeta
public int NumPlugins { get; init; }
public long CumulativeDownloads { get; init; }
public DateTime LastUpdate { get; init; }
public string Sha { get; init; }
public string Dip17Sha { get; init; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace XLWebServices.Data.Migrations
{
/// <inheritdoc />
public partial class VersionStringToSystemVersion : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{

}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{

}
}
}
2 changes: 1 addition & 1 deletion XLWebServices/Data/Models/PluginVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class PluginVersion
public Guid Id { get; set; }

public Plugin Plugin { get; set; }
public string Version { get; set; }
public Version Version { get; set; }
public string Dip17Track { get; set; }
public string? Changelog { get; set; }
public DateTime PublishedAt { get; set; }
Expand Down
6 changes: 6 additions & 0 deletions XLWebServices/Data/WsDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.WithOne(e => e.Plugin)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);

modelBuilder.Entity<PluginVersion>()
.Property(x => x.Version)
.HasConversion(
v => v.ToString(),
v => Version.Parse(v));
}
}
2 changes: 1 addition & 1 deletion XLWebServices/Dip17SystemDefine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace XLWebServices;

public static class Dip17SystemDefine
{
public const string MainTrack = "stable";
public const string StableTrack = "stable";
public const string ChangelogMarkerHide = "nofranz";
}
Loading

0 comments on commit f6dd251

Please sign in to comment.