Skip to Content
Blocks

GitHub App

Make the app

Create a GitHub App on your account. Set the webhook address to your public SwB address plus /github/webhook. For example, use https://swb.example.com/github/webhook. Generate a webhook secret in a private file. SwB accepts secrets of at least 16 characters.

(umask 077; set -C; openssl rand -hex 32 > ~/.swb-github-secret)

Enter the secret in Webhook secret. Ask an agent to connect GitHub. Save the same secret through its claim link. Delete the private file. Restart SwB to load the secret. Ask the agent to call connect again for any remaining App ID or private key links. Paste the full contents of the .pem file in the private key field.

Permissions

Under Repository permissions, use the access levels in the table.

Repository resourceAccessEvents
IssuesRead & writeissues, issue_comment
Pull requestsRead & writepull_request, pull_request_review, pull_request_review_comment, pull_request_review_thread
ContentsRead-onlypush
ChecksRead-onlycheck_run, check_suite
ActionsRead-onlyworkflow_run
MetadataRead-only automatically

Install the app on the repositories you want.

Route events

blocks:
  github:
    use: github
    sinks:
      team: {url_env: SWB_EXAMPLE_GITHUB_SINK_URL}
    routes:
      "acme/app": [team]
      "acme/*": [team]

Set SWB_EXAMPLE_GITHUB_SINK_URL to the receiver's address in your server environment.

A sink is a URL that receives a copy of an event. SwB sends each matching sink a compact JSON event in watch mode. A repository with a sink route uses watch by default. Channel and space modes take priority. SwB quotes additional details in metadata. Each request uses the event's delivery ID as its Idempotency-Key. SwB retries connection failures, timeouts and HTTP 5xx responses.

If Cloudflare Access protects your host, let /github/webhook through. The GitHub signature protects that path.

Owner accounts

In off mode, SwB drops all GitHub events for the space, including events from owner accounts.

Use work mode to accept events from configured owner accounts only. Replace USERNAME in https://api.github.com/users/USERNAME with your GitHub username. Open the URL. Copy the numeric id into the space's owner_ids list. Restart SwB to apply the setting.

blocks:
  github:
    use: github
    spaces:
      acme/app:
        owner_ids: [4242]
        mode:
          mode: work
          target: agent:beta

Use blocks.github.owner_ids to set the default owner IDs. A space's owner_ids list replaces that default. An empty space list clears it.

SwB checks the author of each title, body or comment. The text counts as owner only when its own author is in owner_ids and is a person. SwB quotes branch names, refs, workflow titles and check names as external.

A check_run with a check name carries external trust, even when the owner triggers it. A pull request from a fork can set the check name. Use IDs such as github:4242 in access rules. These rules give access separately from trust.

For GitHub conversation actions, pass the SwB conversation ID in conversation or handle.

Config

KeyUse
blocks.githubSettings for GitHub events and actions
blocks.github.useBlock type. Use github
blocks.github.enabledSet false to skip this block
blocks.github.app_id_envName of the variable that holds the App ID
blocks.github.private_key_envName of the variable that holds the App private key
blocks.github.token_envName of the variable that holds a fine-grained token as an alternative to App credentials
blocks.github.secret_envName of the variable that holds the webhook secret
blocks.github.sinksSettings by event receiver name
blocks.github.sinks.*.url_envName of the variable that holds the receiver address
blocks.github.routesMap from repo names or owner/* to lists of event receivers
blocks.github.owner_idsDefault list of numeric GitHub user IDs trusted as owners
blocks.github.spacesNamed sets of repositories that share settings. A name such as acme/app selects that repository
blocks.github.spaces.*.repoRepository name in owner/repo form
blocks.github.spaces.*.owner_idsList of numeric GitHub user IDs that replaces the default for this space
blocks.github.spaces.*.modeDefault channel mode for the repositories in this space
blocks.github.spaces.*.mode.targetTarget in the mode settings. Choose an address such as agent:beta
blocks.github.spaces.*.projectDefault SwB project for events from this space

Bind an agent to a repository with space_mode(block="github", space="acme/app", mode="triage", target="agent:beta"). Use mode="assist" for assist mode. Choose a target from targets. The linked project route is the fallback.

For outside senders, grant access to both channel:github/acme/app and target:beta. See channel visibility for the access rules.

In watch mode, SwB sends a digest to the target mailbox after modes.digest_minutes or once it collects 50 events for that mailbox and space. See Watch digests.

On this page