From 3308161e35594400c015f9cdce28cd0469fde726 Mon Sep 17 00:00:00 2001 From: 13xforever Date: Tue, 27 Aug 2019 18:56:54 +0500 Subject: [PATCH] link issues mentioned in update description just like on github --- CompatBot/EventHandlers/GithubLinksHandler.cs | 2 +- .../ResultFormatters/UpdateInfoFormatter.cs | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CompatBot/EventHandlers/GithubLinksHandler.cs b/CompatBot/EventHandlers/GithubLinksHandler.cs index cf66d4db..377d1ccd 100644 --- a/CompatBot/EventHandlers/GithubLinksHandler.cs +++ b/CompatBot/EventHandlers/GithubLinksHandler.cs @@ -13,7 +13,7 @@ namespace CompatBot.EventHandlers internal static class GithubLinksHandler { private const RegexOptions DefaultOptions = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.ExplicitCapture; - private static readonly Regex IssueMention = new Regex(@"(\b(issue|pr|pull[ \-]request|bug)\s*#?\s*(?\d+)|(\W|^)#(?\d{4}))\b", DefaultOptions); + public static readonly Regex IssueMention = new Regex(@"(?\b(issue|pr|pull[ \-]request|bug)\s*#?\s*(?\d+)|(\W|^)#(?\d{4}))\b", DefaultOptions); private static readonly Regex IssueLink = new Regex(@"github.com/RPCS3/rpcs3/issues/(?\d+)", DefaultOptions); private static readonly GithubClient.Client Client = new GithubClient.Client(); diff --git a/CompatBot/Utils/ResultFormatters/UpdateInfoFormatter.cs b/CompatBot/Utils/ResultFormatters/UpdateInfoFormatter.cs index a7514f17..28271bdd 100644 --- a/CompatBot/Utils/ResultFormatters/UpdateInfoFormatter.cs +++ b/CompatBot/Utils/ResultFormatters/UpdateInfoFormatter.cs @@ -1,8 +1,10 @@ using System; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using CompatApiClient.POCOs; +using CompatBot.EventHandlers; using DSharpPlus.Entities; using GithubClient.POCOs; @@ -41,7 +43,26 @@ namespace CompatBot.Utils.ResultFormatters if (currentPr > 0 && currentPr != latestPr) currentPrInfo = await githubClient.GetPrInfoAsync(currentPr.Value, Config.Cts.Token).ConfigureAwait(false); } - builder = builder ?? new DiscordEmbedBuilder {Title = prDesc, Url = url, Description = latestPrInfo?.Title, Color = Config.Colors.DownloadLinks}; + var desc = latestPrInfo?.Title; + if (!string.IsNullOrEmpty(desc) + && GithubLinksHandler.IssueMention.Matches(desc) is MatchCollection matches + && matches.Any()) + { + foreach (Match m in matches) + { + if (m.Groups["issue_mention"]?.Value is string str && !string.IsNullOrEmpty(str)) + { + var num = m.Groups["number"].Value; + if (string.IsNullOrEmpty(num)) + num = m.Groups["also_number"].Value; + if (string.IsNullOrEmpty(num)) + continue; + + desc = desc.Replace(str, $"[{str}](https://github.com/RPCS3/rpcs3/issues/{num})"); + } + } + } + builder = builder ?? new DiscordEmbedBuilder {Title = prDesc, Url = url, Description = desc, Color = Config.Colors.DownloadLinks}; var currentCommit = currentPrInfo?.MergeCommitSha; var latestCommit = latestPrInfo?.MergeCommitSha; var currentAppveyorBuild = await appveyorClient.GetMasterBuildAsync(currentCommit, currentPrInfo?.MergedAt, Config.Cts.Token).ConfigureAwait(false);