From df184d41a648cb0dfda71c32ed63a755640cf022 Mon Sep 17 00:00:00 2001 From: Colby Williams Date: Tue, 19 Dec 2023 12:27:52 -0600 Subject: [PATCH] add custom_property and custom_property_values (#417) Co-authored-by: Jamie Magee --- .../CustomProperty/CustomPropertyAction.cs | 16 ++++++++ .../CustomPropertyActionValue.cs | 10 +++++ .../CustomPropertyCreatedEvent.cs | 27 +++++++++++++ .../CustomPropertyDeletedEvent.cs | 9 +++++ .../CustomPropertyUpdatedEvent.cs | 27 +++++++++++++ .../Events/CustomPropertyEvent.cs | 10 +++++ .../CustomPropertyValuesAction.cs | 12 ++++++ .../CustomPropertyValuesActionValue.cs | 6 +++ .../CustomPropertyValuesUpdatedEvent.cs | 9 +++++ .../Events/CustomPropertyValuesEvent.cs | 15 ++++++++ .../CustomProperty/CustomPropertyValueType.cs | 11 ++++++ .../CustomPropertyValue.cs | 11 ++++++ src/Octokit.Webhooks/WebHookEventType.cs | 2 + src/Octokit.Webhooks/WebhookEventProcessor.cs | 38 +++++++++++++++++++ 14 files changed, 203 insertions(+) create mode 100644 src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyAction.cs create mode 100644 src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyActionValue.cs create mode 100644 src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyCreatedEvent.cs create mode 100644 src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyDeletedEvent.cs create mode 100644 src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyUpdatedEvent.cs create mode 100644 src/Octokit.Webhooks/Events/CustomPropertyEvent.cs create mode 100644 src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesAction.cs create mode 100644 src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesActionValue.cs create mode 100644 src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesUpdatedEvent.cs create mode 100644 src/Octokit.Webhooks/Events/CustomPropertyValuesEvent.cs create mode 100644 src/Octokit.Webhooks/Models/CustomProperty/CustomPropertyValueType.cs create mode 100644 src/Octokit.Webhooks/Models/CustomPropertyValues/CustomPropertyValue.cs diff --git a/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyAction.cs b/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyAction.cs new file mode 100644 index 00000000..c48a9d0b --- /dev/null +++ b/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyAction.cs @@ -0,0 +1,16 @@ +namespace Octokit.Webhooks.Events.CustomProperty; + +[PublicAPI] +public sealed record CustomPropertyAction : WebhookEventAction +{ + public static readonly CustomPropertyAction Created = new(CustomPropertyActionValue.Created); + + public static readonly CustomPropertyAction Updated = new(CustomPropertyActionValue.Updated); + + public static readonly CustomPropertyAction Deleted = new(CustomPropertyActionValue.Deleted); + + private CustomPropertyAction(string value) + : base(value) + { + } +} diff --git a/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyActionValue.cs b/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyActionValue.cs new file mode 100644 index 00000000..1a4f0ff1 --- /dev/null +++ b/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyActionValue.cs @@ -0,0 +1,10 @@ +namespace Octokit.Webhooks.Events.CustomProperty; + +public static class CustomPropertyActionValue +{ + public const string Created = "created"; + + public const string Updated = "updated"; + + public const string Deleted = "deleted"; +} diff --git a/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyCreatedEvent.cs b/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyCreatedEvent.cs new file mode 100644 index 00000000..634ffce0 --- /dev/null +++ b/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyCreatedEvent.cs @@ -0,0 +1,27 @@ +using Octokit.Webhooks.Models.CustomProperty; + +namespace Octokit.Webhooks.Events.CustomProperty; + +[PublicAPI] +[WebhookActionType(CustomPropertyActionValue.Created)] +public sealed record CustomPropertyCreatedEvent : CustomPropertyEvent +{ + [JsonPropertyName("action")] + public override string Action => CustomPropertyAction.Created; + + [JsonPropertyName("value_type")] + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum ValueType { get; init; } = null!; + + [JsonPropertyName("default_value")] + public string? DefaultValue { get; init; } + + [JsonPropertyName("required")] + public bool Required { get; init; } + + [JsonPropertyName("description")] + public string? Description { get; init; } + + [JsonPropertyName("allowed_values")] + public IEnumerable? AllowedValues { get; init; } +} diff --git a/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyDeletedEvent.cs b/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyDeletedEvent.cs new file mode 100644 index 00000000..4c34eca6 --- /dev/null +++ b/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyDeletedEvent.cs @@ -0,0 +1,9 @@ +namespace Octokit.Webhooks.Events.CustomProperty; + +[PublicAPI] +[WebhookActionType(CustomPropertyActionValue.Deleted)] +public sealed record CustomPropertyDeletedEvent : CustomPropertyEvent +{ + [JsonPropertyName("action")] + public override string Action => CustomPropertyAction.Deleted; +} diff --git a/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyUpdatedEvent.cs b/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyUpdatedEvent.cs new file mode 100644 index 00000000..2f89c16a --- /dev/null +++ b/src/Octokit.Webhooks/Events/CustomProperty/CustomPropertyUpdatedEvent.cs @@ -0,0 +1,27 @@ +using Octokit.Webhooks.Models.CustomProperty; + +namespace Octokit.Webhooks.Events.CustomProperty; + +[PublicAPI] +[WebhookActionType(CustomPropertyActionValue.Updated)] +public sealed record CustomPropertyUpdatedEvent : CustomPropertyEvent +{ + [JsonPropertyName("action")] + public override string Action => CustomPropertyAction.Updated; + + [JsonPropertyName("value_type")] + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum ValueType { get; init; } = null!; + + [JsonPropertyName("default_value")] + public string? DefaultValue { get; init; } + + [JsonPropertyName("required")] + public bool Required { get; init; } + + [JsonPropertyName("description")] + public string? Description { get; init; } + + [JsonPropertyName("allowed_values")] + public IEnumerable? AllowedValues { get; init; } +} diff --git a/src/Octokit.Webhooks/Events/CustomPropertyEvent.cs b/src/Octokit.Webhooks/Events/CustomPropertyEvent.cs new file mode 100644 index 00000000..44388e55 --- /dev/null +++ b/src/Octokit.Webhooks/Events/CustomPropertyEvent.cs @@ -0,0 +1,10 @@ +namespace Octokit.Webhooks.Events; + +[PublicAPI] +[WebhookEventType(WebhookEventType.CustomProperty)] +[JsonConverter(typeof(WebhookConverter))] +public abstract record CustomPropertyEvent : WebhookEvent +{ + [JsonPropertyName("property_name")] + public string PropertyName { get; init; } = null!; +} diff --git a/src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesAction.cs b/src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesAction.cs new file mode 100644 index 00000000..930297b5 --- /dev/null +++ b/src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesAction.cs @@ -0,0 +1,12 @@ +namespace Octokit.Webhooks.Events.CustomPropertyValues; + +[PublicAPI] +public sealed record CustomPropertyValuesAction : WebhookEventAction +{ + public static readonly CustomPropertyValuesAction Updated = new(CustomPropertyValuesActionValue.Updated); + + private CustomPropertyValuesAction(string value) + : base(value) + { + } +} diff --git a/src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesActionValue.cs b/src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesActionValue.cs new file mode 100644 index 00000000..f289c72e --- /dev/null +++ b/src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesActionValue.cs @@ -0,0 +1,6 @@ +namespace Octokit.Webhooks.Events.CustomPropertyValues; + +public static class CustomPropertyValuesActionValue +{ + public const string Updated = "updated"; +} diff --git a/src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesUpdatedEvent.cs b/src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesUpdatedEvent.cs new file mode 100644 index 00000000..79a11813 --- /dev/null +++ b/src/Octokit.Webhooks/Events/CustomPropertyValues/CustomPropertyValuesUpdatedEvent.cs @@ -0,0 +1,9 @@ +namespace Octokit.Webhooks.Events.CustomPropertyValues; + +[PublicAPI] +[WebhookActionType(CustomPropertyValuesActionValue.Updated)] +public abstract record CustomPropertyValuesUpdatedEvent : CustomPropertyValuesEvent +{ + [JsonPropertyName("action")] + public override string Action => CustomPropertyValuesAction.Updated; +} diff --git a/src/Octokit.Webhooks/Events/CustomPropertyValuesEvent.cs b/src/Octokit.Webhooks/Events/CustomPropertyValuesEvent.cs new file mode 100644 index 00000000..952b2a57 --- /dev/null +++ b/src/Octokit.Webhooks/Events/CustomPropertyValuesEvent.cs @@ -0,0 +1,15 @@ +using Octokit.Webhooks.Models.CustomPropertyValues; + +namespace Octokit.Webhooks.Events; + +[PublicAPI] +[WebhookEventType(WebhookEventType.CustomPropertyValues)] +[JsonConverter(typeof(WebhookConverter))] +public abstract record CustomPropertyValuesEvent : WebhookEvent +{ + [JsonPropertyName("new_property_values")] + public IEnumerable NewPropertyValues { get; init; } = null!; + + [JsonPropertyName("old_property_values")] + public IEnumerable OldPropertyValues { get; init; } = null!; +} diff --git a/src/Octokit.Webhooks/Models/CustomProperty/CustomPropertyValueType.cs b/src/Octokit.Webhooks/Models/CustomProperty/CustomPropertyValueType.cs new file mode 100644 index 00000000..2c54593c --- /dev/null +++ b/src/Octokit.Webhooks/Models/CustomProperty/CustomPropertyValueType.cs @@ -0,0 +1,11 @@ +namespace Octokit.Webhooks.Models.CustomProperty; + +[PublicAPI] +public enum CustomPropertyValueType +{ + [EnumMember(Value = "string")] + String, + + [EnumMember(Value = "single_select")] + SingleSelect, +} diff --git a/src/Octokit.Webhooks/Models/CustomPropertyValues/CustomPropertyValue.cs b/src/Octokit.Webhooks/Models/CustomPropertyValues/CustomPropertyValue.cs new file mode 100644 index 00000000..02ceda6a --- /dev/null +++ b/src/Octokit.Webhooks/Models/CustomPropertyValues/CustomPropertyValue.cs @@ -0,0 +1,11 @@ +namespace Octokit.Webhooks.Models.CustomPropertyValues; + +[PublicAPI] +public record CustomPropertyValue +{ + [JsonPropertyName("property_name")] + public string PropertyName { get; set; } = null!; + + [JsonPropertyName("value")] + public string? Value { get; set; } +} diff --git a/src/Octokit.Webhooks/WebHookEventType.cs b/src/Octokit.Webhooks/WebHookEventType.cs index f1e80581..0a3ca135 100644 --- a/src/Octokit.Webhooks/WebHookEventType.cs +++ b/src/Octokit.Webhooks/WebHookEventType.cs @@ -9,6 +9,8 @@ public static class WebhookEventType public const string CommitComment = "commit_comment"; public const string ContentReference = "content_reference"; public const string Create = "create"; + public const string CustomProperty = "custom_property"; + public const string CustomPropertyValues = "custom_property_values"; public const string Delete = "delete"; public const string DependabotAlert = "dependabot_alert"; public const string Deployment = "deployment"; diff --git a/src/Octokit.Webhooks/WebhookEventProcessor.cs b/src/Octokit.Webhooks/WebhookEventProcessor.cs index 12561cdf..15420f0c 100644 --- a/src/Octokit.Webhooks/WebhookEventProcessor.cs +++ b/src/Octokit.Webhooks/WebhookEventProcessor.cs @@ -9,6 +9,8 @@ using Octokit.Webhooks.Events.CodeScanningAlert; using Octokit.Webhooks.Events.CommitComment; using Octokit.Webhooks.Events.ContentReference; +using Octokit.Webhooks.Events.CustomProperty; +using Octokit.Webhooks.Events.CustomPropertyValues; using Octokit.Webhooks.Events.DependabotAlert; using Octokit.Webhooks.Events.DeployKey; using Octokit.Webhooks.Events.Deployment; @@ -83,6 +85,8 @@ BranchProtectionRuleEvent branchProtectionRuleEvent CommitCommentEvent commitCommentEvent => this.ProcessCommitCommentWebhookAsync(headers, commitCommentEvent), ContentReferenceEvent contentReferenceEvent => this.ProcessContentReferenceWebhookAsync(headers, contentReferenceEvent), CreateEvent createEvent => this.ProcessCreateWebhookAsync(headers, createEvent), + CustomPropertyEvent customPropertyEvent => this.ProcessCustomPropertyWebhookAsync(headers, customPropertyEvent), + CustomPropertyValuesEvent customPropertyValuesEvent => this.ProcessCustomPropertyValuesWebhookAsync(headers, customPropertyValuesEvent), DeleteEvent deleteEvent => this.ProcessDeleteWebhookAsync(headers, deleteEvent), DependabotAlertEvent dependabotAlertEvent => this.ProcessDependabotAlertWebhookAsync(headers, dependabotAlertEvent), DeployKeyEvent deployKeyEvent => this.ProcessDeployKeyWebhookAsync(headers, deployKeyEvent), @@ -165,6 +169,8 @@ public virtual WebhookEvent DeserializeWebhookEvent(WebhookHeaders headers, stri WebhookEventType.CommitComment => JsonSerializer.Deserialize(body)!, WebhookEventType.ContentReference => JsonSerializer.Deserialize(body)!, WebhookEventType.Create => JsonSerializer.Deserialize(body)!, + WebhookEventType.CustomProperty => JsonSerializer.Deserialize(body)!, + WebhookEventType.CustomPropertyValues => JsonSerializer.Deserialize(body)!, WebhookEventType.Delete => JsonSerializer.Deserialize(body)!, WebhookEventType.DependabotAlert => JsonSerializer.Deserialize(body)!, WebhookEventType.DeployKey => JsonSerializer.Deserialize(body)!, @@ -330,6 +336,38 @@ protected virtual Task ProcessContentReferenceWebhookAsync( [PublicAPI] protected virtual Task ProcessCreateWebhookAsync(WebhookHeaders headers, CreateEvent createEvent) => Task.CompletedTask; + private Task ProcessCustomPropertyWebhookAsync(WebhookHeaders headers, CustomPropertyEvent customPropertyEvent) => + customPropertyEvent.Action switch + { + CustomPropertyActionValue.Created + => this.ProcessCustomPropertyWebhookAsync(headers, customPropertyEvent, CustomPropertyAction.Created), + CustomPropertyActionValue.Deleted + => this.ProcessCustomPropertyWebhookAsync(headers, customPropertyEvent, CustomPropertyAction.Deleted), + CustomPropertyActionValue.Updated + => this.ProcessCustomPropertyWebhookAsync(headers, customPropertyEvent, CustomPropertyAction.Updated), + _ => Task.CompletedTask, + }; + + [PublicAPI] + protected virtual Task ProcessCustomPropertyWebhookAsync( + WebhookHeaders headers, + CustomPropertyEvent hookEvent, + CustomPropertyAction action) => Task.CompletedTask; + + private Task ProcessCustomPropertyValuesWebhookAsync(WebhookHeaders headers, CustomPropertyValuesEvent customPropertyValuesEvent) => + customPropertyValuesEvent.Action switch + { + CustomPropertyValuesActionValue.Updated + => this.ProcessCustomPropertyValuesWebhookAsync(headers, customPropertyValuesEvent, CustomPropertyValuesAction.Updated), + _ => Task.CompletedTask, + }; + + [PublicAPI] + protected virtual Task ProcessCustomPropertyValuesWebhookAsync( + WebhookHeaders headers, + CustomPropertyValuesEvent hookEvent, + CustomPropertyValuesAction action) => Task.CompletedTask; + [PublicAPI] protected virtual Task ProcessDeleteWebhookAsync(WebhookHeaders headers, DeleteEvent deleteEvent) => Task.CompletedTask;