shrink full links in issue descriptions

This commit is contained in:
13xforever 2019-11-19 18:20:17 +05:00
parent ed3eae728f
commit 0a8ebba7af
2 changed files with 8 additions and 2 deletions

View File

@ -13,7 +13,7 @@ namespace CompatBot.EventHandlers
internal static class GithubLinksHandler
{
private const RegexOptions DefaultOptions = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.ExplicitCapture;
public static readonly Regex IssueMention = new Regex(@"(?<issue_mention>\b(issue|pr|pull[ \-]request|bug)\s*#?\s*(?<number>\d+)|(?=\W|^)#(?<also_number>\d{4}))\b", DefaultOptions);
public static readonly Regex IssueMention = new Regex(@"(?<issue_mention>\b(issue|pr|pull[ \-]request|bug)\s*#?\s*(?<number>\d+)|(?=\W|^)#(?<also_number>\d{4})|(https?://)github.com/RPCS3/rpcs3/(issues|pull)/(?<another_number>\d+))\b", DefaultOptions);
private static readonly Regex IssueLink = new Regex(@"github.com/RPCS3/rpcs3/issues/(?<number>\d+)", DefaultOptions);
private static readonly GithubClient.Client Client = new GithubClient.Client();

View File

@ -58,13 +58,19 @@ namespace CompatBot.Utils.ResultFormatters
{
if (m.Groups["issue_mention"]?.Value is string str && !string.IsNullOrEmpty(str))
{
var name = str;
var num = m.Groups["number"].Value;
if (string.IsNullOrEmpty(num))
num = m.Groups["also_number"].Value;
if (string.IsNullOrEmpty(num))
{
num = m.Groups["another_number"].Value;
name = "#" + num;
}
if (string.IsNullOrEmpty(num))
continue;
desc = desc.Replace(str, $"[{str}](https://github.com/RPCS3/rpcs3/issues/{num})");
desc = desc.Replace(str, $"[{name}](https://github.com/RPCS3/rpcs3/issues/{num})");
}
}
}