From 185a52638a25a1ea97ce677df147f781723c815d Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Thu, 30 May 2024 02:50:42 +0900 Subject: [PATCH 1/3] Remove suppress diagnostic for obsolete fields --- Runtime/Settings/AutopilotSettings.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Runtime/Settings/AutopilotSettings.cs b/Runtime/Settings/AutopilotSettings.cs index 9d58170..69a363b 100644 --- a/Runtime/Settings/AutopilotSettings.cs +++ b/Runtime/Settings/AutopilotSettings.cs @@ -163,16 +163,12 @@ public void OverrideByCommandLineArguments(Arguments args) if (args.SlackToken.IsCaptured()) { -#pragma warning disable CS0618 // Type or member is obsolete slackToken = args.SlackToken.Value(); -#pragma warning restore CS0618 // Type or member is obsolete } if (args.SlackChannels.IsCaptured()) { -#pragma warning disable CS0618 // Type or member is obsolete slackChannels = args.SlackChannels.Value(); -#pragma warning restore CS0618 // Type or member is obsolete } } } From e4ddee1b50183ff6996a941db33b1868d0aa34b8 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Thu, 30 May 2024 03:07:43 +0900 Subject: [PATCH 2/3] Fix not to send body when stack-trace is empty --- Runtime/Reporters/SlackMessageSender.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Runtime/Reporters/SlackMessageSender.cs b/Runtime/Reporters/SlackMessageSender.cs index 1109d3f..84006c7 100644 --- a/Runtime/Reporters/SlackMessageSender.cs +++ b/Runtime/Reporters/SlackMessageSender.cs @@ -95,7 +95,7 @@ public async UniTask Send( if (withScreenshot) { var coroutineRunner = new GameObject().AddComponent(); - await UniTask.WaitForEndOfFrame(coroutineRunner); + await UniTask.WaitForEndOfFrame(coroutineRunner, cancellationToken); Object.Destroy(coroutineRunner); var screenshot = ScreenCapture.CaptureScreenshotAsTexture(); @@ -107,7 +107,8 @@ public async UniTask Send( slackToken, slackChannel, withoutAlpha.EncodeToPNG(), - postTitleTask.Ts + postTitleTask.Ts, + cancellationToken ); if (!postScreenshotTask.Success) { @@ -115,8 +116,11 @@ public async UniTask Send( } } - var body = Body(logString, stackTrace); - await _slackAPI.Post(slackToken, slackChannel, body, postTitleTask.Ts); + if (stackTrace != null && stackTrace.Length > 0) + { + var body = Body(logString, stackTrace); + await _slackAPI.Post(slackToken, slackChannel, body, postTitleTask.Ts, cancellationToken); + } } From 4f73527486c7fbe608aacb1b2cf27d1fedd5851e Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 1 Jun 2024 15:20:11 +0900 Subject: [PATCH 3/3] Remove AutopilotSettings from parameter of PostReportAsync --- Runtime/Reporters/AbstractReporter.cs | 3 --- Runtime/Reporters/CompositeReporter.cs | 4 +--- Runtime/Reporters/SlackReporter.cs | 26 ++++++++++++++++++------ Runtime/Utilities/LogMessageHandler.cs | 2 +- Tests/Runtime/TestDoubles/SpyReporter.cs | 2 -- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Runtime/Reporters/AbstractReporter.cs b/Runtime/Reporters/AbstractReporter.cs index c40db21..1fc1595 100644 --- a/Runtime/Reporters/AbstractReporter.cs +++ b/Runtime/Reporters/AbstractReporter.cs @@ -3,7 +3,6 @@ using System.Threading; using Cysharp.Threading.Tasks; -using DeNA.Anjin.Settings; using UnityEngine; namespace DeNA.Anjin.Reporters @@ -16,7 +15,6 @@ public abstract class AbstractReporter : ScriptableObject /// /// Post report log message, stacktrace and screenshot /// - /// Autopilot settings /// Log message /// Stack trace /// Log message type @@ -24,7 +22,6 @@ public abstract class AbstractReporter : ScriptableObject /// Cancellation token /// public abstract UniTask PostReportAsync( - AutopilotSettings settings, string logString, string stackTrace, LogType type, diff --git a/Runtime/Reporters/CompositeReporter.cs b/Runtime/Reporters/CompositeReporter.cs index e9fea76..18a8f92 100644 --- a/Runtime/Reporters/CompositeReporter.cs +++ b/Runtime/Reporters/CompositeReporter.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Threading; using Cysharp.Threading.Tasks; -using DeNA.Anjin.Settings; using UnityEngine; namespace DeNA.Anjin.Reporters @@ -24,7 +23,6 @@ public class CompositeReporter : AbstractReporter /// public override async UniTask PostReportAsync( - AutopilotSettings settings, string logString, string stackTrace, LogType type, @@ -36,7 +34,7 @@ await UniTask.WhenAll( reporters .Where(r => r != this && r != null) .Select( - r => r.PostReportAsync(settings, logString, stackTrace, type, withScreenshot, cancellationToken) + r => r.PostReportAsync(logString, stackTrace, type, withScreenshot, cancellationToken) ) ); } diff --git a/Runtime/Reporters/SlackReporter.cs b/Runtime/Reporters/SlackReporter.cs index 13da3d2..a38c8b3 100644 --- a/Runtime/Reporters/SlackReporter.cs +++ b/Runtime/Reporters/SlackReporter.cs @@ -38,7 +38,6 @@ public class SlackReporter : AbstractReporter /// public override async UniTask PostReportAsync( - AutopilotSettings settings, string logString, string stackTrace, LogType type, @@ -46,18 +45,18 @@ public override async UniTask PostReportAsync( CancellationToken cancellationToken = default ) { + OverwriteByCommandlineArguments(); + // NOTE: In _sender.send, switch the execution thread to the main thread, so UniTask.WhenAll is meaningless. - foreach (var slackChannel in (string.IsNullOrEmpty(settings.slackChannels) - ? slackChannels - : settings.slackChannels).Split(',')) + foreach (var slackChannel in slackChannels.Split(',')) { if (cancellationToken.IsCancellationRequested) { return; } - + await _sender.Send( - string.IsNullOrEmpty(settings.slackToken) ? slackToken : settings.slackToken, + slackToken, slackChannel, mentionSubTeamIDs.Split(','), addHereInSlackMessage, @@ -68,5 +67,20 @@ await _sender.Send( ); } } + + private void OverwriteByCommandlineArguments() + { + var args = new Arguments(); + + if (args.SlackToken.IsCaptured()) + { + slackToken = args.SlackToken.Value(); + } + + if (args.SlackChannels.IsCaptured()) + { + slackChannels = args.SlackChannels.Value(); + } + } } } diff --git a/Runtime/Utilities/LogMessageHandler.cs b/Runtime/Utilities/LogMessageHandler.cs index 1de3f20..c68d292 100644 --- a/Runtime/Utilities/LogMessageHandler.cs +++ b/Runtime/Utilities/LogMessageHandler.cs @@ -53,7 +53,7 @@ public async void HandleLog(string logString, string stackTrace, LogType type) if (_reporter != null) { - await _reporter.PostReportAsync(_settings, logString, stackTrace, type, true); + await _reporter.PostReportAsync(logString, stackTrace, type, true); } var autopilot = Object.FindObjectOfType(); diff --git a/Tests/Runtime/TestDoubles/SpyReporter.cs b/Tests/Runtime/TestDoubles/SpyReporter.cs index a1aca42..d69c14b 100644 --- a/Tests/Runtime/TestDoubles/SpyReporter.cs +++ b/Tests/Runtime/TestDoubles/SpyReporter.cs @@ -19,7 +19,6 @@ public class SpyReporter : AbstractReporter public List> Arguments { get; } = new List>(); public override async UniTask PostReportAsync( - AutopilotSettings settings, string logString, string stackTrace, LogType type, @@ -30,7 +29,6 @@ public override async UniTask PostReportAsync( Debug.Log("Reporter called"); Arguments.Add(new Dictionary { - {"settings", settings.ToString()}, {"logString", logString}, {"stackTrace", stackTrace}, {"type", type.ToString()},