feat: add new branch trigger in GitHub

This commit is contained in:
Ali BARIN
2022-04-20 21:56:01 +02:00
committed by Ömer Faruk Aydın
parent 6bee6bafa8
commit 3551d12e7d
7 changed files with 124 additions and 15 deletions

View File

@@ -0,0 +1,45 @@
import { Octokit } from 'octokit';
import { IJSONObject } from '@automatisch/types';
export default class NewBranch {
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.repos.listBranches, this.options);
}
async testRun() {
const options = {
...this.options,
per_page: 1,
};
const { data: branches } = await this.client.rest.repos.listBranches(options);
return branches;
}
}

View File

@@ -5,30 +5,17 @@ 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
) {
if (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);
@@ -36,7 +23,6 @@ export default class NewRepository {
async testRun() {
const options = {
...this.baseOptions,
per_page: 1,
};
const { data: repos } = await this.client.rest.repos.listForAuthenticatedUser(options);