Skip to content

1 intro

tei187 edited this page Jan 15, 2025 · 1 revision

Overview

The GitHub-Discord Webhook package is a powerful integration tool that seamlessly connects GitHub repositories with Discord channels. It allows for customizable notifications of various GitHub events to be sent directly to specified Discord channels.

Key Components

Factories

The package utilizes three main factories:

PayloadFactory

  • Located in src\Factories\PayloadFactory.php
  • Creates payload instances based on GitHub events
  • Uses PayloadResolver to determine the appropriate payload class

WebhookFactory

  • Located in src\Factories\WebhookFactory.php
  • Creates webhook profiles based on configuration settings
  • Extracts webhook name from the request URI

MessageFactory

  • Located in src\Factories\MessageFactory.php
  • Creates message objects based on events and webhook data
  • Supports custom overrides for message classes

Configuration

The package uses configuration files to manage webhooks and messages:

  • Webhook settings: config\webhooks.php
  • Message settings: config\messages.php

Main Execution Flow

The main execution flow is handled in index.php:

  1. Create appropriate payload
  2. Create webhook profile
  3. Create message object
  4. Send the message if all objects are successfully created

Setup and Usage

  1. Configure Discord webhook in your server
  2. Set up webhook configuration in config\webhooks.php
  3. Configure other settings (or use defaults)
  4. Register webhook in your GitHub repository
  5. Ensure the payload URL follows the format: http://example.com/webhook/[webhook-name]

Features

  • Multiple webhook support for different repositories and Discord channels
  • Customizable notifications for various GitHub events
  • Easy setup and configuration
  • Flexible message class system with override capabilities

Interfaces

The package uses several interfaces to ensure consistency:

  • PayloadInterface
  • WebhookInterface
  • MessageInterface

These interfaces are implemented by the respective classes to maintain a standardized structure throughout the package.

Error Handling

The package uses ResponseHandler to manage and send error messages, ensuring smooth operation and helpful debugging.

Extensibility

The modular design of the package allows for easy extension and customization of payload, webhook, and message classes to suit specific needs.

Clone this wiki locally