feat: add new repository trigger in GitHub
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
4f7bef83ea
commit
96ede071cf
46
packages/backend/src/apps/github/triggers/new-repository.ts
Normal file
46
packages/backend/src/apps/github/triggers/new-repository.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Octokit } from 'octokit';
|
||||
import { DateTime } from 'luxon';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default class NewRepository {
|
||||
client?: Octokit;
|
||||
connectionData?: IJSONObject;
|
||||
baseOptions = {
|
||||
visibility: 'all' as const,
|
||||
affiliation: 'owner,organization_member,collaborator',
|
||||
sort: 'created' as const,
|
||||
per_page: 100,
|
||||
};
|
||||
|
||||
constructor(connectionData: IJSONObject) {
|
||||
if (
|
||||
connectionData.consumerKey &&
|
||||
connectionData.consumerSecret &&
|
||||
connectionData.accessToken
|
||||
) {
|
||||
this.client = new Octokit({
|
||||
auth: connectionData.accessToken as string,
|
||||
});
|
||||
|
||||
this.connectionData = connectionData;
|
||||
}
|
||||
}
|
||||
|
||||
async run(startTime: Date) {
|
||||
const options = {
|
||||
...this.baseOptions,
|
||||
since: DateTime.fromJSDate(startTime).toLocaleString(DateTime.TIME_24_SIMPLE),
|
||||
};
|
||||
return await this.client.paginate(this.client.rest.repos.listForAuthenticatedUser, options);
|
||||
}
|
||||
|
||||
async testRun() {
|
||||
const options = {
|
||||
...this.baseOptions,
|
||||
per_page: 1,
|
||||
};
|
||||
const { data: repos } = await this.client.rest.repos.listForAuthenticatedUser(options);
|
||||
|
||||
return repos;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user