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

149 lines
3.9 KiB
TypeScript

import { truncate } from "@trigger.dev/integration-kit";
import { IntegrationTaskKey, Prettify, retry } from "@trigger.dev/sdk";
import { GitHubReturnType, GitHubRunTask, onError } from "./index";
import { Octokit } from "octokit";
import { issueProperties, repoProperties } from "./propertyHelpers";
type AddIssueLabels = GitHubReturnType<Octokit["rest"]["issues"]["addLabels"]>;
export class Issues {
constructor(private runTask: GitHubRunTask) {}
create(
key: IntegrationTaskKey,
params: { title: string; owner: string; repo: string }
): GitHubReturnType<Octokit["rest"]["issues"]["create"]> {
return this.runTask(
key,
async (client, task) => {
const result = await client.rest.issues.create({
owner: params.owner,
repo: params.repo,
title: params.title,
});
return result.data;
},
{
name: "Create Issue",
params,
properties: [
...repoProperties(params),
{
label: "Title",
text: params.title,
},
],
},
onError
);
}
addAssignees(
key: IntegrationTaskKey,
params: { owner: string; repo: string; issueNumber: number; assignees: string[] }
): GitHubReturnType<Octokit["rest"]["issues"]["addAssignees"]> {
return this.runTask(
key,
async (client, task) => {
const result = await client.rest.issues.addAssignees({
owner: params.owner,
repo: params.repo,
issue_number: params.issueNumber,
assignees: params.assignees,
});
return result.data;
},
{
name: "Add Issue Assignees",
params,
properties: [
...repoProperties(params),
...issueProperties(params),
{
label: "assignees",
text: params.assignees.join(", "),
},
],
},
onError
);
}
addLabels(
key: IntegrationTaskKey,
params: { owner: string; repo: string; issueNumber: number; labels: string[] }
): AddIssueLabels {
return this.runTask(
key,
async (client, task) => {
const result = await client.rest.issues.addLabels({
owner: params.owner,
repo: params.repo,
issue_number: params.issueNumber,
labels: params.labels,
});
return result.data;
},
{
name: "Add Issue Labels",
params,
properties: [
...repoProperties(params),
...issueProperties(params),
{
label: "Labels",
text: params.labels.join(", "),
},
],
},
onError
);
}
createComment(
key: IntegrationTaskKey,
params: { body: string; owner: string; repo: string; issueNumber: number }
): GitHubReturnType<Octokit["rest"]["issues"]["createComment"]> {
return this.runTask(
key,
async (client, task) => {
const result = await client.rest.issues.createComment({
owner: params.owner,
repo: params.repo,
body: params.body,
issue_number: params.issueNumber,
});
return result.data;
},
{
name: "Create Issue Comment",
params,
properties: [...repoProperties(params), ...issueProperties(params)],
},
onError
);
}
get(
key: IntegrationTaskKey,
params: { owner: string; repo: string; issueNumber: number }
): GitHubReturnType<Octokit["rest"]["issues"]["get"]> {
return this.runTask(
key,
async (client, task) => {
const result = await client.rest.issues.get({
owner: params.owner,
repo: params.repo,
issue_number: params.issueNumber,
});
return result.data;
},
{
name: "Get Issue",
params,
properties: [...repoProperties(params), ...issueProperties(params)],
},
onError
);
}
}