Getting started

If you have not yet set up Trigger.dev in your project, go to the quick start guide.

Installation

npm install @trigger.dev/github@latest

Authentication

GitHub supports Personal Access Tokens and OAuth.

import { Github } from "@trigger.dev/github";

//create GitHub client using a token
const github = new Github({
  id: "github",
  token: process.env.GITHUB_TOKEN!,
});

//create GitHub client using OAuth
const github2 = new Github({
  id: "github2",
});

Triggers and Tasks

Using the underlying client

You can use the underlying client to do anything Octokit supports. In this example we create a project card when a new issue is opened..

View the official GitHub docs for everything that is supported

import { Github, events } from "@trigger.dev/github";

const github = new Github({
  id: "github",
  token: process.env.GITHUB_TOKEN!,
});

client.defineJob({
  id: "alert-on-new-github-issues",
  name: "Alert on new GitHub issues",
  version: "0.1.1",
  trigger: github.triggers.repo({
    event: events.onIssueOpened,
    owner: "triggerdotdev",
    repo: "trigger.dev",
  }),
  integrations: {
    github,
  },
  run: async (payload, io, ctx) => {
    //io.github.runTask allows you to use the underlying SDK client
    const { data } = await io.github.runTask(
      "create-card",
      async (client) => {
        return client.rest.projects.createCard({
          column_id: 123,
          note: "test",
        });
      },
      { name: "Create card" }
    );

    //log the url of the created card
    await io.logger.info(data.url);
  },
});