Files
triggerdotdev--trigger.dev/integrations/github/src/repos.ts
T
Eric Allam c0dfa8048a feat: BYO Auth (#491)
* feat: BYO Auth

Define client-side auth resolvers to be able to supply custom authentication credentials for integrations before a run is performed

- Added new defineAuthResolver
- Update all integrations to support the new auth resolvers
- Strip internal symbols from .d.ts in integrations and trigger-sdk
- Added BYO Auth docs
- Update Dynamic Schedule to support associated account IDs
- Create external accounts just-in-time
- Added Account ID field to test job when there are external auth integrations
- Show Account ID on run dashboard
- Added new Run error state called “Unresolved auth”

* Added changeset

* Remove @internal from TriggerIntegration public methods

* Add void to the result union

* DynamicTriggers now work with the new BYO auth system, and added a bunch of docs and docs changes

* Add additional key material for registering dynamic trigger task

* Add new define* instance methods to the overview
2023-09-22 08:54:31 -07:00

168 lines
3.6 KiB
TypeScript

import { IntegrationTaskKey } from "@trigger.dev/sdk";
import { Octokit } from "octokit";
import { GitHubReturnType, GitHubRunTask, onError } from "./index";
export class Repos {
constructor(private runTask: GitHubRunTask) {}
get(
key: IntegrationTaskKey,
params: { owner: string; repo: string }
): GitHubReturnType<Octokit["rest"]["repos"]["get"]> {
return this.runTask(
key,
async (client, task) => {
const result = await client.rest.repos.get({
owner: params.owner,
repo: params.repo,
headers: {
"x-trigger-attempt": String(task.attempts),
},
});
return result.data;
},
{
name: "Get Repo",
params,
properties: [
{
label: "Repo",
text: params.repo,
},
],
},
onError
);
}
updateWebhook(
key: IntegrationTaskKey,
params: {
owner: string;
repo: string;
hookId: number;
url: string;
secret: string;
addEvents?: string[];
}
): GitHubReturnType<Octokit["rest"]["repos"]["updateWebhook"]> {
return this.runTask(
key,
async (client, task) => {
const result = await client.rest.repos.updateWebhook({
owner: params.owner,
repo: params.repo,
hook_id: params.hookId,
config: {
content_type: "json",
url: params.url,
secret: params.secret,
},
add_events: params.addEvents,
});
return result.data;
},
{
name: "Update Webhook",
params,
properties: [
{
label: "Owner",
text: params.owner,
},
{
label: "Repo",
text: params.repo,
},
{
label: "Hook ID",
text: String(params.hookId),
},
],
},
onError
);
}
createWebhook(
key: IntegrationTaskKey,
params: {
owner: string;
repo: string;
url: string;
secret: string;
events: string[];
}
): GitHubReturnType<Octokit["rest"]["repos"]["createWebhook"]> {
return this.runTask(
key,
async (client, task) => {
const result = await client.rest.repos.createWebhook({
owner: params.owner,
repo: params.repo,
config: {
content_type: "json",
url: params.url,
secret: params.secret,
},
events: params.events,
});
return result.data;
},
{
name: "Create Webhook",
params,
properties: [
{
label: "Owner",
text: params.owner,
},
{
label: "Repo",
text: params.repo,
},
{
label: "Events",
text: params.events.join(", "),
},
],
},
onError
);
}
listWebhooks(
key: IntegrationTaskKey,
params: {
owner: string;
repo: string;
}
): GitHubReturnType<Octokit["rest"]["repos"]["listWebhooks"]> {
return this.runTask(
key,
async (client, task) => {
const result = await client.rest.repos.listWebhooks({
owner: params.owner,
repo: params.repo,
});
return result.data;
},
{
name: "List Webhooks",
params,
properties: [
{
label: "Owner",
text: params.owner,
},
{
label: "Repo",
text: params.repo,
},
],
},
onError
);
}
}