more audit work
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using StellaOps.Signals.Scm.Models;
|
||||
|
||||
@@ -53,7 +54,7 @@ public sealed class GitHubEventMapper : IScmEventMapper
|
||||
EventId = deliveryId,
|
||||
Provider = ScmProvider.GitHub,
|
||||
EventType = scmEventType,
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Timestamp = ExtractTimestamp(payload),
|
||||
Repository = repository,
|
||||
Actor = ExtractActor(payload),
|
||||
Ref = refName ?? GetString(payload, "ref"),
|
||||
@@ -266,6 +267,36 @@ public sealed class GitHubEventMapper : IScmEventMapper
|
||||
};
|
||||
}
|
||||
|
||||
private static DateTimeOffset ExtractTimestamp(JsonElement payload)
|
||||
{
|
||||
var timestamp = GetNestedString(payload, "head_commit", "timestamp")
|
||||
?? GetNestedString(payload, "workflow_run", "updated_at")
|
||||
?? GetNestedString(payload, "workflow_run", "created_at")
|
||||
?? GetNestedString(payload, "pull_request", "updated_at")
|
||||
?? GetNestedString(payload, "pull_request", "created_at")
|
||||
?? GetNestedString(payload, "release", "published_at")
|
||||
?? GetNestedString(payload, "check_run", "completed_at")
|
||||
?? GetNestedString(payload, "check_run", "started_at");
|
||||
|
||||
return TryParseTimestamp(timestamp) ?? DateTimeOffset.UnixEpoch;
|
||||
}
|
||||
|
||||
private static DateTimeOffset? TryParseTimestamp(string? value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return DateTimeOffset.TryParse(
|
||||
value,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out var parsed)
|
||||
? parsed
|
||||
: null;
|
||||
}
|
||||
|
||||
private static string? GetString(JsonElement element, string property)
|
||||
{
|
||||
return element.TryGetProperty(property, out var value) && value.ValueKind == JsonValueKind.String
|
||||
|
||||
Reference in New Issue
Block a user