These are the docs for Trigger.dev v2 which will be deprecated on January 31st, 2025. You probably want the v3 docs.

Tasks are executed after the job is triggered and are the main building blocks of a job. You can string together as many tasks as you want.


All tasks

createIssue

Creates a new issue in a repository. Official GitHub docs.

example.ts
await io.github.createIssue("create issue", {
  owner: "<owner-name>", // the name of the owner of the repository
  repo: "<repo-name>", // the name of the repository
  title: "<issue-title>", // the title of the issue
  body: "<issue-description>", // the contents of the issue
});

addIssueAssignees

Adds assignees to an existing issue. Official GitHub docs.

example.ts
await io.github.addIssueAssignees("add assignee", {
  owner: "<owner-name>", // the name of the owner of the repository
  repo: "<repo-name>", // the name of the repository
  issueNumber: <issue-number>, // the number of the issue
  assignees: ["<assignee-name>"], // the name(s) of the assignee(s)
});

addIssueLabels

Adds labels to an existing issue. Official GitHub docs.

example.ts
await io.github.addIssueLabels("add label", {
  owner: "<owner-name>", // the name of the owner of the repository
  repo: "<repo-name>", // the name of the repository
  issueNumber: <issue-number>, // the number of the issue
  labels: ["<label-name>"], // the name(s) of the label(s)
});

createIssueComment

Creates a new comment on an existing issue. Official GitHub docs.

example.ts
await io.github.createIssueComment("create comment", {
  owner: "<owner-name>", // the name of the owner of the repository
  repo: "<repo-name>", // the name of the repository
  issueNumber: <issue-number>, // the number of the issue
  body: "<comment-text>", // the contents of the comment
});

getRepo

Retrieves information about a repository. Official GitHub docs.

example.ts
const repoInfo = await io.github.getRepo({
  owner: "<owner-name>", // the name of the owner of the repository
  repo: "<repo-name>", // the name of the repository
});

createIssueCommentWithReaction

Creates a new comment on an existing issue with a reaction. Official GitHub docs.

example.ts
await io.github.createIssueCommentWithReaction("create comment with reaction", {
  owner: "<owner-name>", // the name of the owner of the repository
  repo: "<repo-name>", // the name of the repository
  issueNumber: <issue-number>, // the number of the issue
  body: "<comment-text>", // the contents of the comment
  content: "<reaction-type>", // the type of reaction
});

addIssueCommentReaction

Adds a reaction to an existing issue comment. Official GitHub docs.

example.ts
await io.github.addIssueCommentReaction("add reaction", {
  owner: "<owner-name>", // the name of the owner of the repository
  repo: "<repo-name>", // the name of the repository
  commentId: <comment-id>, // the id of the specific comment
  content: "<reaction-type>", // the type of reaction
});

updateWebhook

Updates an existing webhook. Official GitHub docs.

example.ts
await io.github.updateWebhook("update webhook", {
  owner: "<owner-name>", // the name of the owner of the repository
  repo: "<repo-name>", // the name of the repository
  webhookId: <webhook-id>, // the unique id of the webhook
  config: {
    url: "<webhook-url>", // the url to which payloads will be delivered
    contentType: "json", // the media type used to serialize the payloads
    secret: "<webhook-secret>", // If provided, the secret will be used as the key to generate the HMAC hex digest value for delivery signature headers.
  },
});

createWebhook

Creates a new webhook. Official GitHub docs.

example.ts
await io.github.createWebhook("create webhook", {
  owner: "<owner-name>", // the name of the owner of the repository
  repo: "<repo-name>", // the name of the repository
  config: {
    url: "<webhook-url>", // the url to which payloads will be delivered
    contentType: "json", // the media type used to serialize the payloads
    secret: "<webhook-secret>", // If provided, the secret will be used as the key to generate the HMAC hex digest value for delivery signature headers.
  },
  events: ["<event-type>"], // the events for which the webhook will trigger
});

listWebhooks

Lists the webhooks for a repository. Official GitHub docs.

example.ts
const webhooks = await io.github.listWebhooks({
  owner: "<owner-name>", // the name of the owner of the repository
  repo: "<repo-name>", // the name of the repository
});

updateOrgWebhook

Updates an existing webhook for an organization. Official GitHub docs.

await io.github.updateOrgWebhook("update org webhook", {
  org: "<organization-name>", // the name of the organization
  webhookId: <webhook-id>, // the unique id of the webhook
  config: {
    url: "<webhook-url>", // the url to which payloads will be delivered
    contentType: "json", // the media type used to serialize the payloads
    secret: "<webhook-secret>", // If provided, the secret will be used as the key to generate the HMAC hex digest value for delivery signature headers.
  },
});

createOrgWebhook

Creates a new webhook for an organization. Official GitHub docs.

example.ts
await io.github.createOrgWebhook("create org webhook", {
  org: "<organization-name>", // the name of the organization
  config: {
    url: "<webhook-url>", // the url to which payloads will be delivered
    contentType: "json", // the media type used to serialize the payloads
    secret: "<webhook-secret>", // If provided, the secret will be used as the key to generate the HMAC hex digest value for delivery signature headers.
  },
  events: ["<event-type>"], // the events for which the webhook will trigger
});

listOrgWebhooks

Lists the webhooks for an organization. Official GitHub docs.

example.ts
const orgWebhooks = await io.github.listOrgWebhooks({
  org: "<organization-name>", // the name of the organization
  per-page: <number>, // the number of webhooks to return per page (max 100)
  page: <number>, // Page number of the results to fetch.
});

Example usage

In this example we’ll create a task that adds an assignee and a label to an issue when it’s opened.

client.defineJob({
  id: "github-integration-on-issue-opened",
  name: "GitHub Integration - On Issue Opened",
  version: "1.0.0",
  integrations: { github },
  trigger: github.triggers.repo({
    event: events.onIssueOpened,
    owner: "<your-org-name>",
    repo: "<your-repo-name>",
  }),
  run: async (payload, io, ctx) => {
    await io.github.addIssueAssignees("add assignee", {
      owner: payload.repository.owner.login,
      repo: payload.repository.name,
      issueNumber: payload.issue.number,
      assignees: ["<assignee-name>"],
    });

    await io.github.addIssueLabels("add label", {
      owner: payload.repository.owner.login,
      repo: payload.repository.name,
      issueNumber: payload.issue.number,
      labels: ["<label-name>"],
    });

    return { payload, ctx };
  },
});

Using the underlying GitHub client

You can access the Octokit instance by using the runTask method on the integration:

const github = new Github({
  id: "github",
});

client.defineJob({
  id: "github-example-1",
  name: "GitHub Example 1",
  version: "0.1.0",
  trigger: eventTrigger({
    name: "github.example",
  }),
  integrations: {
    github,
  },
  run: async (payload, io, ctx) => {
    const contributors = await io.github.runTask(
      "get-contributors",
      async (octokit, task) => {
        const contributors = await octokit.rest.repos.listContributors({
          owner: "<owner-name>",
          repo: "<repo-name>",
        });

        return contributors;
      },
      //this is optional, it will appear on the Run page
      { name: "List Contributors" }
    );
  },
});