--- title: GitHub Tasks sidebarTitle: 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: "", // the name of the owner of the repository repo: "", // the name of the repository title: "", // the title of the issue body: "", // 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: "", // the name of the owner of the repository repo: "", // the name of the repository issueNumber: , // the number of the issue assignees: [""], // 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: "", // the name of the owner of the repository repo: "", // the name of the repository issueNumber: , // the number of the issue labels: [""], // 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: "", // the name of the owner of the repository repo: "", // the name of the repository issueNumber: , // the number of the issue body: "", // 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: "", // the name of the owner of the repository repo: "", // 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: "", // the name of the owner of the repository repo: "", // the name of the repository issueNumber: , // the number of the issue body: "", // the contents of the comment content: "", // 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: "", // the name of the owner of the repository repo: "", // the name of the repository commentId: , // the id of the specific comment content: "", // 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: "", // the name of the owner of the repository repo: "", // the name of the repository webhookId: , // the unique id of the webhook config: { url: "", // the url to which payloads will be delivered contentType: "json", // the media type used to serialize the payloads 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: "", // the name of the owner of the repository repo: "", // the name of the repository config: { url: "", // the url to which payloads will be delivered contentType: "json", // the media type used to serialize the payloads secret: "", // If provided, the secret will be used as the key to generate the HMAC hex digest value for delivery signature headers. }, events: [""], // 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: "", // the name of the owner of the repository repo: "", // 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: "", // the name of the organization webhookId: , // the unique id of the webhook config: { url: "", // the url to which payloads will be delivered contentType: "json", // the media type used to serialize the payloads 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: "", // the name of the organization config: { url: "", // the url to which payloads will be delivered contentType: "json", // the media type used to serialize the payloads secret: "", // If provided, the secret will be used as the key to generate the HMAC hex digest value for delivery signature headers. }, events: [""], // 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: "", // the name of the organization per-page: , // the number of webhooks to return per page (max 100) page: , // 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: "", repo: "", }), 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: [""], }); await io.github.addIssueLabels("add label", { owner: payload.repository.owner.login, repo: payload.repository.name, issueNumber: payload.issue.number, labels: [""], }); 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: "", repo: "", }); return contributors; }, //this is optional, it will appear on the Run page { name: "List Contributors" } ); }, }); ```