Back to jobs

Adds a custom label to a GitHub issue

Trigger: eventTrigger

When a new GitHub issue is opened add a “Bug” label to it.

Integrations:

/src/githubNewIssueOpened

Dev Ops

1
import { TriggerClient } from "@trigger.dev/sdk";
2
import { Github, events } from "@trigger.dev/github";
3
4
const client = new TriggerClient({ id: "jobs-showcase" });
5
6
const github = new Github({ id: "github" });
7
8
// This Job will run when a new issue is opened on a repo you have admin rights to
9
// Once created, it will add a 'Bug' label to the issue
10
client.defineJob({
11
id: "github-new-issue-opened",
12
name: "GitHub: new issue opened",
13
version: "1.0.0",
14
integrations: { github: github },
15
trigger: github.triggers.repo({
16
event: events.onIssueOpened,
17
owner: "<your-org-name>",
18
repo: "<your-repo-name>",
19
}),
20
run: async (payload, io, ctx) => {
21
await io.github.addIssueLabels("add label", {
22
owner: payload.repository.owner.login,
23
repo: payload.repository.name,
24
issueNumber: payload.issue.number,
25
labels: ["bug"],
26
});
27
return { payload, ctx };
28
},
29
});
30
31
// These lines can be removed if you don't want to use express
32
import { createExpressServer } from "@trigger.dev/express";
33
createExpressServer(client);