Skip to content

Conversation

@martincostello
Copy link
Contributor

Resolves #711


Before the change?

  • Custom repository_dispatch events cannot be deserialized.

After the change?

  • Custom repository_dispatch payloads can be deserialized

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

  • Yes
  • No

Copilot AI review requested due to automatic review settings July 13, 2025 08:47
@github-actions
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for user-defined repository_dispatch actions by introducing a custom event type and updating the converter to fall back to it when an action isn’t recognized.

  • Added a new RepositoryDispatchCustomEvent record inheriting from RepositoryDispatchEvent
  • Updated WebhookConverter to detect unregistered actions and route them to the custom event
  • Provided a sample JSON payload for testing custom repository_dispatch events

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/Octokit.Webhooks.Test/Resources/repository_dispatch/custom.payload.json New sample payload illustrating a custom action
src/Octokit.Webhooks/Events/RepositoryDispatch/RepositoryDispatchCustomEvent.cs New empty record type for custom repository_dispatch events
src/Octokit.Webhooks/Converter/WebhookConverter.cs Logic updated to map unknown actions to the custom event type
Comments suppressed due to low confidence (3)

src/Octokit.Webhooks/Converter/WebhookConverter.cs:36

  • [nitpick] Using a local variable named type shadows the System.Type class and can cause confusion. Consider renaming this variable to eventType or targetType for clarity.
        Type? type = null;

test/Octokit.Webhooks.Test/Resources/repository_dispatch/custom.payload.json:1

  • A JSON sample for a custom repository_dispatch event has been added, but there isn’t a corresponding unit test to deserialize it into RepositoryDispatchCustomEvent. Please add a test in WebhookConverterTests to verify this mapping.
{

src/Octokit.Webhooks/Converter/WebhookConverter.cs:46

  • The fallback condition for custom repository_dispatch events checks if typeToConvert == typeof(RepositoryDispatchEvent), but the converter is registered for WebhookEvent so this never matches. You may need to detect repository_dispatch by inspecting the JSON or adjust the type check to ensure custom events are correctly routed.
        if (type == null && typeToConvert == typeof(Events.RepositoryDispatchEvent))

martincostello added a commit to martincostello/costellobot that referenced this pull request Jul 13, 2025
- `dynamic` is a `JsonElement`.
- Add integration tests.
- Pick up fix from octokit/webhooks.net#712.
martincostello added a commit to martincostello/costellobot that referenced this pull request Jul 13, 2025
- `dynamic` is a `JsonElement`.
- Add integration tests.
- Pick up fix from octokit/webhooks.net#712.
- Add support for deserializing user-defined `repository_dispatch` payloads.
- Simplify reflection to get attributes.
- Use dictionary instead of iterating it.
- Use constant instead of computing string per-deserialization.
@martincostello martincostello force-pushed the custom-repository_dispatch branch from 44f0a20 to 9251df1 Compare July 14, 2025 09:38
@JamieMagee
Copy link
Member

Thanks for this! But since I merged #708, this is going to come in a major release.

@JamieMagee JamieMagee merged commit 5c645c2 into octokit:main Jul 14, 2025
7 checks passed
@github-project-automation github-project-automation bot moved this from 🆕 Triage to ✅ Done in 🧰 Octokit Active Jul 14, 2025
@martincostello martincostello deleted the custom-repository_dispatch branch July 14, 2025 16:06
@martincostello
Copy link
Contributor Author

this is going to come in a major release.

Do you have a rough ETA on v3? Would prefer to not have to consume the NuGet packages from CI directly (I don't like the need to use a GitHub PAT to get packages from the repo's NuGet artifacts feed).

@JamieMagee
Copy link
Member

@martincostello I need to get #716 in, and I am also considering #710. I was wondering if I could get your opinion on it please?

@JamieMagee
Copy link
Member

@martincostello did v3.0.0 work for you?

@martincostello
Copy link
Contributor Author

Yes, great thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

[BUG]: Cannot deserialize custom repository_dispatch events

2 participants