Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: ProcessDeployProtectionRuleWebhookAsync seems to have the wrong argument type #546

Closed
1 task done
justinmchase opened this issue Aug 7, 2024 · 3 comments · Fixed by #549
Closed
1 task done
Labels
Type: Bug Something isn't working as documented

Comments

@justinmchase
Copy link

What happened?

The second argument is of type DeploymentProtectionRuleEvent but it should be DeploymentProtectionRuleRequestedEvent.

There are a bunch of fields on the payload that are inaccessible as a result.

Bug is on this line:
https://github.com/octokit/webhooks.net/blob/main/src/Octokit.Webhooks/WebhookEventProcessor.cs#L178

Should be:

            WebhookEventType.DeploymentProtectionRule => JsonSerializer.Deserialize<DeploymentProtectionRuleRequestedEvent>(body)!,

Versions

webhooks.net latest version

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@justinmchase justinmchase added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Aug 7, 2024
Copy link

github-actions bot commented Aug 7, 2024

👋 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! 🚀

@justinmchase
Copy link
Author

justinmchase commented Aug 7, 2024

I was able to work around this with the following:

public override WebhookEvent DeserializeWebhookEvent(WebhookHeaders headers, string body)
{
  return headers.Event switch
  {
    "deployment_protection_rule" => JsonSerializer.Deserialize<DeploymentProtectionRuleRequestedEvent>(body),
    _ => base.DeserializeWebhookEvent(headers, body)
  };
}

protected override async Task ProcessDeployProtectionRuleWebhookAsync(
  WebhookHeaders headers,
  DeploymentProtectionRuleEvent deploymentProtectionRuleEvent,
  DeploymentProtectionRuleAction action
)
{
  if (deploymentProtectionRuleEvent is DeploymentProtectionRuleRequestedEvent deploymentProtectionRuleRequestedEvent)
  {
    await ProcessDeployProtectionRuleRequestedAsync(deploymentProtectionRuleRequestedEvent);
  }
}

protected async Task ProcessDeployProtectionRuleRequestedAsync(
  DeploymentProtectionRuleRequestedEvent evt
)
{
  // todo: implement...
}

@JamieMagee
Copy link
Contributor

I don't think this is a bug. The pattern we're following is that we have a common abstract class that contains all the common properties between each different event action type, and each concrete action type only has the specific properties for the action.

So DeploymentProtectionRuleEvent is the abstract base class for the deployment_protection_rule event, and DeploymentProtectionRuleRequestedEvent is the concrete implementation for the requested action. It looks like in this case, all of the properties are on the concrete implementation. But I suspect that's because it's the only action for that event. We don't know what's common until we have 2 actions for an event.

I think your workaround is not so much a workaround, but how I would expect the SDK to be used. All you should need is:

protected override async Task ProcessDeployProtectionRuleWebhookAsync(
  WebhookHeaders headers,
  DeploymentProtectionRuleEvent deploymentProtectionRuleEvent,
  DeploymentProtectionRuleAction action
)
{
  if (deploymentProtectionRuleEvent is DeploymentProtectionRuleRequestedEvent deploymentProtectionRuleRequestedEvent)
  {
    // do whatever here
  }
}

I think we could also move the properties from DeploymentProtectionRuleRequestedEvent to DeploymentProtectionRuleEvent, and re-evaluate what is actually common when another action is added for this event.

@kfcampbell kfcampbell moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Aug 16, 2024
@kfcampbell kfcampbell removed the Status: Triage This is being looked at and prioritized label Aug 16, 2024
@github-project-automation github-project-automation bot moved this from 🔥 Backlog to ✅ Done in 🧰 Octokit Active Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
Archived in project
3 participants