ODR the interop json classes a bit. Add more docs

This commit is contained in:
Cyberboss
2018-08-09 15:48:34 -04:00
parent 9902495e78
commit 1a8ae3a29a
6 changed files with 123 additions and 60 deletions
+16 -11
View File
@@ -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
@@ -6,7 +6,7 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// Represents a merge of a GitHub pull request
/// </summary>
public class TestMerge : TestMergeParameters
public class TestMerge : TestMergeBase
{
/// <summary>
/// The ID of the <see cref="TestMerge"/>
@@ -18,31 +18,5 @@ namespace Tgstation.Server.Api.Models.Internal
/// </summary>
[Required]
public DateTimeOffset MergedAt { get; set; }
/// <summary>
/// The title of the pull request
/// </summary>
[Required]
public string TitleAtMerge { get; set; }
/// <summary>
/// The body of the pull request
/// </summary>
[Required]
public string BodyAtMerge { get; set; }
/// <summary>
/// The URL of the pull request
/// </summary>
[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
/// <summary>
/// The author of the pull request
/// </summary>
[Required]
public string Author { get; set; }
}
}
@@ -0,0 +1,59 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Api.Models.Internal
{
/// <summary>
/// Layer of test merge data required internally
/// </summary>
public abstract class TestMergeBase : TestMergeParameters
{
/// <summary>
/// The title of the pull request
/// </summary>
[Required]
public string TitleAtMerge { get; set; }
/// <summary>
/// The body of the pull request
/// </summary>
[Required]
public string BodyAtMerge { get; set; }
/// <summary>
/// The URL of the pull request
/// </summary>
[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
/// <summary>
/// The author of the pull request
/// </summary>
[Required]
public string Author { get; set; }
/// <summary>
/// Construct a <see cref="TestMergeBase"/>
/// </summary>
protected TestMergeBase() { }
/// <summary>
/// Construct a <see cref="TestMergeBase"/> from a <paramref name="copy"/>
/// </summary>
/// <param name="copy"></param>
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;
}
}
}
@@ -3,22 +3,49 @@ using Tgstation.Server.Api.Models.Internal;
namespace Tgstation.Server.Host.Components.Watchdog
{
/// <summary>
/// Representation of the initial json passed to DreamDaemon
/// </summary>
sealed class InteropInfo
{
/// <summary>
/// The code used by the server to authenticate command Topics
/// </summary>
public string AccessIdentifier { get; set; }
/// <summary>
/// If DD should just respond if it's API is working and then exit
/// </summary>
public bool ApiValidateOnly { get; set; }
/// <summary>
/// The <see cref="Api.Models.Instance.Name"/> of the owner at the time of launch
/// </summary>
public string InstanceName { get; set; }
/// <summary>
/// JSON file name that contains current active chat channel information
/// </summary>
public string ChatChannelsJson { get; set; }
/// <summary>
/// JSON file DD should write to with available chat commands
/// </summary>
public string ChatCommandsJson { get; set; }
/// <summary>
/// JSON file DD should write to to send commands to the server
/// </summary>
public string ServerCommandsJson { get; set; }
/// <summary>
/// The <see cref="RevisionInformation"/> of the launch
/// </summary>
public RevisionInformation Revision { get; set; }
/// <summary>
/// The <see cref="TestMerge"/>s in the launch
/// </summary>
public List<TestMerge> TestMerges { get; } = new List<TestMerge>();
}
}
@@ -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");
@@ -5,15 +5,26 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// <summary>
/// This model mirrors /datum/tgs_revision_information/test_merge
/// </summary>
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; }
/// <summary>
/// The unix time of when the test merge was applied
/// </summary>
public long TimeMerged { get; set; }
public string Comment { get; set; }
/// <summary>
/// The <see cref="RevisionInformation"/> of the <see cref="TestMerge"/>
/// </summary>
public RevisionInformation Revision { get; set; }
/// <summary>
/// Construct a <see cref="TestMerge"/>
/// </summary>
/// <param name="testMerge">The <see cref="Models.TestMerge"/> to build from</param>
public TestMerge(Models.TestMerge testMerge) : base(testMerge)
{
TimeMerged = testMerge.MergedAt.Ticks;
Revision = testMerge.PrimaryRevisionInformation;
}
}
}