> ## Documentation Index
> Fetch the complete documentation index at: https://trigger-v3-fix-additional-files.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# GitHub Tasks

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](https://docs.github.com/en/free-pro-team@latest/rest/issues/issues?apiVersion=2022-11-28#create-an-issue).

```ts 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](https://docs.github.com/en/free-pro-team@latest/rest/issues/assignees?apiVersion=2022-11-28#add-assignees-to-an-issue).

```ts 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](https://docs.github.com/en/free-pro-team@latest/rest/issues/labels?apiVersion=2022-11-28#add-labels-to-an-issue).

```ts 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](https://docs.github.com/en/free-pro-team@latest/rest/issues/comments?apiVersion=2022-11-28#create-an-issue-comment).

```ts 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](https://docs.github.com/en/free-pro-team@latest/rest/repos/repos?apiVersion=2022-11-28#get-a-repository).

```ts 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](https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#create-an-issue-comment).

```ts 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](https://docs.github.com/en/free-pro-team@latest/rest/reactions/reactions?apiVersion=2022-11-28#create-reaction-for-an-issue-comment).

```ts 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](https://docs.github.com/en/rest/webhooks/repos?apiVersion=2022-11-28#update-a-repository-webhook).

```ts 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](https://docs.github.com/en/rest/webhooks/repos?apiVersion=2022-11-28#create-a-repository-webhook).

```ts 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](https://docs.github.com/en/rest/webhooks/repos?apiVersion=2022-11-28#list-repository-webhooks).

```ts 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](https://docs.github.com/en/rest/orgs/webhooks?apiVersion=2022-11-28#update-an-organization-webhook).

```ts
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](https://docs.github.com/en/rest/orgs/webhooks?apiVersion=2022-11-28#create-an-organization-webhook).

```ts 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](https://docs.github.com/en/rest/orgs/webhooks?apiVersion=2022-11-28#list-organization-webhooks).

```ts 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.

```ts
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](https://github.com/octokit/octokit.js#octokit-api-client) by using the `runTask` method on the integration:

```ts
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" }
    );
  },
});
```
