Files
automatisch/packages/backend/src/apps/github/triggers/new-label.ts
2022-05-03 21:12:29 +02:00

45 lines
957 B
TypeScript

import { Octokit } from 'octokit';
import { IJSONObject } from '@automatisch/types';
import { assignOwnerAndRepo } from '../utils';
export default class NewLabel {
client?: Octokit;
repoOwner?: string;
repo?: string;
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
if (connectionData.accessToken) {
this.client = new Octokit({
auth: connectionData.accessToken as string,
});
}
assignOwnerAndRepo(this, parameters?.repo as string);
}
get options() {
return {
owner: this.repoOwner,
repo: this.repo,
};
}
async run() {
// TODO: implement pagination on undated entires
return await this.client.paginate(
this.client.rest.issues.listLabelsForRepo,
this.options
);
}
async testRun() {
const options = {
...this.options,
per_page: 1,
};
return (await this.client.rest.issues.listLabelsForRepo(options)).data;
}
}