Skip to content

Commit

Permalink
Custom Properties (custom_property and custom_property_values eve…
Browse files Browse the repository at this point in the history
…nts) (#500)

* add test custom_property payloads

* add test custom_property_values payload

* custom_property custom_property_values app events

* organization_custom_properties repository_custom_properties app permissions

* add custom_properties to Repository

* fix bug in (released) custom_property_values event

* correct objects for custom_property_values events

* correct objects for custom_property events

* docs say values_editable_by can be null
  • Loading branch information
colbylwilliams authored May 9, 2024
1 parent 645eae2 commit 9fc75ba
Show file tree
Hide file tree
Showing 19 changed files with 395 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Octokit.Webhooks.Models.CustomProperty;

namespace Octokit.Webhooks.Events.CustomProperty;

[PublicAPI]
Expand All @@ -9,19 +7,6 @@ public sealed record CustomPropertyCreatedEvent : CustomPropertyEvent
[JsonPropertyName("action")]
public override string Action => CustomPropertyAction.Created;

[JsonPropertyName("value_type")]
[JsonConverter(typeof(StringEnumConverter<CustomPropertyValueType>))]
public StringEnum<CustomPropertyValueType> 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<string>? AllowedValues { get; init; }
[JsonPropertyName("definition")]
public Models.CustomPropertyEvent.CustomProperty CustomProperty { get; init; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ public sealed record CustomPropertyDeletedEvent : CustomPropertyEvent
{
[JsonPropertyName("action")]
public override string Action => CustomPropertyAction.Deleted;

[JsonPropertyName("definition")]
public Models.CustomPropertyEvent.CustomPropertyLite CustomProperty { get; init; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Octokit.Webhooks.Models.CustomProperty;

namespace Octokit.Webhooks.Events.CustomProperty;

[PublicAPI]
Expand All @@ -9,19 +7,6 @@ public sealed record CustomPropertyUpdatedEvent : CustomPropertyEvent
[JsonPropertyName("action")]
public override string Action => CustomPropertyAction.Updated;

[JsonPropertyName("value_type")]
[JsonConverter(typeof(StringEnumConverter<CustomPropertyValueType>))]
public StringEnum<CustomPropertyValueType> 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<string>? AllowedValues { get; init; }
[JsonPropertyName("definition")]
public Models.CustomPropertyEvent.CustomProperty CustomProperty { get; init; } = null!;
}
6 changes: 1 addition & 5 deletions src/Octokit.Webhooks/Events/CustomPropertyEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ namespace Octokit.Webhooks.Events;
[PublicAPI]
[WebhookEventType(WebhookEventType.CustomProperty)]
[JsonConverter(typeof(WebhookConverter<CustomPropertyEvent>))]
public abstract record CustomPropertyEvent : WebhookEvent
{
[JsonPropertyName("property_name")]
public string PropertyName { get; init; } = null!;
}
public abstract record CustomPropertyEvent : WebhookEvent;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ namespace Octokit.Webhooks.Events.CustomPropertyValues;

[PublicAPI]
[WebhookActionType(CustomPropertyValuesActionValue.Updated)]
public abstract record CustomPropertyValuesUpdatedEvent : CustomPropertyValuesEvent
public sealed record CustomPropertyValuesUpdatedEvent : CustomPropertyValuesEvent
{
[JsonPropertyName("action")]
public override string Action => CustomPropertyValuesAction.Updated;

[JsonPropertyName("new_property_values")]
public IEnumerable<Models.CustomPropertyValuesEvent.CustomPropertyValue> NewPropertyValues { get; init; } = null!;

[JsonPropertyName("old_property_values")]
public IEnumerable<Models.CustomPropertyValuesEvent.CustomPropertyValue> OldPropertyValues { get; init; } = null!;
}
11 changes: 1 addition & 10 deletions src/Octokit.Webhooks/Events/CustomPropertyValuesEvent.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
using Octokit.Webhooks.Models.CustomPropertyValues;

namespace Octokit.Webhooks.Events;

[PublicAPI]
[WebhookEventType(WebhookEventType.CustomPropertyValues)]
[JsonConverter(typeof(WebhookConverter<CustomPropertyValuesEvent>))]
public abstract record CustomPropertyValuesEvent : WebhookEvent
{
[JsonPropertyName("new_property_values")]
public IEnumerable<CustomPropertyValue> NewPropertyValues { get; init; } = null!;

[JsonPropertyName("old_property_values")]
public IEnumerable<CustomPropertyValue> OldPropertyValues { get; init; } = null!;
}
public abstract record CustomPropertyValuesEvent : WebhookEvent;
4 changes: 4 additions & 0 deletions src/Octokit.Webhooks/Models/AppEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public enum AppEvent
ContentReference,
[EnumMember(Value = "create")]
Create,
[EnumMember(Value = "custom_property")]
CustomProperty,
[EnumMember(Value = "custom_property_values")]
CustomPropertyValues,
[EnumMember(Value = "delete")]
Delete,
[EnumMember(Value = "deploy_key")]
Expand Down
8 changes: 8 additions & 0 deletions src/Octokit.Webhooks/Models/AppPermissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public sealed record AppPermissions
[JsonConverter(typeof(StringEnumConverter<AppPermissionsLevel>))]
public StringEnum<AppPermissionsLevel>? OrganizationAdministration { get; init; }

[JsonPropertyName("organization_custom_properties")]
[JsonConverter(typeof(StringEnumConverter<AppPermissionsLevel>))]
public StringEnum<AppPermissionsLevel>? OrganizationCustomProperties { get; init; }

[JsonPropertyName("organization_hooks")]
[JsonConverter(typeof(StringEnumConverter<AppPermissionsLevel>))]
public StringEnum<AppPermissionsLevel>? OrganizationHooks { get; init; }
Expand Down Expand Up @@ -117,6 +121,10 @@ public sealed record AppPermissions
[JsonConverter(typeof(StringEnumConverter<AppPermissionsLevel>))]
public StringEnum<AppPermissionsLevel>? PullRequests { get; init; }

[JsonPropertyName("repository_custom_properties")]
[JsonConverter(typeof(StringEnumConverter<AppPermissionsLevel>))]
public StringEnum<AppPermissionsLevel>? RepositoryCustomProperties { get; init; }

[JsonPropertyName("repository_hooks")]
[JsonConverter(typeof(StringEnumConverter<AppPermissionsLevel>))]
public StringEnum<AppPermissionsLevel>? RepositoryHooks { get; init; }
Expand Down
28 changes: 28 additions & 0 deletions src/Octokit.Webhooks/Models/CustomPropertyEvent/CustomProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Octokit.Webhooks.Models.CustomPropertyEvent;

[PublicAPI]
public sealed record CustomProperty
{
[JsonPropertyName("property_name")]
public string PropertyName { get; init; } = null!;

[JsonPropertyName("value_type")]
[JsonConverter(typeof(StringEnumConverter<CustomPropertyValueType>))]
public StringEnum<CustomPropertyValueType> ValueType { get; init; } = null!;

[JsonPropertyName("required")]
public bool Required { get; init; }

[JsonPropertyName("default_value")]
public string? DefaultValue { get; init; }

[JsonPropertyName("description")]
public string? Description { get; init; }

[JsonPropertyName("allowed_values")]
public IEnumerable<string>? AllowedValues { get; init; }

[JsonPropertyName("values_editable_by")]
[JsonConverter(typeof(StringEnumConverter<CustomPropertyValuesEditableBy>))]
public StringEnum<CustomPropertyValuesEditableBy>? ValuesEditableBy { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Octokit.Webhooks.Models.CustomPropertyEvent;

[PublicAPI]
public sealed record CustomPropertyLite
{
[JsonPropertyName("property_name")]
public string PropertyName { get; init; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Octokit.Webhooks.Models.CustomProperty;
namespace Octokit.Webhooks.Models.CustomPropertyEvent;

[PublicAPI]
public enum CustomPropertyValueType
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Octokit.Webhooks.Models.CustomPropertyEvent;

[PublicAPI]
public enum CustomPropertyValuesEditableBy
{
[EnumMember(Value = "org_actors")]
OrgActors,

[EnumMember(Value = "org_and_repo_actors")]
OrgAndRepoActors,
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Octokit.Webhooks.Models.CustomPropertyValuesEvent;

[PublicAPI]
public sealed record CustomPropertyValue
{
[JsonPropertyName("property_name")]
public string PropertyName { get; init; } = null!;

[JsonPropertyName("value")]
public string? Value { get; init; }
}
3 changes: 3 additions & 0 deletions src/Octokit.Webhooks/Models/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,7 @@ public sealed record Repository

[JsonPropertyName("organization")]
public string? Organization { get; init; }

[JsonPropertyName("custom_properties")]
public IDictionary<string, string>? CustomProperties { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"action": "created",
"definition": {
"property_name": "dev_platform_select",
"value_type": "single_select",
"required": true,
"default_value": "option_default",
"description": "select description",
"allowed_values": [
"option_one",
"option_two",
"option_default"
],
"values_editable_by": "org_and_repo_actors"
},
"organization": {
"login": "Contoso-Inc",
"id": 128636122,
"node_id": "O_kgDOB6rU2g",
"url": "https://api.github.com/orgs/Contoso-Inc",
"repos_url": "https://api.github.com/orgs/Contoso-Inc/repos",
"events_url": "https://api.github.com/orgs/Contoso-Inc/events",
"hooks_url": "https://api.github.com/orgs/Contoso-Inc/hooks",
"issues_url": "https://api.github.com/orgs/Contoso-Inc/issues",
"members_url": "https://api.github.com/orgs/Contoso-Inc/members{/member}",
"public_members_url": "https://api.github.com/orgs/Contoso-Inc/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/128636122?v=4",
"description": "Contoso Inc brings you the best of everything. "
},
"sender": {
"login": "colbylwilliams",
"id": 1829082,
"node_id": "MDQ6VXNldfG4MjkwODI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1829082?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/colbylwilliams",
"html_url": "https://github.com/colbylwilliams",
"followers_url": "https://api.github.com/users/colbylwilliams/followers",
"following_url": "https://api.github.com/users/colbylwilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/colbylwilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/colbylwilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/colbylwilliams/subscriptions",
"organizations_url": "https://api.github.com/users/colbylwilliams/orgs",
"repos_url": "https://api.github.com/users/colbylwilliams/repos",
"events_url": "https://api.github.com/users/colbylwilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/colbylwilliams/received_events",
"type": "User",
"site_admin": false
},
"installation": {
"id": 40989628,
"node_id": "MDIzOkludGVncmF0aF32SW5zdGFsbGF0aW9uNDA5ODk2Mjg="
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"action": "deleted",
"definition": {
"property_name": "dev_platform_test"
},
"organization": {
"login": "Contoso-Inc",
"id": 128636122,
"node_id": "O_kgDOB6rU2g",
"url": "https://api.github.com/orgs/Contoso-Inc",
"repos_url": "https://api.github.com/orgs/Contoso-Inc/repos",
"events_url": "https://api.github.com/orgs/Contoso-Inc/events",
"hooks_url": "https://api.github.com/orgs/Contoso-Inc/hooks",
"issues_url": "https://api.github.com/orgs/Contoso-Inc/issues",
"members_url": "https://api.github.com/orgs/Contoso-Inc/members{/member}",
"public_members_url": "https://api.github.com/orgs/Contoso-Inc/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/128636122?v=4",
"description": "Contoso Inc brings you the best of everything. "
},
"sender": {
"login": "colbylwilliams",
"id": 1829082,
"node_id": "MDQ6VXNldfG4MjkwODI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1829082?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/colbylwilliams",
"html_url": "https://github.com/colbylwilliams",
"followers_url": "https://api.github.com/users/colbylwilliams/followers",
"following_url": "https://api.github.com/users/colbylwilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/colbylwilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/colbylwilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/colbylwilliams/subscriptions",
"organizations_url": "https://api.github.com/users/colbylwilliams/orgs",
"repos_url": "https://api.github.com/users/colbylwilliams/repos",
"events_url": "https://api.github.com/users/colbylwilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/colbylwilliams/received_events",
"type": "User",
"site_admin": false
},
"installation": {
"id": 40989628,
"node_id": "MDIzOkludGVncmF0aF32SW5zdGFsbGF0aW9uNDA5ODk2Mjg="
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"action": "updated",
"definition": {
"property_name": "dev_platform_test",
"value_type": "single_select",
"required": false,
"allowed_values": [
"option_one",
"option_two"
],
"values_editable_by": "org_and_repo_actors"
},
"organization": {
"login": "Contoso-Inc",
"id": 128636122,
"node_id": "O_kgDOB6rU2g",
"url": "https://api.github.com/orgs/Contoso-Inc",
"repos_url": "https://api.github.com/orgs/Contoso-Inc/repos",
"events_url": "https://api.github.com/orgs/Contoso-Inc/events",
"hooks_url": "https://api.github.com/orgs/Contoso-Inc/hooks",
"issues_url": "https://api.github.com/orgs/Contoso-Inc/issues",
"members_url": "https://api.github.com/orgs/Contoso-Inc/members{/member}",
"public_members_url": "https://api.github.com/orgs/Contoso-Inc/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/128636122?v=4",
"description": "Contoso Inc brings you the best of everything. "
},
"sender": {
"login": "colbylwilliams",
"id": 1829082,
"node_id": "MDQ6VXNldfG4MjkwODI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1829082?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/colbylwilliams",
"html_url": "https://github.com/colbylwilliams",
"followers_url": "https://api.github.com/users/colbylwilliams/followers",
"following_url": "https://api.github.com/users/colbylwilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/colbylwilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/colbylwilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/colbylwilliams/subscriptions",
"organizations_url": "https://api.github.com/users/colbylwilliams/orgs",
"repos_url": "https://api.github.com/users/colbylwilliams/repos",
"events_url": "https://api.github.com/users/colbylwilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/colbylwilliams/received_events",
"type": "User",
"site_admin": false
},
"installation": {
"id": 40989628,
"node_id": "MDIzOkludGVncmF0aF32SW5zdGFsbGF0aW9uNDA5ODk2Mjg="
}
}
Loading

0 comments on commit 9fc75ba

Please sign in to comment.