Skip to content

A middleware designed to sort your repository feeds into Discord forum posts. Built with Cloudflare Workers.

License

Notifications You must be signed in to change notification settings

biaw/gitcord-forum

Repository files navigation

Image of the forum channel on Discord

Explanation

Instead of having a single Discord channel for all your GitHub repository feeds, or having a separate tech channel for each repository, you can use this worker to create a forum post for each repository and sort your GitHub activity into those forum posts individually. This way, you can have a single channel for all your GitHub activity, but still keep it organized by repository - and users can easily follow the forum posts that they are interested in.

Screenshot Image of the forum channel on Discord

Setting up with Cloudflare Workers

Deploy to Cloudflare Workers

  1. Deploy to Cloudflare Workers using the button above. It should be as simple as keeping all defaults, unless you want to change some predefined variables.
  2. Insert the two variable secrets, either via the Cloudflare Workers dashboard (recommended) or using the command wrangler secret put <key>:
    • GITHUB_WEBHOOK_SECRET - your secret for webhooks (like a phrase or a word) to verify that the webhook is coming from GitHub. This needs to match the secret you set in your GitHub webhook settings.
    • DISCORD_WEBHOOK - your Discord webhook link (needs to be in a forum channel!). The link should not end in /github as the worker will append that automatically.
  3. Add your new worker URL (https://gitcord-forum.WORKER_SUBDOMAIN.workers.dev/) as a webhook in your GitHub repository settings with your preferred set of notifications to get from the repository. Make sure to set content type to application/json and also match the secret you set in the environment variables.
    • Make sure that the repository event is enabled. Although not supported by Discord, it is recommended to enable updates to the first message in the forum channel.
    • You can also add this URL as a webhook for your entire GitHub organization!

Keep in mind that the worker will simply forward the GitHub events to Discord, so you will make sure that Discord has support for the events you want to pass through. See Discord's documentation for a list of supported events. The worker will automatically ignore events that are not supported by Discord, and will rather use these events to update the first message in the forum channel with the latest information about the repository. We therefore recommend enabling the repository event in your webhook settings, so it can get infrequent updates about the repository.

How the middleware works

sequenceDiagram
    autonumber
    participant G as GitHub
    participant W as Cloudflare Worker & Storage
    participant D as Discord Webhook

    activate G
    G->>W: Send a Webhook event
    activate W

    alt signature header is not valid
        W->>G: 401 Unauthorized
    end

    alt event is ignored in some way, e.g. if it's not from a repository or is from a sender which is ignored
        W->>G: 202 Accepted "GitHub event ignored"
    end

    W->>W: Find thread ID for repository

    alt no forum thread exists
        W->>D: Create a new forum thread and send first message
        D->>W: Return message data with thread ID
        W->>W: Save thread ID and message ID
    else forum thread exists
        W->>D: Update first forum message with new information
    end

    W->>D: Forward GitHub event to new or existing forum thread
    D->>W: Response back from Discord including the rate limit headers
    W->>G: Passthrough Discord's response
Loading

About

A middleware designed to sort your repository feeds into Discord forum posts. Built with Cloudflare Workers.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors 2

  •  
  •