From 1a8ae3a29a7deb297dbf9204c8805d9718c4b6fa Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 9 Aug 2018 15:48:34 -0400 Subject: [PATCH] ODR the interop json classes a bit. Add more docs --- src/DMAPI/tgs/v4/api.dm | 27 +++++---- .../Models/Internal/TestMerge.cs | 28 +-------- .../Models/Internal/TestMergeBase.cs | 59 +++++++++++++++++++ .../Components/Watchdog/InteropInfo.cs | 27 +++++++++ .../Watchdog/SessionControllerFactory.cs | 15 +---- .../Components/Watchdog/TestMerge.cs | 27 ++++++--- 6 files changed, 123 insertions(+), 60 deletions(-) create mode 100644 src/Tgstation.Server.Api/Models/Internal/TestMergeBase.cs diff --git a/src/DMAPI/tgs/v4/api.dm b/src/DMAPI/tgs/v4/api.dm index 141cee1fb3..514dc6a365 100644 --- a/src/DMAPI/tgs/v4/api.dm +++ b/src/DMAPI/tgs/v4/api.dm @@ -77,29 +77,34 @@ src.event_handler = event_handler instance_name = cached_json["instanceName"] + ListCustomCommands() + + . = TRUE + + var/list/revisionData = cached_json["revision"] + if(!revisionData) + return + + cached_revision = new + cached_revision.commit = revisionData["commitSha"] + cached_revision.origin_commit = revisionData["originCommitSha"] + cached_test_merges = list() var/json = cached_json["testMerges"] for(var/I in json) var/datum/tgs_revision_information/test_merge/tm = new tm.number = text2num(I) var/list/entry = json[I] - tm.pull_request_commit = entry["prCommit"] + tm.pull_request_commit = entry["pullRequestRevision"] tm.author = entry["author"] tm.title = entry["title"] - tm.commit = entry["commit"] - tm.origin_commit = entry["originCommit"] + var/list/revInfo = entry["revision"] + tm.commit = revInfo["commitSha"] + tm.origin_commit = entry["originCommitSha"] tm.time_merged = text2num(entry["timeMerged"]) tm.comment = entry["comment"] tm.url = entry["url"] - cached_revision = new - cached_revision.commit = cached_json["commit"] - cached_revision.origin_commit = cached_json["originCommit"] - - ListCustomCommands() - - return TRUE - /datum/tgs_api/v4/OnInitializationComplete() Export(TGS4_COMM_SERVER_PRIMED) var/tgs4_secret_sleep_offline_sauce = 24051994 diff --git a/src/Tgstation.Server.Api/Models/Internal/TestMerge.cs b/src/Tgstation.Server.Api/Models/Internal/TestMerge.cs index 715620ba93..6189c0327c 100644 --- a/src/Tgstation.Server.Api/Models/Internal/TestMerge.cs +++ b/src/Tgstation.Server.Api/Models/Internal/TestMerge.cs @@ -6,7 +6,7 @@ namespace Tgstation.Server.Api.Models.Internal /// /// Represents a merge of a GitHub pull request /// - public class TestMerge : TestMergeParameters + public class TestMerge : TestMergeBase { /// /// The ID of the @@ -18,31 +18,5 @@ namespace Tgstation.Server.Api.Models.Internal /// [Required] public DateTimeOffset MergedAt { get; set; } - - /// - /// The title of the pull request - /// - [Required] - public string TitleAtMerge { get; set; } - - /// - /// The body of the pull request - /// - [Required] - public string BodyAtMerge { get; set; } - - /// - /// The URL of the pull request - /// - [Required] -#pragma warning disable CA1056 // Uri properties should not be strings - public string Url { get; set; } -#pragma warning restore CA1056 // Uri properties should not be strings - - /// - /// The author of the pull request - /// - [Required] - public string Author { get; set; } } } diff --git a/src/Tgstation.Server.Api/Models/Internal/TestMergeBase.cs b/src/Tgstation.Server.Api/Models/Internal/TestMergeBase.cs new file mode 100644 index 0000000000..b0bbb0db23 --- /dev/null +++ b/src/Tgstation.Server.Api/Models/Internal/TestMergeBase.cs @@ -0,0 +1,59 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace Tgstation.Server.Api.Models.Internal +{ + /// + /// Layer of test merge data required internally + /// + public abstract class TestMergeBase : TestMergeParameters + { + /// + /// The title of the pull request + /// + [Required] + public string TitleAtMerge { get; set; } + + /// + /// The body of the pull request + /// + [Required] + public string BodyAtMerge { get; set; } + + /// + /// The URL of the pull request + /// + [Required] +#pragma warning disable CA1056 // Uri properties should not be strings + public string Url { get; set; } +#pragma warning restore CA1056 // Uri properties should not be strings + + /// + /// The author of the pull request + /// + [Required] + public string Author { get; set; } + + /// + /// Construct a + /// + protected TestMergeBase() { } + + /// + /// Construct a from a + /// + /// + protected TestMergeBase(TestMergeBase copy) + { + if (copy == null) + throw new ArgumentNullException(nameof(copy)); + Author = copy.Author; + BodyAtMerge = copy.BodyAtMerge; + Comment = copy.Comment; + Number = copy.Number; + PullRequestRevision = copy.PullRequestRevision; + TitleAtMerge = copy.TitleAtMerge; + Url = copy.Url; + } + } +} diff --git a/src/Tgstation.Server.Host/Components/Watchdog/InteropInfo.cs b/src/Tgstation.Server.Host/Components/Watchdog/InteropInfo.cs index 6ef2befdbb..6530632ff8 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/InteropInfo.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/InteropInfo.cs @@ -3,22 +3,49 @@ using Tgstation.Server.Api.Models.Internal; namespace Tgstation.Server.Host.Components.Watchdog { + /// + /// Representation of the initial json passed to DreamDaemon + /// sealed class InteropInfo { + /// + /// The code used by the server to authenticate command Topics + /// public string AccessIdentifier { get; set; } + /// + /// If DD should just respond if it's API is working and then exit + /// public bool ApiValidateOnly { get; set; } + /// + /// The of the owner at the time of launch + /// public string InstanceName { get; set; } + /// + /// JSON file name that contains current active chat channel information + /// public string ChatChannelsJson { get; set; } + /// + /// JSON file DD should write to with available chat commands + /// public string ChatCommandsJson { get; set; } + /// + /// JSON file DD should write to to send commands to the server + /// public string ServerCommandsJson { get; set; } + /// + /// The of the launch + /// public RevisionInformation Revision { get; set; } + /// + /// The s in the launch + /// public List TestMerges { get; } = new List(); } } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs index 1f412ec361..57a3d47a4e 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs @@ -120,20 +120,7 @@ namespace Tgstation.Server.Host.Components.Watchdog Revision = dmbProvider.CompileJob.RevisionInformation }; - if (dmbProvider.CompileJob.RevisionInformation != null) //null while compiling - interopInfo.TestMerges.AddRange(dmbProvider.CompileJob.RevisionInformation.ActiveTestMerges.Select(x => x.TestMerge).Select(x => new TestMerge - { - Author = x.Author, - Body = x.BodyAtMerge, - Comment = x.Comment, - CommitSha = x.PrimaryRevisionInformation.CommitSha, - Number = x.Number, - OriginCommitSha = x.PrimaryRevisionInformation.OriginCommitSha, - PullRequestCommit = x.PullRequestRevision, - TimeMerged = x.MergedAt.Ticks, - Title = x.TitleAtMerge, - Url = x.Url - })); + interopInfo.TestMerges.AddRange(dmbProvider.CompileJob.RevisionInformation.ActiveTestMerges.Select(x => x.TestMerge).Select(x => new TestMerge(x))); var interopJsonFile = JsonFile("interop"); diff --git a/src/Tgstation.Server.Host/Components/Watchdog/TestMerge.cs b/src/Tgstation.Server.Host/Components/Watchdog/TestMerge.cs index 7a55e739fe..e72d6cfc5c 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/TestMerge.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/TestMerge.cs @@ -5,15 +5,26 @@ namespace Tgstation.Server.Host.Components.Watchdog /// /// This model mirrors /datum/tgs_revision_information/test_merge /// - sealed class TestMerge : RevisionInformation + sealed class TestMerge : TestMergeBase { - public int Number { get; set; } - public string Title { get; set; } - public string Body { get; set; } - public string Author { get; set; } - public string Url { get; set; } - public string PullRequestCommit { get; set; } + /// + /// The unix time of when the test merge was applied + /// public long TimeMerged { get; set; } - public string Comment { get; set; } + + /// + /// The of the + /// + public RevisionInformation Revision { get; set; } + + /// + /// Construct a + /// + /// The to build from + public TestMerge(Models.TestMerge testMerge) : base(testMerge) + { + TimeMerged = testMerge.MergedAt.Ticks; + Revision = testMerge.PrimaryRevisionInformation; + } } }