Skip to content
Changelog

Report a bug

GitHub

A GitHub trigger starts a managed agent automation when something changes in a repository. There are two ways to use GitHub events:

  • With instructions. The managed agent follows your instructions for each GitHub event.
  • With code. Your TypeScript runs for each GitHub event. It can filter events, read more with the GitHub CLI in the sandbox, and pass a step to an agent stage.
  • Connect GitHub to type.com, and add the connection to the Space. In the CLI, run type-cli integrations connect github.
  • Make sure that the GitHub App can see the repository. It must also subscribe to the events that you need.
  • Make sure that the Space has the skills that the managed agent needs, for example a review skill.
  • For a code automation, get the GitHub connection ID (orgint_...) and the Space ID (ch_...). To see Space IDs, run type-cli spaces list --json.

In an instruction automation, a GitHub event starts work in the Space. The managed agent follows your instructions, with the Space’s connections and skills.

Examples:

  • Review new pull requests with the team’s review skill.
  • Summarize new issues and suggest an owner.
  • Post a short note when a release is published.

The same creation flow handles schedules and incoming events. Existing legacy sources stay under Synced events.

  1. Open the Space’s Automations page (or Space settings → Automations in the settings layout).
  2. Select New automation.
  3. Choose GitHub in Trigger.
  4. If GitHub has more than one connection, choose the connection.
  5. Write the required instructions describing what to do with each event. To use a skill, write its handle, for example /pr-review.
  6. Select Create automation. No test event is required.

In the CLI:

Terminal window
type-cli automations create --space <space> --source github --integration <org-integration-id> \
--name "GitHub triage" --instructions "Summarize relevant changes; take no action on other events." --enable

Without --enable, the CLI creates the automation paused.

The new automation subscribes to every GitHub event from the connection (github.*). Each event starts a run:

  1. An agent stage follows your instructions, with the GitHub event as its input.
  2. A code stage records the agent’s result: completed or no_results, with a short summary.

The automation decides whether to post a message or take another action. You can later change it to use code, agent work, or both.

Every event that GitHub sends starts a run, including events that do not matter to you. Say in the instructions which events matter, and tell the managed agent to stop with no action for the others. To stop runs for other events, change the subscription’s events or add a GitHub matcher in the automation’s code.

A code automation runs your TypeScript when a GitHub event comes. To learn the basics, see Core concepts. For more complete automations, see Diagnose CI failures and Fix one security finding a day.

This example makes a code automation that posts in a Space when a pull request is merged into main.

src/main.ts
import { TypeApiError } from "@type-dot-com/sdk";
import { automation, code, complete } from "@type-dot-com/sdk/automations";
import { err } from "neverthrow";
import { z } from "zod";
const github = "orgint_example"; // the GitHub connection
const space = "ch_example"; // this Space
const pullRequestEvent = z.object({
type: z.string(),
id: z.string(),
resourceId: z.string().nullable(),
resourceType: z.string().nullable(),
data: z.unknown(),
});
const pullRequest = z.object({
repositoryFullName: z.string(),
title: z.string(),
url: z.string(),
});
export default automation({
output: z.object({ messageId: z.string() }),
deployment: {
subscriptions: {
onMerged: {
title: "Merged into main",
description: "Post in the Space when a pull request is merged into main",
source: {
kind: "integration",
connectionId: github,
events: ["github.pull_request.closed"],
},
match: {
"github.pull_request": {
repositories: ["acme/project"],
merged: true,
baseBranches: ["main"],
},
},
entry: "announce",
},
},
},
stages: {
announce: code({
input: pullRequestEvent,
run: async ({ ctx, input: event }) => {
const pr = pullRequest.safeParse(event.data);
if (!pr.success)
return err(
new TypeApiError("Unexpected pull request data", "invalid_input"),
);
const { repositoryFullName, title, url } = pr.data;
const sent = await ctx.write.sendMessage(
{ channelId: space, content: `Merged into main: ${title}\n${url}` },
{ effectKey: `merged:${repositoryFullName}/${event.resourceId}` },
);
if (sent.isErr()) return err(sent.error);
return complete({ messageId: sent.value.messageId });
},
}),
},
});
  • events: ["github.pull_request.closed"] selects closed pull requests. GitHub sends closed for merged pull requests too.
  • The match field uses a GitHub matcher. It selects the repository, merged pull requests, and the base branch. An event that it skips ends without running your code.
  • With no schema, the entry stage gets the generic event envelope, and data is unchecked. The code checks the fields that it uses and fails the stage when they are missing.
  • The effect key uses the repository and the pull request number (resourceId), so each merge posts once. Effect keys can use letters, digits, and ., _, :, /, -.

The example posts with ctx.write.sendMessage. Fixtures cannot answer that call, so a fixture cannot test the path that posts. See Calls that fixtures cannot answer.

Test the example in two parts:

  1. Use fixtures for the paths that end before the post. Test a pull request that the matcher skips. Also test a pull request with data that the code rejects. A GitHub matcher needs the normalized fields of its event, for example title for a pull request, so a fixture payload must include them.

    fixtures.json
    [
    {
    "name": "skips a closed pull request that is not merged",
    "subscriptionId": "onMerged",
    "payload": {
    "type": "github.pull_request.closed",
    "id": "delivery-1",
    "resourceType": "pull_request",
    "resourceId": "42",
    "data": { "repositoryFullName": "acme/project", "merged": false, "baseBranch": "main", "title": "Draft idea", "url": "https://github.com/acme/project/pull/42" }
    },
    "toolResponses": []
    },
    {
    "name": "fails on pull request data without a URL",
    "subscriptionId": "onMerged",
    "payload": {
    "type": "github.pull_request.closed",
    "id": "delivery-2",
    "resourceType": "pull_request",
    "resourceId": "43",
    "data": { "repositoryFullName": "acme/project", "merged": true, "baseBranch": "main", "title": "Fix login" }
    },
    "toolResponses": [],
    "expectedError": "Unexpected pull request data"
    }
    ]
  2. Test the post in a live run. First, set repositories to a test repository. Merge a test pull request into main. Then read the run:

    Terminal window
    type-cli automations history --space <space> --automation <automation-id>

    When the run is correct, change repositories to the real repository and deploy again.

GitHub event names have the form github.<event>.<action>. github.push and github.status have no action. Branch and tag events are github.create.branch, github.create.tag, github.delete.branch, and github.delete.tag. See the Events reference for all events and their data fields.

Each event arrives in an envelope:

  • type: the event name, for example github.pull_request.closed.
  • id: the GitHub delivery ID.
  • resourceType and resourceId: for example pull_request and the pull request number.
  • data: normalized fields, for example title, url, merged, baseBranch, and repositoryFullName.

Common choices:

Goaleventsmatch
A pull request openedgithub.pull_request.openedgithub.pull_request
A pull request mergedgithub.pull_request.closedgithub.pull_request with merged: true
A comment on a pull requestgithub.issue_comment.createdgithub.issue_comment with pullRequest: true
A review requested changesgithub.pull_request_review.submittedgithub.pull_request_review with states: ["changes_requested"]
CI failedgithub.workflow_run.completedgithub.workflow_run with conclusions: ["failure"]
A push to maingithub.pushgithub.push with refs: ["refs/heads/main"]
A release publishedgithub.release.publishedgithub.release

github.* selects every GitHub event. Other wildcards, such as github.pull_request.*, are not supported.

Use the repositories option of the matcher. The value is owner/repo, and the comparison is not case-sensitive.

The event has a summary of the change. To read more, for example the files of a pull request, run the GitHub CLI in the sandbox. Commands get GitHub credentials only for the GitHub connections of the Space.

  • Existing legacy sources retain their previous controls. New event automations can be paused and resumed from their automation editor.
  • type.com does not send deployment, deployment_status, pull_request_review_thread, label, or member events to automations.
  • The GitHub App settings decide which events GitHub sends. Saving an automation does not change these settings.
  • In code automations, type.com does not check <action> values against a list. A wrong action name deploys, but no event matches it.
  • In GitHub matchers, list filters are case-sensitive, except repositories.