Skip to content

[Webhooks] Add a github provider #58471

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

Closed
tacman opened this issue Oct 6, 2024 · 10 comments
Closed

[Webhooks] Add a github provider #58471

tacman opened this issue Oct 6, 2024 · 10 comments

Comments

@tacman
Copy link
Contributor

tacman commented Oct 6, 2024

Description

The providers on https://symfony.com/doc/current/webhook.html are for email and notifiers (like SMS). Since every developer using Symfony has a github account and many use github for their applications, a native github provider would be useful.

Example

use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
use Symfony\Component\RemoteEvent\Event\Github\IssueEvent;
use Symfony\Component\RemoteEvent\Event\Github\PullRequestEvent;
use Symfony\Component\RemoteEvent\RemoteEvent;

#[AsRemoteEventConsumer('github')]
class WebhookListener implements ConsumerInterface
{
    public function consume(RemoteEvent $event): void
    {
        if ($event instanceof IssueEvent) {
            $this->handleIssueEvent($event);
        } elseif ($event instanceof PullRequestEvent) {
            $this->handlePullRequestEvent($event);
        } else {
            // This is not an Github event
            return;
        }
    }

}
@tacman
Copy link
Contributor Author

tacman commented Oct 6, 2024

@fabpot
Copy link
Member

fabpot commented Oct 7, 2024

Sounds good to me.

@tacman
Copy link
Contributor Author

tacman commented Oct 7, 2024

Can you give me some guidance on how to set this up as a bundle? I imagine in the GithubWebhookBundle.php there's a service that has a tag on it, and then the application that uses the bundle adds a RemoteEventConsumer?

@stof
Copy link
Member

stof commented Oct 7, 2024

To me, parsing GitHub webhook payloads into a RemoteEvent is not something that belongs in the core of Symfony. Our parsers in core bridges are all about parsing a subset of the webhook payload into a shared abstraction of mailer or notifier webhooks. GitHub webhooks don't make sense in those abstraction.

Writing a dedicated GitHub-specific webhook request parser exposing the full GitHub payload to write GitHub-specific webhook consumers is something that should be provided by a bundle out of core IMO (which would also allow it to make releases much more often, to react to changes in the GitHub webhooks to add new fields for instance).
That bundle can reuse all the infrastructure of symfony/webhook in the core. It will mostly need to implement the appropriate RequestParser and register it as a service that projects can use in the webhook routing (which can even be provided in a recipe): https://symfony.com/doc/current/webhook.html

@norkunas
Copy link
Contributor

norkunas commented Oct 7, 2024

Symfony's @carsonbot uses github webhooks so if git webhook abstraction would be integrated in core, it could be direct user of this

@stof
Copy link
Member

stof commented Oct 7, 2024

if it is in a bundle, it could also use the bundle. The fact that one of our tool has such need is not a sufficient argument to bring it in core.
A SDK for GitHub webhook payloads needs to adapt constantly to the evolution of GitHub. A 6-month release schedule is not adapted for it.

@tacman
Copy link
Contributor Author

tacman commented Oct 7, 2024

Perhaps it would be a good fit for https://github.com/KnpLabs/php-github-api

Just brainstorming: The bundle could provide a command line tool that registers the webhook on github.

bin/console github:register https://my-application  --event=issue.new --event=pull.request --event=release.new

(I'm making up these event names).

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?
Every feature is developed by the community.
Perhaps someone would like to try?
You can read how to contribute to get started.

@carsonbot
Copy link

Friendly reminder that this issue exists. If I don't hear anything I'll close this.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

@carsonbot carsonbot closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants