Skip to content

Commit

Permalink
Fix SlackReporter convert condition and create file
Browse files Browse the repository at this point in the history
Same as a JUnitXmlReporter; see #98
  • Loading branch information
nowsprinting committed Nov 4, 2024
1 parent 991457b commit 2313037
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions Runtime/Settings/AutopilotSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,20 +301,25 @@ internal void ConvertReportersFromObsoleteReporter(ILogger logger)
internal void ConvertSlackReporterFromObsoleteSlackSettings(ILogger logger)
{
if (string.IsNullOrEmpty(this.slackToken) || string.IsNullOrEmpty(this.slackChannels) ||
this.reporters.Any())
this.reporters.Any(x => x.GetType() == typeof(SlackReporter)))
{
return;
}

logger.Log(LogType.Warning, @"Slack settings in AutopilotSettings has been obsolete.
const string AutoConvertingMessage = @"Slack settings in AutopilotSettings has been obsolete.
Please delete the value using Debug Mode in the Inspector window. And create a SlackReporter asset file.
This time, temporarily generate and use SlackReporter instance.");
This time, temporarily generate and use SlackReporter instance.";
logger.Log(LogType.Warning, AutoConvertingMessage);

var convertedReporter = CreateInstance<SlackReporter>();
convertedReporter.slackToken = this.slackToken;
convertedReporter.slackChannels = this.slackChannels;
convertedReporter.mentionSubTeamIDs = this.mentionSubTeamIDs;
convertedReporter.addHereInSlackMessage = this.addHereInSlackMessage;
#if UNITY_EDITOR
convertedReporter.description = AutoConvertingMessage;
SaveConvertedObject(convertedReporter);
#endif
this.reporters.Add(convertedReporter);
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/Runtime/Settings/AutopilotSettingsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using DeNA.Anjin.TestDoubles;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace DeNA.Anjin.Settings
{
Expand Down Expand Up @@ -220,14 +219,15 @@ public void ConvertSlackReporterFromObsoleteSlackSettings_HasNotSlackChannels_No
[Test]
public void ConvertSlackReporterFromObsoleteSlackSettings_ExistReporter_NotGenerateSlackReporter()
{
var existReporter = ScriptableObject.CreateInstance<SlackReporter>();
var settings = ScriptableObject.CreateInstance<AutopilotSettings>();
settings.reporters.Add(ScriptableObject.CreateInstance<CompositeReporter>()); // already exists
settings.reporters.Add(existReporter); // already exists
settings.slackToken = "token";
settings.slackChannels = "channels";

settings.ConvertSlackReporterFromObsoleteSlackSettings(Debug.unityLogger);
Assert.That(settings.reporters.Count, Is.EqualTo(1));
Assert.That(settings.reporters, Has.No.InstanceOf<SlackReporter>());
Assert.That(settings.reporters, Does.Contain(existReporter));
}
}
}

0 comments on commit 2313037

Please sign in to comment.