Pero Grubač

GitHub Discord Bot

Manage GitHub issues and get activity reports from Discord.

Render · one Python processadd, closeREST · to_threadsigned webhooksave issueissues, repositoriescards, through the bot's event loopreport, reminderYoucommands, buttons, formsOwner checkcommands, buttons, menusCogs and viewsClose, menus, pagers, formScheduled tasksmonthly report, reminderIssue actionsGitHub first, then the DBFlask thread/webhook · /healthDiscord channelsnotifications, reportsGitHub APIissues, commits, searchSupabasePostgreSQL
One Python process on Render runs the Discord bot on the asyncio event loop and a Flask server on its own thread for GitHub's webhook. Every command, button and menu passes the owner check first. Issue actions change GitHub first and the database second, and remember each change for five minutes, so the webhook GitHub sends back for it updates Supabase but posts nothing. Calls to GitHub and Supabase run in threads, so the bot keeps answering Discord while it waits.
  • /add create an issue, in one line or a form
  • /list open issues, with a menu to close one
  • /done close an issue
  • /today issues created today
  • /stale open issues older than 14 days
  • /repos registered repositories
  • /register register one repository
  • /sync-repos register every repository you own
  • /repo-info language, stars, forks, last push
  • /stats commits & issues by period
  • /streak commit streak
  • /top-repo most active repo this month
  • /help every command, grouped

What it does

GitHub Discord Bot brings my GitHub account into a Discord server. I built it for the Human–Computer Interaction course, so the interaction design mattered as much as the integration: autocomplete wherever a value can be guessed, buttons and menus instead of typed numbers, a form when there is more to say, and one card style whose colours carry meaning.

/add opens a GitHub issue in one line, or through a form with a description field when there is no title. Words such as crash, ne radi, add or readme in the title add the bug, enhancement or documentation label. Every new issue comes back as a card with a link to GitHub and a Close button, and /list shows the open issues across all repositories, with a menu to close any of them and pages instead of a cut-off list.

For activity, /stats counts commits and issues per repository for the last 7 days, this month or last month, /streak works out the current commit streak and the longest one in the last 90 days, and /top-repo names the most active repository of the month. The bot also posts on its own: a monthly report on the 1st and a reminder of stale issues every Monday, both at 09:00 in my time zone.

It works the other way round too. Issues opened or closed on GitHub, pull requests opened or merged, failed CI runs and published releases appear in a Discord channel through a signed webhook, while changes made from Discord are not announced a second time. Only the owner can use any of it, even if others on the server see the commands.

Architecture

One Python process runs two things: the Discord bot on the asyncio event loop, and a small Flask server on its own thread for GitHub’s webhook and the health check.

  • The Cogs hold the slash commands, one module per area: issues, repositories, stats with the monthly report, activity, and reminders with the weekly task. Every command, autocomplete, button and menu passes the same owner check first.
  • The views are the buttons, menus, pagers and the issue form. Their state lives in their custom_id, so the Close button and the /list controls still work on old messages after a restart.
  • Issue actions open and close issues for the commands, the buttons and the form alike: GitHub first, then the database.
  • The webhook thread verifies each delivery, saves issue changes to the database, and hands the card to the bot’s event loop to post.
  • core/ holds the pure logic (labels, periods, paging, streaks, reports and access), and ui/embeds.py every card the bot sends, with Discord’s limits in one place.
  • Supabase keeps the registered repositories and the issues, one row per repository and issue number.

The GitHub and Supabase clients are synchronous, so every call goes through asyncio.to_thread and the bot keeps answering Discord while it waits.

Decisions and why

  • Owner only, checked once. Strangers get a private “not for you” card, and their autocomplete shows nothing.
  • One server, no global commands. The commands are synced to the configured server only, so a change shows up at once and nothing is listed twice.
  • GitHub first, database second. An issue is marked closed in the database only after GitHub accepted it, so a failure never leaves the two disagreeing.
  • One card per action. Before the bot changes something on GitHub it remembers the change for five minutes, so the webhook GitHub sends back updates the database but posts nothing.
  • A form only when it helps. /add with a title is one line; without one it opens a form, because a description doesn’t fit in a slash option.
  • My clock, not the server’s. “Today”, the streaks and the scheduled messages follow the configured time zone, daylight saving included; GitHub always gets UTC.
  • Fewer requests. Repositories whose last push is older than the requested period are skipped, the rest are fetched in parallel, and repository names for autocomplete are cached for a minute.
  • One unreadable repository doesn’t sink a report. If the token may not read a repository’s commits (403), /stats, /streak and /top-repo leave it out and log a warning instead of failing.

Security

  • The webhook is signed. Each delivery is checked against X-Hub-Signature-256 with HMAC-SHA256, compared in constant time, and a bad signature gets 401.
  • Owner only. Nobody else on the server can create, close or browse issues, whatever they can see.
  • No privileged intents. The bot uses only slash commands and components, so it never asks to read message content.
  • A least-privilege token. The bot runs with a fine-grained GitHub token with an expiry date: read-only metadata and contents, and read and write issues.
  • Settings are checked at start-up. The bot reads every setting from the environment and lists all the missing or invalid ones in one error instead of starting half-configured.

Testing and deployment

There are 237 tests with pytest, pytest-asyncio and responses, at 99% coverage. They run in a few seconds with no network: the GitHub API is mocked, the commands run as async tests, and the pure logic in core/ is tested with plain values. GitHub Actions runs Ruff and the tests on every push to master, but not when only the README, the demo GIF or other documentation changed, and a newer push cancels the run still in progress.

The bot runs as one web service on Render, from a Blueprint. Render deploys only after CI passes and ignores commits that only touch tests, workflows or documentation, so a README edit never restarts the bot. A free Render service sleeps after 15 minutes without HTTP traffic, which would also disconnect the bot, so UptimeRobot calls /health every five minutes. A daily task also reads one row from Supabase, so the free database is never paused for inactivity.

HomepageAboutsectionSystemssectionIndex of projectssectionBrowser appspageContactsectionIncident Alertsystem · case studyeMobilityHubsystem · case studyChat Roomsystem · case studyOnline Library Systemsystem · case studyRepoHealthlive app · case studyOpen RepoHealth app (opens in a new tab)live appGitHub Discord Bottool · case studyBookstore APIweb project · case studyFitForgemobile app · case studyAssetManagermobile app · case studyStore Managementdesktop app · case studyETF Oglasimobile app · case studyDevKitlive app · case studyOpen DevKit app (opens in a new tab)live appDev Timelinelive app · case studyOpen Dev Timeline app (opens in a new tab)live appGitHub Dashboardlive app · case studyOpen GitHub Dashboard app (opens in a new tab)live appStore Chain Managementdesktop app · case studySecure Repositorytool · case studyMinimal Blogweb project · case studyCatan Map Generatorlive app · case studyOpen Catan Map Generator app (opens in a new tab)live appMonte Carlo π · Pythonlive app · case studyOpen Monte Carlo π · Python app (opens in a new tab)live appBrick Breakerlive app · case studyOpen Brick Breaker app (opens in a new tab)live appArcane Keeplive app · case studyOpen Arcane Keep app (opens in a new tab)live appe-Mobility Rentaldesktop app · case studyCountdownlive app · case studyOpen Countdown app (opens in a new tab)live appANOVAdesktop app · case studyEcho Playerdesktop app · case studyMonte Carlo πdesktop app · case studyexcuse.exelive app · case studyOpen excuse.exe app (opens in a new tab)live appYamb Tablelive app · case studyOpen Yamb Table app (opens in a new tab)live appSedmicalive app · case studyOpen Sedmica app (opens in a new tab)live appLora Score Tablelive app · case studyOpen Lora Score Table app (opens in a new tab)live appSnake (Blavor)desktop app · case study
Copy emailpero.grubac00@gmail.com