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.
Before you start
Section titled “Before you start”- 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, runtype-cli spaces list --json.
With instructions
Section titled “With instructions”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.
Make an instruction automation
Section titled “Make an instruction automation”The same creation flow handles schedules and incoming events. Existing legacy sources stay under Synced events.
- Open the Space’s Automations page (or Space settings → Automations in the settings layout).
- Select New automation.
- Choose GitHub in Trigger.
- If GitHub has more than one connection, choose the connection.
- Write the required instructions describing what to do with each event. To use a skill, write its handle, for example
/pr-review. - Select Create automation. No test event is required.
In the CLI:
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." --enableWithout --enable, the CLI creates the automation paused.
The new automation subscribes to every GitHub event from the connection (github.*). Each event starts a run:
- An agent stage follows your instructions, with the GitHub event as its input.
- A code stage records the agent’s result:
completedorno_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.
Keep runs focused
Section titled “Keep runs focused”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.
With code
Section titled “With 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.
Post when a pull request is merged
Section titled “Post when a pull request is merged”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 connectionconst 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 sendsclosedfor merged pull requests too.- The
matchfield 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, anddatais 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.,_,:,/,-.
Test the example
Section titled “Test the example”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:
-
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
titlefor 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"}] -
Test the post in a live run. First, set
repositoriesto a test repository. Merge a test pull request intomain. Then read the run:Terminal window type-cli automations history --space <space> --automation <automation-id>When the run is correct, change
repositoriesto the real repository and deploy again.
Event names
Section titled “Event names”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 examplegithub.pull_request.closed.id: the GitHub delivery ID.resourceTypeandresourceId: for examplepull_requestand the pull request number.data: normalized fields, for exampletitle,url,merged,baseBranch, andrepositoryFullName.
Common choices:
| Goal | events | match |
|---|---|---|
| A pull request opened | github.pull_request.opened | github.pull_request |
| A pull request merged | github.pull_request.closed | github.pull_request with merged: true |
| A comment on a pull request | github.issue_comment.created | github.issue_comment with pullRequest: true |
| A review requested changes | github.pull_request_review.submitted | github.pull_request_review with states: ["changes_requested"] |
| CI failed | github.workflow_run.completed | github.workflow_run with conclusions: ["failure"] |
A push to main | github.push | github.push with refs: ["refs/heads/main"] |
| A release published | github.release.published | github.release |
github.* selects every GitHub event. Other wildcards, such as github.pull_request.*, are not supported.
Select repositories
Section titled “Select repositories”Use the repositories option of the matcher. The value is owner/repo, and the comparison is not case-sensitive.
Read more from GitHub
Section titled “Read more from GitHub”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.
Limitations
Section titled “Limitations”- 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, ormemberevents 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.