-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polymorphic custom property values (fixes deserialization bug) (#521)
* Polymorphic custom properties values * Apply suggestions from code review Co-authored-by: Jamie Magee <jamie.magee@gmail.com> --------- Co-authored-by: Jamie Magee <jamie.magee@gmail.com>
- Loading branch information
1 parent
8c1296f
commit 936ebd8
Showing
13 changed files
with
323 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 21 additions & 1 deletion
22
src/Octokit.Webhooks/Models/CustomPropertyValuesEvent/CustomPropertyValue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
namespace Octokit.Webhooks.Models.CustomPropertyValuesEvent; | ||
|
||
using System.Linq; | ||
|
||
[PublicAPI] | ||
public sealed record CustomPropertyValue | ||
{ | ||
[JsonPropertyName("property_name")] | ||
public string PropertyName { get; init; } = null!; | ||
|
||
[JsonPropertyName("value")] | ||
public string? Value { get; init; } | ||
public object? Object { get; init; } | ||
|
||
public string? Value => this.Object switch | ||
{ | ||
string str => str, | ||
IEnumerable<string> strings => "[" + string.Join(",", strings) + "]", | ||
JsonElement { ValueKind: JsonValueKind.String } json => json.GetString(), | ||
JsonElement { ValueKind: JsonValueKind.Array } json => "[" + string.Join(",", json.EnumerateArray().Select(e => e.GetString()!)) + "]", | ||
_ => null, | ||
}; | ||
|
||
public IEnumerable<string>? Values => this.Object switch | ||
{ | ||
string str => [str], | ||
IEnumerable<string> strings => strings, | ||
JsonElement { ValueKind: JsonValueKind.String } json => [json.GetString()!], | ||
JsonElement { ValueKind: JsonValueKind.Array } json => json.EnumerateArray().Select(e => e.GetString()!), | ||
_ => null, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 8 additions & 6 deletions
14
test/Octokit.Webhooks.Test/Resources/custom_property/created.payload.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 14 additions & 6 deletions
20
test/Octokit.Webhooks.Test/Resources/custom_property/updated.payload.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
test/Octokit.Webhooks.Test/Resources/custom_property_values/1.updated.payload.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
{ | ||
"action": "updated", | ||
"new_property_values": [ | ||
{ | ||
"property_name": "test_ms", | ||
"value": [ | ||
"option_c", | ||
"option_d" | ||
] | ||
}, | ||
{ | ||
"property_name": "test_ss", | ||
"value": "option_b" | ||
}, | ||
{ | ||
"property_name": "test_tf", | ||
"value": "true" | ||
} | ||
], | ||
"old_property_values": [ | ||
{ | ||
"property_name": "test_ms", | ||
"value": [ | ||
"option_b", | ||
"option_c" | ||
] | ||
}, | ||
{ | ||
"property_name": "test_ss", | ||
"value": "option_c" | ||
}, | ||
{ | ||
"property_name": "test_tf", | ||
"value": "false" | ||
} | ||
], | ||
"repository": { | ||
"id": 798052885, | ||
"node_id": "R_kgDOL5FSFQ", | ||
"name": "demo01", | ||
"full_name": "Contoso-Inc/demo01", | ||
"private": false, | ||
"owner": { | ||
"login": "Contoso-Inc", | ||
"id": 128636122, | ||
"node_id": "O_kgDOB6rU2g", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/128636122?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/Contoso-Inc", | ||
"html_url": "https://github.com/Contoso-Inc", | ||
"followers_url": "https://api.github.com/users/Contoso-Inc/followers", | ||
"following_url": "https://api.github.com/users/Contoso-Inc/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/Contoso-Inc/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/Contoso-Inc/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/Contoso-Inc/subscriptions", | ||
"organizations_url": "https://api.github.com/users/Contoso-Inc/orgs", | ||
"repos_url": "https://api.github.com/users/Contoso-Inc/repos", | ||
"events_url": "https://api.github.com/users/Contoso-Inc/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/Contoso-Inc/received_events", | ||
"type": "Organization", | ||
"site_admin": false | ||
}, | ||
"html_url": "https://github.com/Contoso-Inc/demo01", | ||
"description": null, | ||
"fork": false, | ||
"url": "https://api.github.com/repos/Contoso-Inc/demo01", | ||
"forks_url": "https://api.github.com/repos/Contoso-Inc/demo01/forks", | ||
"keys_url": "https://api.github.com/repos/Contoso-Inc/demo01/keys{/key_id}", | ||
"collaborators_url": "https://api.github.com/repos/Contoso-Inc/demo01/collaborators{/collaborator}", | ||
"teams_url": "https://api.github.com/repos/Contoso-Inc/demo01/teams", | ||
"hooks_url": "https://api.github.com/repos/Contoso-Inc/demo01/hooks", | ||
"issue_events_url": "https://api.github.com/repos/Contoso-Inc/demo01/issues/events{/number}", | ||
"events_url": "https://api.github.com/repos/Contoso-Inc/demo01/events", | ||
"assignees_url": "https://api.github.com/repos/Contoso-Inc/demo01/assignees{/user}", | ||
"branches_url": "https://api.github.com/repos/Contoso-Inc/demo01/branches{/branch}", | ||
"tags_url": "https://api.github.com/repos/Contoso-Inc/demo01/tags", | ||
"blobs_url": "https://api.github.com/repos/Contoso-Inc/demo01/git/blobs{/sha}", | ||
"git_tags_url": "https://api.github.com/repos/Contoso-Inc/demo01/git/tags{/sha}", | ||
"git_refs_url": "https://api.github.com/repos/Contoso-Inc/demo01/git/refs{/sha}", | ||
"trees_url": "https://api.github.com/repos/Contoso-Inc/demo01/git/trees{/sha}", | ||
"statuses_url": "https://api.github.com/repos/Contoso-Inc/demo01/statuses/{sha}", | ||
"languages_url": "https://api.github.com/repos/Contoso-Inc/demo01/languages", | ||
"stargazers_url": "https://api.github.com/repos/Contoso-Inc/demo01/stargazers", | ||
"contributors_url": "https://api.github.com/repos/Contoso-Inc/demo01/contributors", | ||
"subscribers_url": "https://api.github.com/repos/Contoso-Inc/demo01/subscribers", | ||
"subscription_url": "https://api.github.com/repos/Contoso-Inc/demo01/subscription", | ||
"commits_url": "https://api.github.com/repos/Contoso-Inc/demo01/commits{/sha}", | ||
"git_commits_url": "https://api.github.com/repos/Contoso-Inc/demo01/git/commits{/sha}", | ||
"comments_url": "https://api.github.com/repos/Contoso-Inc/demo01/comments{/number}", | ||
"issue_comment_url": "https://api.github.com/repos/Contoso-Inc/demo01/issues/comments{/number}", | ||
"contents_url": "https://api.github.com/repos/Contoso-Inc/demo01/contents/{+path}", | ||
"compare_url": "https://api.github.com/repos/Contoso-Inc/demo01/compare/{base}...{head}", | ||
"merges_url": "https://api.github.com/repos/Contoso-Inc/demo01/merges", | ||
"archive_url": "https://api.github.com/repos/Contoso-Inc/demo01/{archive_format}{/ref}", | ||
"downloads_url": "https://api.github.com/repos/Contoso-Inc/demo01/downloads", | ||
"issues_url": "https://api.github.com/repos/Contoso-Inc/demo01/issues{/number}", | ||
"pulls_url": "https://api.github.com/repos/Contoso-Inc/demo01/pulls{/number}", | ||
"milestones_url": "https://api.github.com/repos/Contoso-Inc/demo01/milestones{/number}", | ||
"notifications_url": "https://api.github.com/repos/Contoso-Inc/demo01/notifications{?since,all,participating}", | ||
"labels_url": "https://api.github.com/repos/Contoso-Inc/demo01/labels{/name}", | ||
"releases_url": "https://api.github.com/repos/Contoso-Inc/demo01/releases{/id}", | ||
"deployments_url": "https://api.github.com/repos/Contoso-Inc/demo01/deployments", | ||
"created_at": "2024-05-09T02:09:11Z", | ||
"updated_at": "2024-05-09T02:09:12Z", | ||
"pushed_at": "2024-05-09T02:09:12Z", | ||
"git_url": "git://github.com/Contoso-Inc/demo01.git", | ||
"ssh_url": "git@github.com:Contoso-Inc/demo01.git", | ||
"clone_url": "https://github.com/Contoso-Inc/demo01.git", | ||
"svn_url": "https://github.com/Contoso-Inc/demo01", | ||
"homepage": null, | ||
"size": 0, | ||
"stargazers_count": 0, | ||
"watchers_count": 0, | ||
"language": null, | ||
"has_issues": true, | ||
"has_projects": true, | ||
"has_downloads": true, | ||
"has_wiki": true, | ||
"has_pages": false, | ||
"has_discussions": false, | ||
"forks_count": 0, | ||
"mirror_url": null, | ||
"archived": false, | ||
"disabled": false, | ||
"open_issues_count": 0, | ||
"license": null, | ||
"allow_forking": true, | ||
"is_template": false, | ||
"web_commit_signoff_required": false, | ||
"topics": [], | ||
"visibility": "public", | ||
"forks": 0, | ||
"open_issues": 0, | ||
"watchers": 0, | ||
"default_branch": "main", | ||
"custom_properties": { | ||
"dev_platform": "workflows" | ||
} | ||
}, | ||
"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": "markweitzel", | ||
"id": 522116, | ||
"node_id": "MDQ6VXNlcjUyMjExNg==", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/522116?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/markweitzel", | ||
"html_url": "https://github.com/markweitzel", | ||
"followers_url": "https://api.github.com/users/markweitzel/followers", | ||
"following_url": "https://api.github.com/users/markweitzel/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/markweitzel/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/markweitzel/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/markweitzel/subscriptions", | ||
"organizations_url": "https://api.github.com/users/markweitzel/orgs", | ||
"repos_url": "https://api.github.com/users/markweitzel/repos", | ||
"events_url": "https://api.github.com/users/markweitzel/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/markweitzel/received_events", | ||
"type": "User", | ||
"site_admin": false | ||
}, | ||
"installation": { | ||
"id": 40989628, | ||
"node_id": "MDIzOkludGVncmF0aF32SW5zdGFsbGF0aW9uNDA5ODk2Mjg=" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.