Back to APIs

Subscribe to webhooks and automate tasks in your code repositories.

Using our official GitHub integration

Easily subscribe to GitHub webhooks to trigger your jobs.

Create any tasks possible with the GitHub API.

Use io.runTask() and the official SDK or fetch.

GitHub integration docs

Example code using GitHub

Below are some working code examples of how you can use GitHub with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import { TriggerClient } from "@trigger.dev/sdk";
2
import { Github, events } from "@trigger.dev/github";
3
import { Slack } from "@trigger.dev/slack";
4
5
const github = new Github({ id: "github" });
6
const slack = new Slack({ id: "slack" });
7
8
// Sends a Slack message to a channel if a GitHub issue is left open for 24 hours
9
client.defineJob({
10
id: "github-new-issue-reminder",
11
name: "GitHub: new issue reminder",
12
version: "1.0.0",
13
trigger: github.triggers.repo({
14
event: events.onIssueOpened,
15
owner: "<your-org-name>",
16
repo: "<your-repo-name>",
17
}),
18
integrations: {
19
github,
20
slack,
21
},
22
run: async (payload, io, ctx) => {
23
const delayDuration =
24
ctx.environment.type === "DEVELOPMENT" ? 3 : 60 * 60 * 24;
25
await io.wait("wait 24 hours", delayDuration);
26
27
const issue = await io.github.getIssue("get issue", {
28
owner: payload.repository.owner.login,
29
repo: payload.repository.name,
30
issueNumber: payload.issue.number,
31
});
32
33
if (issue.updated_at === payload.issue.updated_at) {
34
const assigneeResult = await io.github.addIssueAssignees("add assignee", {
35
owner: payload.repository.owner.login,
36
repo: payload.repository.name,
37
issueNumber: payload.issue.number,
38
assignees: [payload.sender.login],
39
});
40
41
await io.slack.postMessage("send reminder", {
42
channel: process.env.SLACK_CHANNEL_ID!,
43
text: `Issue ${payload.issue.title} is still open. I've assigned it to ${payload.sender.login}.\n${issue.html_url}`,
44
});
45
}
46
},
47
});

Full-stack GitHub example projects