feat: add new label trigger in GitHub

This commit is contained in:
Ali BARIN
2022-04-22 18:08:41 +02:00
parent c79622aefd
commit 57478dcc17
3 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
import { Octokit } from 'octokit';
import { IJSONObject } from '@automatisch/types';
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,
});
}
if (parameters?.repo) {
const [owner, repo] = (parameters.repo as string).split('/');
this.repoOwner = owner;
this.repo = repo;
}
}
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;
}
}