Ejemplo n.º 1
0
        public static DiscordEmbedBuilder AsEmbed(this PrInfo prInfo)
        {
            var state      = prInfo.GetState();
            var stateLabel = state.state == null ? null : $"[{state.state}] ";
            var title      = $"{stateLabel}PR #{prInfo.Number} by {prInfo.User?.Login ?? "???"}";

            return(new DiscordEmbedBuilder {
                Title = title, Url = prInfo.HtmlUrl, Description = prInfo.Title, Color = state.color
            });
        }
Ejemplo n.º 2
0
        public static DiscordEmbedBuilder AsEmbed(this PrInfo prInfo)
        {
            (string, DiscordColor)state = prInfo.GetState();
            var stateLabel = state.Item1 == null ? null : $"[{state.Item1}] ";
            var pr         = $"{stateLabel}PR #{prInfo.Number} by {prInfo.User?.Login ?? "???"}";

            return(new DiscordEmbedBuilder {
                Title = pr, Url = prInfo.HtmlUrl, Description = prInfo.Title, Color = state.Item2
            });
        }
Ejemplo n.º 3
0
        public static (string state, DiscordColor color) GetState(this PrInfo prInfo)
        {
            if (prInfo.State == "open")
            {
                return("Open", Config.Colors.PrOpen);
            }

            if (prInfo.State == "closed")
            {
                if (prInfo.MergedAt.HasValue)
                {
                    return("Merged", Config.Colors.PrMerged);
                }

                return("Closed", Config.Colors.PrClosed);
            }

            return(null, Config.Colors.DownloadLinks);
        }
Ejemplo n.º 4
0
        public static async Task <DiscordEmbedBuilder> AsEmbedAsync(this UpdateInfo info, DiscordEmbedBuilder builder = null)
        {
            if ((info?.LatestBuild?.Windows?.Download ?? info?.LatestBuild?.Linux?.Download) == null)
            {
                return builder ?? new DiscordEmbedBuilder {
                           Title = "Error", Description = "Error communicating with the update API. Try again later.", Color = Config.Colors.Maintenance
                }
            }
            ;

            var    justAppend = builder != null;
            var    build      = info.LatestBuild;
            var    pr         = build?.Pr ?? "0";
            string url        = null;
            PrInfo prInfo     = null;

            if (!justAppend)
            {
                if (pr == "0")
                {
                    pr = "PR #???";
                }
                else
                {
                    url    = "https://github.com/RPCS3/rpcs3/pull/" + pr;
                    prInfo = await client.GetPrInfoAsync(pr, Config.Cts.Token).ConfigureAwait(false);

                    pr = $"PR #{pr} by {prInfo?.User?.Login ?? "???"}";
                }
            }
            builder = builder ?? new DiscordEmbedBuilder {
                Title = pr, Url = url, Description = prInfo?.Title, Color = Config.Colors.DownloadLinks
            };
            return(builder
                   .AddField($"Windows ({build?.Windows?.Datetime})   ".FixSpaces(), GetLinkMessage(build?.Windows?.Download, true), true)
                   .AddField($"Linux ({build?.Linux?.Datetime})   ".FixSpaces(), GetLinkMessage(build?.Linux?.Download, true), true));
        }
Ejemplo n.º 5
0
        public static async Task <DiscordEmbedBuilder> AsEmbedAsync(this UpdateInfo info, DiscordEmbedBuilder builder = null)
        {
            if ((info?.LatestBuild?.Windows?.Download ?? info?.LatestBuild?.Linux?.Download) == null)
            {
                return builder ?? new DiscordEmbedBuilder {
                           Title = "Error", Description = "Error communicating with the update API. Try again later.", Color = Config.Colors.Maintenance
                }
            }
            ;

            var    justAppend = builder != null;
            var    build      = info.LatestBuild;
            var    pr         = build?.Pr ?? "0";
            string url        = null;
            PrInfo prInfo     = null;

            if (!justAppend)
            {
                if (int.TryParse(pr, out var prNum) && prNum > 0)
                {
                    prInfo = await githubClient.GetPrInfoAsync(prNum, Config.Cts.Token).ConfigureAwait(false);

                    url = prInfo?.HtmlUrl ?? "https://github.com/RPCS3/rpcs3/pull/" + pr;
                    pr  = $"PR #{pr} by {prInfo?.User?.Login ?? "???"}";
                }
                else
                {
                    pr = "PR #???";
                }
            }
            builder = builder ?? new DiscordEmbedBuilder {
                Title = pr, Url = url, Description = prInfo?.Title, Color = Config.Colors.DownloadLinks
            };
            if (!string.IsNullOrEmpty(build?.Datetime))
            {
                var timestampInfo = build.Datetime;

                if (info.CurrentBuild?.Pr is string buildPr &&
                    buildPr != info.LatestBuild?.Pr &&
                    GetUpdateDelta(info) is TimeSpan timeDelta)
                {
                    timestampInfo += $" ({timeDelta.AsTimeDeltaDescription()} newer)";
                }
                else if (!justAppend && DateTime.TryParse(build.Datetime, out var buildDateTime) && DateTime.UtcNow.Ticks > buildDateTime.Ticks)
                {
                    timestampInfo += $" ({(DateTime.UtcNow - buildDateTime.AsUtc()).AsTimeDeltaDescription()} ago)";
                }

                if (justAppend)
                {
                    builder.AddField($"Latest master build ({timestampInfo})", "This pull request has been merged, and is a part of `master` now");
                }
                else
                {
                    builder.AddField("Build timestamp", timestampInfo);
                }
            }
            return(builder
                   .AddField($"Windows   ".FixSpaces(), GetLinkMessage(build?.Windows?.Download, true), true)
                   .AddField($"Linux   ".FixSpaces(), GetLinkMessage(build?.Linux?.Download, true), true));
        }
Ejemplo n.º 6
0
        public static async Task <DiscordEmbedBuilder> AsEmbedAsync(this UpdateInfo info, DiscordClient client, bool includePrBody = false, DiscordEmbedBuilder builder = null, PrInfo currentPrInfo = null)
        {
            if ((info?.LatestBuild?.Windows?.Download ?? info?.LatestBuild?.Linux?.Download) == null)
            {
                return builder ?? new DiscordEmbedBuilder {
                           Title = "Error", Description = "Error communicating with the update API. Try again later.", Color = Config.Colors.Maintenance
                }
            }
            ;

            var    justAppend   = builder != null;
            var    latestBuild  = info.LatestBuild;
            var    latestPr     = latestBuild?.Pr;
            var    currentPr    = info.CurrentBuild?.Pr;
            string url          = null;
            PrInfo latestPrInfo = null;

            string prDesc = "";

            if (!justAppend)
            {
                if (latestPr > 0)
                {
                    latestPrInfo = await githubClient.GetPrInfoAsync(latestPr.Value, Config.Cts.Token).ConfigureAwait(false);

                    url = latestPrInfo?.HtmlUrl ?? "https://github.com/RPCS3/rpcs3/pull/" + latestPr;
                    var userName = latestPrInfo?.User?.Login ?? "???";
                    var emoji    = GetUserNameEmoji(client, userName);
                    if (emoji != null)
                    {
                        userName += " " + emoji;
                    }
                    prDesc = $"PR #{latestPr} by {userName}";
                }
                else
                {
                    prDesc = "PR #???";
                }

                if (currentPr > 0 && currentPr != latestPr)
                {
                    currentPrInfo ??= await githubClient.GetPrInfoAsync(currentPr.Value, Config.Cts.Token).ConfigureAwait(false);
                }
            }
            var desc = latestPrInfo?.Title;

            if (includePrBody &&
                latestPrInfo?.Body is string prInfoBody &&
                !string.IsNullOrEmpty(prInfoBody))
            {
                desc = $"**{desc.TrimEnd()}**\n\n{prInfoBody}";
            }
            desc = desc?.Trim();
            if (!string.IsNullOrEmpty(desc))
            {
                if (GithubLinksHandler.IssueMention.Matches(desc) is MatchCollection issueMatches && issueMatches.Any())
                {
                    var uniqueLinks = new HashSet <string>(10);
                    foreach (Match m in issueMatches)
                    {
                        if (m.Groups["issue_mention"]?.Value is string str &&
                            !string.IsNullOrEmpty(str) &&
                            uniqueLinks.Add(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, $"[{name}](https://github.com/RPCS3/rpcs3/issues/{num})");
                        }
                    }
                }
                if (GithubLinksHandler.CommitMention.Matches(desc) is MatchCollection commitMatches && commitMatches.Any())
                {
                    var uniqueLinks = new HashSet <string>(2);
                    foreach (Match m in commitMatches)
                    {
                        if (m.Groups["commit_mention"]?.Value is string lnk &&
                            !string.IsNullOrEmpty(lnk) &&
                            uniqueLinks.Add(lnk))
                        {
                            var num = m.Groups["commit_hash"].Value;
                            if (string.IsNullOrEmpty(num))
                            {
                                continue;
                            }

                            if (num.Length > 7)
                            {
                                num = num[..7];
Ejemplo n.º 7
0
        public static async Task <DiscordEmbedBuilder> AsEmbedAsync(this UpdateInfo info, DiscordClient client, bool includePrBody = false, DiscordEmbedBuilder builder = null)
        {
            if ((info?.LatestBuild?.Windows?.Download ?? info?.LatestBuild?.Linux?.Download) == null)
            {
                return builder ?? new DiscordEmbedBuilder {
                           Title = "Error", Description = "Error communicating with the update API. Try again later.", Color = Config.Colors.Maintenance
                }
            }
            ;

            var    justAppend    = builder != null;
            var    latestBuild   = info.LatestBuild;
            var    latestPr      = latestBuild?.Pr;
            var    currentPr     = info.CurrentBuild?.Pr;
            string url           = null;
            PrInfo latestPrInfo  = null;
            PrInfo currentPrInfo = null;

            string prDesc = "";

            if (!justAppend)
            {
                if (latestPr > 0)
                {
                    latestPrInfo = await githubClient.GetPrInfoAsync(latestPr.Value, Config.Cts.Token).ConfigureAwait(false);

                    url = latestPrInfo?.HtmlUrl ?? "https://github.com/RPCS3/rpcs3/pull/" + latestPr;
                    var userName = latestPrInfo?.User?.Login ?? "???";
                    var emoji    = GetUserNameEmoji(client, userName);
                    if (emoji != null)
                    {
                        userName += " " + emoji;
                    }
                    prDesc = $"PR #{latestPr} by {userName}";
                }
                else
                {
                    prDesc = "PR #???";
                }

                if (currentPr > 0 && currentPr != latestPr)
                {
                    currentPrInfo = await githubClient.GetPrInfoAsync(currentPr.Value, Config.Cts.Token).ConfigureAwait(false);
                }
            }
            var desc = latestPrInfo?.Title;

            if (includePrBody &&
                latestPrInfo?.Body is string prInfoBody &&
                !string.IsNullOrEmpty(prInfoBody))
            {
                desc = $"**{desc.TrimEnd()}**\n\n{prInfoBody}";
            }
            desc = desc?.Trim();
            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 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, $"[{name}](https://github.com/RPCS3/rpcs3/issues/{num})");
                    }
                }
            }
            desc = desc.Trim(EmbedPager.MaxDescriptionLength);
            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);

            var latestAppveyorBuild = await appveyorClient.GetMasterBuildAsync(latestCommit, latestPrInfo?.MergedAt, Config.Cts.Token).ConfigureAwait(false);

            var buildTimestampKind    = "Build";
            var latestBuildTimestamp  = latestAppveyorBuild?.Finished?.ToUniversalTime();
            var currentBuildTimestamp = currentAppveyorBuild?.Finished?.ToUniversalTime();

            if (!latestBuildTimestamp.HasValue)
            {
                buildTimestampKind    = "Merge";
                latestBuildTimestamp  = latestPrInfo?.MergedAt;
                currentBuildTimestamp = currentPrInfo?.MergedAt;
            }

            if (!string.IsNullOrEmpty(latestBuild?.Datetime))
            {
                var timestampInfo = latestBuildTimestamp?.ToString("u") ?? latestBuild.Datetime;
                if (currentPr > 0 &&
                    currentPr != latestPr &&
                    GetUpdateDelta(latestBuildTimestamp, currentBuildTimestamp) is TimeSpan timeDelta)
                {
                    timestampInfo += $" ({timeDelta.AsTimeDeltaDescription()} newer)";
                }
                else if (!justAppend &&
                         latestBuildTimestamp.HasValue &&
                         DateTime.UtcNow.Ticks > latestBuildTimestamp.Value.Ticks)
                {
                    timestampInfo += $" ({(DateTime.UtcNow - latestBuildTimestamp.Value).AsTimeDeltaDescription()} ago)";
                }

                if (justAppend)
                {
                    builder.AddField($"Latest master build ({timestampInfo})", "This pull request has been merged, and is a part of `master` now");
                }
                else
                {
                    builder.AddField($"{buildTimestampKind} timestamp", timestampInfo);
                }
            }
            return(builder
                   .AddField("Windows download", GetLinkMessage(latestBuild?.Windows?.Download, true), true)
                   .AddField("Linux download", GetLinkMessage(latestBuild?.Linux?.Download, true), true));
        }