102 lines
2.1 KiB
Plaintext
102 lines
2.1 KiB
Plaintext
---
|
|
title: Introduction
|
|
---
|
|
|
|
<Snippet file="integration-getting-started.mdx" />
|
|
|
|
## Installation
|
|
|
|
<CodeGroup>
|
|
|
|
```bash npm
|
|
npm install @trigger.dev/github@latest
|
|
```
|
|
|
|
```bash pnpm
|
|
pnpm install @trigger.dev/github@latest
|
|
```
|
|
|
|
```bash yarn
|
|
yarn add @trigger.dev/github@latest
|
|
```
|
|
|
|
</CodeGroup>
|
|
|
|
## Authentication
|
|
|
|
GitHub supports Personal Access Tokens and OAuth.
|
|
|
|
```ts
|
|
import { Github } from "@trigger.dev/github";
|
|
|
|
//create GitHub client using a token
|
|
const github = new Github({
|
|
id: "github",
|
|
token: process.env.GITHUB_TOKEN!,
|
|
});
|
|
|
|
//create GitHub client using OAuth
|
|
const github2 = new Github({
|
|
id: "github2",
|
|
});
|
|
```
|
|
|
|
## Triggers and Tasks
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Triggers" icon="stars" href="/integrations/apis/github-triggers">
|
|
Trigger Jobs when events happen in GitHub, such as a new commit or a new issue.
|
|
</Card>
|
|
<Card title="Tasks" icon="sparkles" href="/integrations/apis/github-tasks">
|
|
Perform tasks such as creating a new issue or a new comment.
|
|
</Card>
|
|
</CardGroup>
|
|
|
|
## Using the underlying client
|
|
|
|
You can use the underlying client to do anything Octokit supports. In this example we create a project card when a new issue is opened..
|
|
|
|
<Info>
|
|
View [the official GitHub docs](https://docs.github.com/en/rest) for everything that is
|
|
supported{" "}
|
|
</Info>
|
|
|
|
```ts
|
|
import { Github, events } from "@trigger.dev/github";
|
|
|
|
const github = new Github({
|
|
id: "github",
|
|
token: process.env.GITHUB_TOKEN!,
|
|
});
|
|
|
|
client.defineJob({
|
|
id: "alert-on-new-github-issues",
|
|
name: "Alert on new GitHub issues",
|
|
version: "0.1.1",
|
|
trigger: github.triggers.repo({
|
|
event: events.onIssueOpened,
|
|
owner: "triggerdotdev",
|
|
repo: "trigger.dev",
|
|
}),
|
|
integrations: {
|
|
github,
|
|
},
|
|
run: async (payload, io, ctx) => {
|
|
//io.github.runTask allows you to use the underlying SDK client
|
|
const { data } = await io.github.runTask(
|
|
"create-card",
|
|
async (client) => {
|
|
return client.rest.projects.createCard({
|
|
column_id: 123,
|
|
note: "test",
|
|
});
|
|
},
|
|
{ name: "Create card" }
|
|
);
|
|
|
|
//log the url of the created card
|
|
await io.logger.info(data.url);
|
|
},
|
|
});
|
|
```
|