feat: add new watcher trigger in GitHub (#302)

* feat: add new watcher trigger in GitHub
This commit is contained in:
Ali BARIN
2022-04-23 01:21:51 +02:00
committed by GitHub
parent af348714f8
commit 65e6fbd54b
4 changed files with 95 additions and 3 deletions

View File

@@ -32,13 +32,15 @@ export default class NewPullRequest {
}
async run(startTime: Date) {
const iterator = await this.client.paginate.iterator(this.client.rest.pulls.list, this.options);
const iterator = await this.client.paginate.iterator(
this.client.rest.pulls.list,
this.options
);
const newPullRequests = [];
const startTimeDateObject = DateTime.fromJSDate(startTime);
pullRequestIterator:
for await (const { data: pullRequests } of iterator) {
pullRequestIterator: for await (const { data: pullRequests } of iterator) {
for (const pullRequest of pullRequests) {
const createdAtDateObject = DateTime.fromISO(pullRequest.created_at);

View File

@@ -0,0 +1,48 @@
import { Octokit } from 'octokit';
import { IJSONObject } from '@automatisch/types';
export default class NewWatcher {
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 entries
return await this.client.paginate(
this.client.rest.activity.listWatchersForRepo,
this.options
);
}
async testRun() {
return await this.run();
const options = {
...this.options,
per_page: 1,
};
return (await this.client.rest.activity.listWatchersForRepo(options)).data;
}
}