Skip to content

Commit

Permalink
Changelog categories
Browse files Browse the repository at this point in the history
This means we get ADMIN CHANGELOGS
  • Loading branch information
PJB3005 committed Jan 14, 2024
1 parent bf34fbf commit edbca25
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 138 deletions.
297 changes: 228 additions & 69 deletions SS14.Changelog.Tests/ChangelogParseTest.cs
Original file line number Diff line number Diff line change
@@ -1,97 +1,128 @@
using System;
using System.Diagnostics.CodeAnalysis;
using NUnit.Framework;
using SS14.Changelog.Configuration;
using SS14.Changelog.Controllers;

namespace SS14.Changelog.Tests
{
[Parallelizable(ParallelScope.All)]
[TestFixture]
// NUnit assertion is bugged.
[SuppressMessage("Assertion", "NUnit2022:Missing property required for constraint")]
public class ChangelogParseTest
{
[Test]
public void Test()
{
const string text = @"
Did stuff!
const string text = """
Did stuff!
:cl: Ev1__l P-JB2323
- add: Did the thing
- remove: Removed the thing
- fix: A
- bugfix: B
- bug: C
";
:cl: Ev1__l P-JB2323
- add: Did the thing
- remove: Removed the thing
- fix: A
- bugfix: B
- bug: C
""";

var time = new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero);
var pr = new GHPullRequest(true, text, new GHUser("PJB"), time, new GHPullRequestBase("master"), 123, "https://www.example.com");
var parsed = WebhookController.ParsePRBody(pr);

Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Author, Is.EqualTo("Ev1__l P-JB2323"));
Assert.That(parsed.Time, Is.EqualTo(time));
Assert.That(parsed.HtmlUrl, Is.EqualTo("https://www.example.com"));
Assert.That(parsed.Changes, Is.EquivalentTo(new[]
var pr = new GHPullRequest(true, text, new GHUser("PJB"), time, new GHPullRequestBase("master"), 123,
"https://www.example.com");
var parsed = WebhookController.ParsePRBody(pr, new ChangelogConfig());

Assert.Multiple(() =>
{
(ChangelogEntryType.Add, "Did the thing"),
(ChangelogEntryType.Remove, "Removed the thing"),
(ChangelogEntryType.Fix, "A"),
(ChangelogEntryType.Fix, "B"),
(ChangelogEntryType.Fix, "C"),
}));
Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Author, Is.EqualTo("Ev1__l P-JB2323"));
Assert.That(parsed.Time, Is.EqualTo(time));
Assert.That(parsed.HtmlUrl, Is.EqualTo("https://www.example.com"));
Assert.That(parsed.Categories, Has.Length.EqualTo(1));
Assert.That(parsed.Categories, Has.One
.Property(nameof(ChangelogData.CategoryData.Category)).EqualTo(ChangelogData.MainCategory)
.And.Property(nameof(ChangelogData.CategoryData.Changes)).EquivalentTo(new ChangelogData.Change[]
{
new(ChangelogData.ChangeType.Add, "Did the thing"),
new(ChangelogData.ChangeType.Remove, "Removed the thing"),
new(ChangelogData.ChangeType.Fix, "A"),
new(ChangelogData.ChangeType.Fix, "B"),
new(ChangelogData.ChangeType.Fix, "C"),
}));
});
}

[Test]
public void TestWithoutName()
{
const string text = @"
Did stuff!
const string text = """
Did stuff!
:cl:
- add: Did the thing
- remove: Removed the thing
";
:cl:
- add: Did the thing
- remove: Removed the thing
""";

var time = new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero);
var pr = new GHPullRequest(true, text, new GHUser("Swept"), time, new GHPullRequestBase("master"), 123, "https://www.example.com");
var parsed = WebhookController.ParsePRBody(pr);

Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Author, Is.EqualTo("Swept"));
Assert.That(parsed.Time, Is.EqualTo(time));
Assert.That(parsed.HtmlUrl, Is.EqualTo("https://www.example.com"));
Assert.That(parsed.Changes, Is.EquivalentTo(new[]
var pr = new GHPullRequest(true, text, new GHUser("Swept"), time, new GHPullRequestBase("master"), 123,
"https://www.example.com");
var parsed = WebhookController.ParsePRBody(pr, new ChangelogConfig());

Assert.Multiple(() =>
{
(ChangelogEntryType.Add, "Did the thing"),
(ChangelogEntryType.Remove, "Removed the thing"),
}));
Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Author, Is.EqualTo("Swept"));
Assert.That(parsed.Time, Is.EqualTo(time));
Assert.That(parsed.HtmlUrl, Is.EqualTo("https://www.example.com"));
Assert.That(parsed.Categories, Has.Length.EqualTo(1));
Assert.That(parsed.Categories, Has.One
.Property(nameof(ChangelogData.CategoryData.Category)).EqualTo(ChangelogData.MainCategory)
.And.Property(nameof(ChangelogData.CategoryData.Changes)).EquivalentTo(new ChangelogData.Change[]
{
new(ChangelogData.ChangeType.Add, "Did the thing"),
new(ChangelogData.ChangeType.Remove, "Removed the thing"),
}));
});
}

[Test]
public void TestComment()
{
const string text = @"
Did stuff!
const string text = """
<!-- The :cl: symbol
-->
Did stuff!
:cl:
- add: Did the thing
- remove: Removed the thing
";
<!-- The :cl: symbol
-->
:cl:
- add: Did the thing
- remove: Removed the thing
""";

var time = new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero);
var pr = new GHPullRequest(true, text, new GHUser("Swept"), time, new GHPullRequestBase("master"), 123, "https://www.example.com");
var parsed = WebhookController.ParsePRBody(pr);

Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Author, Is.EqualTo("Swept"));
Assert.That(parsed.Time, Is.EqualTo(time));
Assert.That(parsed.HtmlUrl, Is.EqualTo("https://www.example.com"));
Assert.That(parsed.Changes, Is.EquivalentTo(new[]
var pr = new GHPullRequest(true, text, new GHUser("Swept"), time, new GHPullRequestBase("master"), 123,
"https://www.example.com");
var parsed = WebhookController.ParsePRBody(pr, new ChangelogConfig());

Assert.Multiple(() =>
{
(ChangelogEntryType.Add, "Did the thing"),
(ChangelogEntryType.Remove, "Removed the thing"),
}));
Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Author, Is.EqualTo("Swept"));
Assert.That(parsed.Time, Is.EqualTo(time));
Assert.That(parsed.HtmlUrl, Is.EqualTo("https://www.example.com"));
Assert.That(parsed.Categories, Has.Length.EqualTo(1));
Assert.That(parsed.Categories, Has.One
.Property(nameof(ChangelogData.CategoryData.Category)).EqualTo(ChangelogData.MainCategory)
.And.Property(nameof(ChangelogData.CategoryData.Changes)).EquivalentTo(new ChangelogData.Change[]
{
new(ChangelogData.ChangeType.Add, "Did the thing"),
new(ChangelogData.ChangeType.Remove, "Removed the thing"),
}));
});
}

[Test]
Expand All @@ -101,17 +132,145 @@ public void TestBroke()
"Makes it possible to repair things with a welder.\r\n\r\n**Changelog**\r\n:cl: AJCM\r\n- add: Makes gravity generator and windows repairable with a lit welding tool \r\n\r\n";

var time = new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero);
var pr = new GHPullRequest(true, text, new GHUser("AJCM-Git"), time, new GHPullRequestBase("master"), 123, "https://www.example.com");
var parsed = WebhookController.ParsePRBody(pr);

Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Author, Is.EqualTo("AJCM"));
Assert.That(parsed.Time, Is.EqualTo(time));
Assert.That(parsed.HtmlUrl, Is.EqualTo("https://www.example.com"));
Assert.That(parsed.Changes, Is.EquivalentTo(new[]
var pr = new GHPullRequest(true, text, new GHUser("AJCM-Git"), time, new GHPullRequestBase("master"), 123,
"https://www.example.com");
var parsed = WebhookController.ParsePRBody(pr, new ChangelogConfig());

Assert.Multiple(() =>
{
Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Author, Is.EqualTo("AJCM"));
Assert.That(parsed.Time, Is.EqualTo(time));
Assert.That(parsed.HtmlUrl, Is.EqualTo("https://www.example.com"));
Assert.That(parsed.Categories, Has.Length.EqualTo(1));
Assert.That(parsed.Categories, Has.One
.Property(nameof(ChangelogData.CategoryData.Category)).EqualTo(ChangelogData.MainCategory)
.And.Property(nameof(ChangelogData.CategoryData.Changes)).EquivalentTo(new ChangelogData.Change[]
{
new(ChangelogData.ChangeType.Add, "Makes gravity generator and windows repairable with a lit welding tool"),
}));
});
}

[Test]
public void TestCategory()
{
const string text = """
Did stuff!
:cl:
ADMIN:
- add: Did the thing
- remove: Removed the thing
""";

var time = new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero);
var pr = new GHPullRequest(true, text, new GHUser("Swept"), time, new GHPullRequestBase("master"), 123,
"https://www.example.com");
var parsed = WebhookController.ParsePRBody(pr, new ChangelogConfig());

Assert.Multiple(() =>
{
Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Author, Is.EqualTo("Swept"));
Assert.That(parsed.Time, Is.EqualTo(time));
Assert.That(parsed.HtmlUrl, Is.EqualTo("https://www.example.com"));
Assert.That(parsed.Categories, Has.Length.EqualTo(1));
Assert.That(parsed.Categories, Has.One
.Property(nameof(ChangelogData.CategoryData.Category)).EqualTo(ChangelogData.MainCategory)
.And.Property(nameof(ChangelogData.CategoryData.Changes)).EquivalentTo(new ChangelogData.Change[]
{
new(ChangelogData.ChangeType.Add, "Did the thing"),
new(ChangelogData.ChangeType.Remove, "Removed the thing"),
}));
});
}

[Test]
public void TestCategoryMulti()
{
const string text = """
Did stuff!
:cl:
ADMIN:
- add: Did the thing
- remove: Removed the thing
MAIN:
- add: Did more thing
- remove: Removed more thing
ADMIN:
- fix: Fix the thing
""";

var time = new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero);
var pr = new GHPullRequest(true, text, new GHUser("Swept"), time, new GHPullRequestBase("master"), 123,
"https://www.example.com");
var parsed = WebhookController.ParsePRBody(pr, new ChangelogConfig { ExtraCategories = new []{"Admin"}});

Assert.Multiple(() =>
{
Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Author, Is.EqualTo("Swept"));
Assert.That(parsed.Time, Is.EqualTo(time));
Assert.That(parsed.HtmlUrl, Is.EqualTo("https://www.example.com"));
Assert.That(parsed.Categories, Has.Length.EqualTo(2));
Assert.That(parsed.Categories, Has.One
.Property(nameof(ChangelogData.CategoryData.Category)).EqualTo("Admin")
.And.Property(nameof(ChangelogData.CategoryData.Changes)).EquivalentTo(new ChangelogData.Change[]
{
new(ChangelogData.ChangeType.Add, "Did the thing"),
new(ChangelogData.ChangeType.Remove, "Removed the thing"),
new(ChangelogData.ChangeType.Fix, "Fix the thing"),
}));
Assert.That(parsed.Categories, Has.One
.Property(nameof(ChangelogData.CategoryData.Category)).EqualTo(ChangelogData.MainCategory)
.And.Property(nameof(ChangelogData.CategoryData.Changes)).EquivalentTo(new ChangelogData.Change[]
{
new(ChangelogData.ChangeType.Add, "Did more thing"),
new(ChangelogData.ChangeType.Remove, "Removed more thing"),
}));
});
}

[Test]
public void TestCategoryInvalid()
{
const string text = """
Did stuff!
:cl:
- add: Did the thing
- remove: Removed the thing
NOTACATEGORY:
- add: WOW
""";

var time = new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero);
var pr = new GHPullRequest(true, text, new GHUser("Swept"), time, new GHPullRequestBase("master"), 123,
"https://www.example.com");
var parsed = WebhookController.ParsePRBody(pr, new ChangelogConfig { ExtraCategories = new []{"Admin"}});

Assert.Multiple(() =>
{
(ChangelogEntryType.Add, "Makes gravity generator and windows repairable with a lit welding tool")
}));
Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Author, Is.EqualTo("Swept"));
Assert.That(parsed.Time, Is.EqualTo(time));
Assert.That(parsed.HtmlUrl, Is.EqualTo("https://www.example.com"));
Assert.That(parsed.Categories, Has.Length.EqualTo(1));
Assert.That(parsed.Categories, Has.One
.Property(nameof(ChangelogData.CategoryData.Category)).EqualTo(ChangelogData.MainCategory)
.And.Property(nameof(ChangelogData.CategoryData.Changes)).EquivalentTo(new ChangelogData.Change[]
{
new(ChangelogData.ChangeType.Add, "Did the thing"),
new(ChangelogData.ChangeType.Remove, "Removed the thing"),
new(ChangelogData.ChangeType.Add, "WOW"),
}));
});
}
}
}
28 changes: 17 additions & 11 deletions SS14.Changelog/ChangelogData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@ namespace SS14.Changelog
{
public sealed record ChangelogData
{
public ChangelogData(string author, ImmutableArray<(ChangelogEntryType, string)> changes, DateTimeOffset time)
public const string MainCategory = "Main";

public ChangelogData(string author, ImmutableArray<CategoryData> categories, DateTimeOffset time)
{
Author = author;
Changes = changes;
Categories = categories;
Time = time;
}

public string Author { get; }
public ImmutableArray<(ChangelogEntryType, string)> Changes { get; }
public ImmutableArray<CategoryData> Categories { get; }
public DateTimeOffset Time { get; }
public int Number { get; init; }
public required string HtmlUrl { get; init; }
}

public enum ChangelogEntryType
{
Add,
Remove,
Fix,
Tweak

public sealed record CategoryData(string Category, ImmutableArray<Change> Changes);

public record struct Change(ChangeType Type, string Message);

public enum ChangeType
{
Add,
Remove,
Fix,
Tweak
}
}
}
Loading

0 comments on commit edbca25

Please sign in to comment.