-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2164 from andy840119/refactor-the-changelog-again
Refactor the changelog again.
- Loading branch information
Showing
16 changed files
with
262 additions
and
136 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
osu.Game.Rulesets.Karaoke.Tests/Overlays/Changelog/ChangelogPullRequestInfoTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Game.Rulesets.Karaoke.Overlays.Changelog; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Overlays.Changelog; | ||
|
||
public class ChangelogPullRequestInfoTest | ||
{ | ||
[TestCase("#2152@andy840119", new[] { 2152 }, new[] { "andy840119" })] | ||
[TestCase("#2152", new[] { 2152 }, new string[] { })] | ||
[TestCase("@andy840119", new int[] { }, new[] { "andy840119" })] | ||
[TestCase("#2152#2153", new[] { 2152, 2153 }, new string[] { })] | ||
[TestCase("#2152#2152", new[] { 2152 }, new string[] { })] | ||
[TestCase("@andy@andy840119", new int[] { }, new[] { "andy", "andy840119" })] | ||
[TestCase("@andy840119@andy840119", new int[] { }, new[] { "andy840119" })] | ||
[TestCase("https://raw.githubusercontent.com/karaoke-dev/karaoke-dev.github.io/master/content/changelog/2023.1212/#2152@andy840119", new[] { 2152 }, new[] { "andy840119" })] // the actual data that will be get in this method. | ||
public void TestGetPullRequestInfoFromLink(string url, int[] expectedPrs, string[] expectedUserNames) | ||
{ | ||
var result = ChangelogPullRequestInfo.GetPullRequestInfoFromLink("karaoke", url)!; | ||
|
||
Assert.AreEqual(expectedPrs, result.PullRequests.Select(x => x.Number)); | ||
Assert.AreEqual(expectedUserNames, result.Users.Select(x => x.UserName)); | ||
} | ||
|
||
[TestCase("unknown_repo", "#2152@andy840119")] // "unknown_repo" does not in the repo list. | ||
[TestCase("karaoke", "")] // there's no pr number or username. | ||
[TestCase("karaoke", "hello")] // invalid pr number or username. | ||
[TestCase("karaoke", "#aaa")] // invalid pr number. | ||
public void TestTestGetPullRequestInfoFromLinkWithNull(string link, string url) | ||
{ | ||
var result = ChangelogPullRequestInfo.GetPullRequestInfoFromLink(link, url); | ||
Assert.IsNull(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
osu.Game.Rulesets.Karaoke/Online/API/Requests/ChangelogRequestUtils.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using Octokit; | ||
using osu.Game.Rulesets.Karaoke.Extensions; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Online.API.Requests; | ||
|
||
public static class ChangelogRequestUtils | ||
{ | ||
public const string ORGANIZATION_NAME = "karaoke-dev"; | ||
|
||
private const string project_name = $"{ORGANIZATION_NAME}.github.io"; | ||
private const string branch_name = "master"; | ||
private const string changelog_path = "content/changelog"; | ||
|
||
public static Task<IReadOnlyList<RepositoryContent>> GetAllChangelogs(IGitHubClient client) | ||
{ | ||
return client | ||
.Repository | ||
.Content | ||
.GetAllContents(ORGANIZATION_NAME, project_name, changelog_path); | ||
} | ||
|
||
public static string GetDocumentUrl(RepositoryContent content) | ||
=> $"https://raw.githubusercontent.com/{ORGANIZATION_NAME}/{project_name}/{branch_name}/{content.Path}/"; | ||
|
||
public static string GetRootUrl(RepositoryContent content) | ||
=> content.HtmlUrl; | ||
|
||
public static string GetVersion(RepositoryContent content) | ||
=> content.Name; | ||
|
||
public static DateTimeOffset GetPublishDateFromName(RepositoryContent content) | ||
{ | ||
string? name = content.Name; | ||
var regex = new Regex("(?<year>[-0-9]+).(?<month>[-0-9]{2})(?<day>[-0-9]{2})"); | ||
var result = regex.Match(name); | ||
if (!result.Success) | ||
return DateTimeOffset.MaxValue; | ||
|
||
int year = result.GetGroupValue<int>("year"); | ||
int month = result.GetGroupValue<int>("month"); | ||
int day = result.GetGroupValue<int>("day"); | ||
|
||
return new DateTimeOffset(new DateTime(year, month, day)); | ||
} | ||
|
||
public static async Task<string> GetChangelogContent(IGitHubClient client, string version) | ||
{ | ||
string changeLogPath = $"{changelog_path}/{version}/index.md"; | ||
byte[]? content = await client | ||
.Repository | ||
.Content | ||
.GetRawContent(ORGANIZATION_NAME, project_name, changeLogPath) | ||
.ConfigureAwait(false); | ||
|
||
// convert the content to a string | ||
return System.Text.Encoding.UTF8.GetString(content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using Octokit; | ||
using osu.Framework.Extensions.IEnumerableExtensions; | ||
using osu.Game.Rulesets.Karaoke.Extensions; | ||
using osu.Game.Rulesets.Karaoke.Online.API.Requests.Responses; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Online.API.Requests; | ||
|
||
public class GetChangelogRequest : GithubChangeLogAPIRequest<APIChangelogIndex> | ||
public class GetChangelogRequest : GithubAPIRequest<APIChangelogIndex> | ||
{ | ||
public GetChangelogRequest() | ||
: base(ChangelogRequestUtils.ORGANIZATION_NAME) | ||
{ | ||
} | ||
|
||
protected override async Task<APIChangelogIndex> Perform(IGitHubClient client) | ||
{ | ||
var builds = await getAllBuilds(client).ConfigureAwait(false); | ||
|
@@ -31,11 +33,7 @@ protected override async Task<APIChangelogIndex> Perform(IGitHubClient client) | |
|
||
private static async Task<List<APIChangelogBuild>> getAllBuilds(IGitHubClient client) | ||
{ | ||
var reposAscending = await client | ||
.Repository | ||
.Content | ||
.GetAllContents(ORGANIZATION_NAME, PROJECT_NAME, CHANGELOG_PATH) | ||
.ConfigureAwait(false); | ||
var reposAscending = await ChangelogRequestUtils.GetAllChangelogs(client).ConfigureAwait(false); | ||
|
||
var builds = reposAscending | ||
.Reverse() | ||
|
@@ -57,34 +55,17 @@ private static APIChangelogBuild createBuild(RepositoryContent content) | |
{ | ||
return new APIChangelogBuild | ||
{ | ||
DocumentUrl = getDocumentUrl(content.Path), | ||
RootUrl = content.HtmlUrl, | ||
Version = content.Name, | ||
PublishedAt = getPublishDateFromName(content.Name), | ||
DocumentUrl = ChangelogRequestUtils.GetDocumentUrl(content), | ||
RootUrl = ChangelogRequestUtils.GetRootUrl(content), | ||
Version = ChangelogRequestUtils.GetVersion(content), | ||
PublishedAt = ChangelogRequestUtils.GetPublishDateFromName(content), | ||
}; | ||
|
||
static DateTimeOffset getPublishDateFromName(string name) | ||
{ | ||
var regex = new Regex("(?<year>[-0-9]+).(?<month>[-0-9]{2})(?<day>[-0-9]{2})"); | ||
var result = regex.Match(name); | ||
if (!result.Success) | ||
return DateTimeOffset.MaxValue; | ||
|
||
int year = result.GetGroupValue<int>("year"); | ||
int month = result.GetGroupValue<int>("month"); | ||
int day = result.GetGroupValue<int>("day"); | ||
|
||
return new DateTimeOffset(new DateTime(year, month, day)); | ||
} | ||
|
||
string getDocumentUrl(string path) | ||
=> $"https://raw.githubusercontent.com/{ORGANIZATION_NAME}/{PROJECT_NAME}/{BRANCH_NAME}/{path}/"; | ||
} | ||
|
||
private static async Task<APIChangelogBuild> createPreviewBuild(IGitHubClient client, APIChangelogBuild originBuild) | ||
{ | ||
string contentString = await GetChangelogContent(client, originBuild.Version).ConfigureAwait(false); | ||
return CreateBuildWithContent(originBuild, contentString); | ||
string contentString = await ChangelogRequestUtils.GetChangelogContent(client, originBuild.Version).ConfigureAwait(false); | ||
return originBuild.CreateBuildWithContent(contentString); | ||
} | ||
|
||
private static int[] generateYears(IEnumerable<APIChangelogBuild> builds) | ||
|
51 changes: 0 additions & 51 deletions
51
osu.Game.Rulesets.Karaoke/Online/API/Requests/GithubChangeLogAPIRequest.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.