Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update changelog system to be datetime based and merge all files #75

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions Content.Client/Changelog/ChangelogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Content.Shared.CCVar;
using Robust.Shared.Configuration;
Expand All @@ -25,8 +26,8 @@ public sealed partial class ChangelogManager
[Dependency] private readonly IConfigurationManager _configManager = default!;

public bool NewChangelogEntries { get; private set; }
public int LastReadId { get; private set; }
public int MaxId { get; private set; }
public DateTime LastReadTime { get; private set; } // Modified, see EOF
public DateTime MaxTime { get; private set; } // Modified, see EOF

public event Action? NewChangelogEntriesChanged;

Expand All @@ -35,17 +36,17 @@ public sealed partial class ChangelogManager
/// stores the new ID to disk and clears <see cref="NewChangelogEntries"/>.
/// </summary>
/// <remarks>
/// <see cref="LastReadId"/> is NOT cleared
/// <see cref="LastReadTime"/> is NOT cleared
/// since that's used in the changelog menu to show the "since you last read" bar.
/// </remarks>
public void SaveNewReadId()
{
NewChangelogEntries = false;
NewChangelogEntriesChanged?.Invoke();

using var sw = _resource.UserData.OpenWriteText(new ($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}"));
using var sw = _resource.UserData.OpenWriteText(new ($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}_datetime")); // Modified, see EOF

sw.Write(MaxId.ToString());
sw.Write(MaxTime.ToString("O")); // Modified, see EOF
}

public async void Initialize()
Expand All @@ -58,24 +59,46 @@ public async void Initialize()
return;
}

MaxId = changelog.Max(c => c.Id);
MaxTime = changelog.Max(c => c.Time); // Modified, see EOF

var path = new ResPath($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}");
if(_resource.UserData.TryReadAllText(path, out var lastReadIdText))
// Begin modified codeblock, see EOF
var path = new ResPath($"/changelog_last_seen_{_configManager.GetCVar(CCVars.ServerId)}_datetime");
if(_resource.UserData.TryReadAllText(path, out var lastReadTimeText))
{
LastReadId = int.Parse(lastReadIdText);
if (Regex.IsMatch(lastReadTimeText,
@"^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$"))
{
LastReadTime = DateTime.ParseExact(lastReadTimeText, "O", CultureInfo.InvariantCulture);
}
}

NewChangelogEntries = LastReadId < MaxId;
NewChangelogEntries = LastReadTime < MaxTime;
// End modified codeblock

NewChangelogEntriesChanged?.Invoke();
}

public Task<List<ChangelogEntry>> LoadChangelog()
// Begin modified codeblock, see EOF
public async Task<List<ChangelogEntry>> LoadChangelog()
{
var paths = _resource.ContentFindFiles("/Changelog/")
.Where(filePath => filePath.Extension == "yml")
.ToArray();

var result = new List<ChangelogEntry>();
foreach (var path in paths)
{
var changelog = await LoadChangelogFile(path);
result = result.Union(changelog).ToList();
}
return result.OrderBy(x => x.Time).ToList();
}

private Task<List<ChangelogEntry>> LoadChangelogFile(ResPath path) // end modified codeblock
{
return Task.Run(() =>
{
var yamlData = _resource.ContentFileReadYaml(new ("/Changelog/Changelog.yml"));
var yamlData = _resource.ContentFileReadYaml(path); // Modified, see EOF

if (yamlData.Documents.Count == 0)
return new List<ChangelogEntry>();
Expand Down Expand Up @@ -126,3 +149,7 @@ public enum ChangelogLineType
}
}
}


// This file was extensively modified to allow for datetime based changelogs instead of relying on IDs.
// This is because our IDs are much lower then Wizdens, and if we use their entries, the server will not properly show new changes
7 changes: 5 additions & 2 deletions Content.Client/Changelog/ChangelogWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ private async void PopulateChangelog()
.GroupBy(e => e.Time.ToLocalTime().Date)
.OrderByDescending(c => c.Key);

var hasRead = _changelog.MaxId <= _changelog.LastReadId;
var hasRead = _changelog.MaxTime <= _changelog.LastReadTime; // Modified, see EOF
foreach (var dayEntries in byDay)
{
var day = dayEntries.Key;

var groupedEntries = dayEntries
.GroupBy(c => (c.Author, Read: c.Id <= _changelog.LastReadId))
.GroupBy(c => (c.Author, Read: c.Time <= _changelog.LastReadTime)) // Modified, see EOF
.OrderBy(c => c.Key.Read)
.ThenBy(c => c.Key.Author);

Expand Down Expand Up @@ -203,3 +203,6 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
}
}
}

// This file was extensively modified to allow for datetime based changelogs instead of relying on IDs.
// This is because our IDs are much lower then Wizdens, and if we use their entries, the server will not properly show new changes
4 changes: 2 additions & 2 deletions Tools/actions_changelogs_since_last_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

DISCORD_WEBHOOK_URL = os.environ.get("DISCORD_WEBHOOK_URL")

CHANGELOG_FILE = "Resources/Changelog/Changelog.yml"
CHANGELOG_FILE = "Resources/Changelog/DeltaVChangelog.yml"

TYPES_TO_EMOJI = {
"Fix": "🐛",
Expand Down Expand Up @@ -130,4 +130,4 @@ def send_to_discord(entries: Iterable[ChangelogEntry]) -> None:
requests.post(DISCORD_WEBHOOK_URL, json=body)


main()
main()
Loading