DEV Community

Ramu Narasinga
Ramu Narasinga

Posted on

Here is how the Github bot is built in Background Agents codebase.

In this article, we review the Github bot in Background Agents codebase. You will learn:

  1. What is Background Agents?

  2. What is this Github bot?

What is Background Agents?

Background Agents is an open-source background agents coding system.

Features

  1. Let your whole team ship code. Not just engineers.
  2. Anyone can start. No configuration required.
  3. Requests become PRs, not backlogs
  4. Scale your team without scaling headcount
  5. Meet agents where you work
  6. Every session is collaborative

Learn more about Background Agents..

What is a Github bot?

In the Background Agents codebase, there is a coding agent that uses this Github bot. You will find the below comment in the background-agents/packages/github-bot/src/index.ts.

/**
 * Open-Inspect GitHub Bot Worker
 *
 * Cloudflare Worker that handles GitHub webhook events and provides
 * automated code review and comment-triggered actions via the coding agent.
 */
Enter fullscreen mode Exit fullscreen mode

So this Github bot does the code review and handles actions triggered via comments on the PR.
In this dispatch handler function, you can see the cases handled:

function dispatchHandler(
  env: Env,
  log: Logger,
  event: string | undefined,
  p: Record<string, unknown>,
  payload: unknown,
  traceId: string
): Promise<HandlerResult> {
  switch (event) {
    case "pull_request":
      if (p.action === "opened") {
        return handlePullRequestOpened(env, log, payload as PullRequestOpenedPayload, traceId);
      }
      if (p.action === "review_requested") {
        return handleReviewRequested(env, log, payload as ReviewRequestedPayload, traceId);
      }
      return Promise.resolve({
        outcome: "skipped",
        skip_reason: "unsupported_action",
      });
    case "issue_comment":
      if (p.action === "created") {
        return handleIssueComment(env, log, payload as IssueCommentPayload, traceId);
      }
      return Promise.resolve({
        outcome: "skipped",
        skip_reason: "unsupported_action",
      });
    case "pull_request_review_comment":
      if (p.action === "created") {
        return handleReviewComment(env, log, payload as ReviewCommentPayload, traceId);
      }
      return Promise.resolve({
        outcome: "skipped",
        skip_reason: "unsupported_action",
      });
    default:
      return Promise.resolve({
        outcome: "skipped",
        skip_reason: "unsupported_event",
      });
  }
}
Enter fullscreen mode Exit fullscreen mode

How is Github bot built?

Background agents use Cloudflare Worker to handle GitHub webhook events.

It has these 2 endpoints defined:

app.get("/health", (c) => c.json({ status: "healthy", service: "open-inspect-github-bot" }));

app.post("/webhooks/github", async (c) => {
Enter fullscreen mode Exit fullscreen mode

About me:

Hey, my name is ramunarasinga. Email: ramunarasinga@gmail.com

Tired of AI slop?

I spent 3+ years studying OSS codebases and wrote 350+ articles on what makes them production-grade. I built

Get started for free - thinkthroo.com.

References:

  1. backgroundagents.dev/.

  2. background-agents/packages/github-bot/src/index.ts.

Top comments (0)