diff --git a/osu.Game.Rulesets.Karaoke/Overlays/Changelog/ChangeLogMarkdownContainer.cs b/osu.Game.Rulesets.Karaoke/Overlays/Changelog/ChangeLogMarkdownContainer.cs index c1ce7c354..5e4110134 100644 --- a/osu.Game.Rulesets.Karaoke/Overlays/Changelog/ChangeLogMarkdownContainer.cs +++ b/osu.Game.Rulesets.Karaoke/Overlays/Changelog/ChangeLogMarkdownContainer.cs @@ -44,12 +44,17 @@ protected override void AddLinkText(string text, LinkInline linkInline) var pullRequestInfo = ChangelogPullRequestInfo.GetPullRequestInfoFromLink(text, linkInline.Url); - if (pullRequestInfo == null) + if (pullRequestInfo != null) { - base.AddLinkText(text, linkInline); + addPullRequestInfo(pullRequestInfo); return; } + base.AddLinkText(text, linkInline); + } + + private void addPullRequestInfo(ChangelogPullRequestInfo pullRequestInfo) + { var pullRequests = pullRequestInfo.PullRequests; var users = pullRequestInfo.Users; @@ -57,14 +62,15 @@ protected override void AddLinkText(string text, LinkInline linkInline) { AddText("("); - foreach (var pullRequest in pullRequests) + for (int index = 0; index < pullRequests.Length; index++) { - AddDrawable(new OsuMarkdownLinkText($"{text}#{pullRequest.Number}", new LinkInline + var pullRequest = pullRequests[index]; + AddDrawable(new OsuMarkdownLinkText($"{pullRequestInfo.RepoName}#{pullRequest.Number}", new LinkInline { Url = pullRequest.Url, })); - if (pullRequest != pullRequests.LastOrDefault()) + if (index != pullRequests.Length - 1) AddText(", "); } @@ -81,7 +87,7 @@ protected override void AddLinkText(string text, LinkInline linkInline) }); AddDrawable(new UserLinkText(user.UserName, new LinkInline { - Url = user.UserUrl, + Url = user.Url, }) { Scale = textScale, diff --git a/osu.Game.Rulesets.Karaoke/Overlays/Changelog/ChangelogPullRequestInfo.cs b/osu.Game.Rulesets.Karaoke/Overlays/Changelog/ChangelogPullRequestInfo.cs index cab7994bc..7df1e8142 100644 --- a/osu.Game.Rulesets.Karaoke/Overlays/Changelog/ChangelogPullRequestInfo.cs +++ b/osu.Game.Rulesets.Karaoke/Overlays/Changelog/ChangelogPullRequestInfo.cs @@ -22,22 +22,35 @@ public class ChangelogPullRequestInfo { "font-package", "https://github.com/karaoke-dev/osu-framework-font/" }, }; - public PullRequestInfo[] PullRequests { get; set; } = Array.Empty(); + public string RepoName { get; init; } = string.Empty; - public UserInfo[] Users { get; set; } = Array.Empty(); + public PullRequestInfo[] PullRequests { get; init; } = Array.Empty(); - public class PullRequestInfo + public UserInfo[] Users { get; init; } = Array.Empty(); + + public readonly struct PullRequestInfo { - public int Number { get; set; } + public PullRequestInfo(string repoName, int number) + { + Number = number; + Url = new Uri(new Uri(repo_urls[repoName]), $"pull/{number}").AbsoluteUri; + } + + public int Number { get; } = 0; - public string Url { get; set; } = string.Empty; + public string Url { get; } = string.Empty; } - public class UserInfo + public readonly struct UserInfo { - public string UserName { get; set; } = string.Empty; + public UserInfo(string useName) + { + UserName = useName; + } + + public string UserName { get; } = string.Empty; - public string UserUrl => $"https://github.com/{UserName}"; + public string Url => $"https://github.com/{UserName}"; } /// @@ -50,12 +63,12 @@ public class UserInfo /// @andy840119
/// @andy@andy840119 /// - /// Link text - /// Link url + /// Link text + /// Link url /// - public static ChangelogPullRequestInfo? GetPullRequestInfoFromLink(string text, string url) + public static ChangelogPullRequestInfo? GetPullRequestInfoFromLink(string repo, string info) { - if (!repo_urls.ContainsKey(text)) + if (!repo_urls.ContainsKey(repo)) return null; const string pull_request_key = "pull_request"; @@ -63,7 +76,7 @@ public class UserInfo const string pull_request_regex = $"#(?<{pull_request_key}>[0-9]+)|@(?<{username_key}>[0-9A-z]+)"; // note: should have at least one pr number or one username, - var result = Regex.Matches(url, pull_request_regex, RegexOptions.IgnoreCase); + var result = Regex.Matches(info, pull_request_regex, RegexOptions.IgnoreCase); if (!result.Any()) return null; @@ -77,21 +90,9 @@ public class UserInfo return new ChangelogPullRequestInfo { - PullRequests = prs.Select(x => generatePullRequestInfo(repo_urls[text], x)).ToArray(), - Users = usernames.Select(generateUserInfo).ToArray(), + RepoName = repo, + PullRequests = prs.Select(pr => new PullRequestInfo(repo, int.Parse(pr))).ToArray(), + Users = usernames.Select(userName => new UserInfo(userName)).ToArray(), }; - - static PullRequestInfo generatePullRequestInfo(string url, string pr) => - new() - { - Number = int.Parse(pr), - Url = new Uri(new Uri(url), $"pull/{pr}").AbsoluteUri, - }; - - static UserInfo generateUserInfo(string username) => - new() - { - UserName = username, - }; } }