Files
triggerdotdev--trigger.dev/integrations/github/src/orgs.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

121 lines
2.6 KiB
TypeScript

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