feat: add new commit trigger in GitHub

This commit is contained in:
Ali BARIN
2022-04-24 01:23:59 +02:00
parent 2e2d371875
commit e651fd141b
32 changed files with 439 additions and 98 deletions

View File

@@ -1,6 +1,8 @@
import { Octokit } from 'octokit';
import { IJSONObject } from '@automatisch/types';
import { assignOwnerAndRepo } from '../utils';
export default class NewBranch {
client?: Octokit;
repoOwner?: string;
@@ -13,12 +15,7 @@ export default class NewBranch {
});
}
if (parameters?.repo) {
const [owner, repo] = (parameters.repo as string).split('/');
this.repoOwner = owner;
this.repo = repo;
}
assignOwnerAndRepo(this, parameters?.repo as string);
}
get options() {

View File

@@ -1,6 +1,8 @@
import { Octokit } from 'octokit';
import { IJSONObject } from '@automatisch/types';
import { assignOwnerAndRepo } from '../utils';
export default class NewCollaborator {
client?: Octokit;
repoOwner?: string;
@@ -13,12 +15,7 @@ export default class NewCollaborator {
});
}
if (parameters?.repo) {
const [owner, repo] = (parameters.repo as string).split('/');
this.repoOwner = owner;
this.repo = repo;
}
assignOwnerAndRepo(this, parameters?.repo as string);
}
get options() {

View File

@@ -2,6 +2,8 @@ import { Octokit } from 'octokit';
import { DateTime } from 'luxon';
import { IJSONObject } from '@automatisch/types';
import { assignOwnerAndRepo } from '../utils';
export default class NewCommitComment {
client?: Octokit;
repoOwner?: string;
@@ -14,12 +16,7 @@ export default class NewCommitComment {
});
}
if (parameters?.repo) {
const [owner, repo] = (parameters.repo as string).split('/');
this.repoOwner = owner;
this.repo = repo;
}
assignOwnerAndRepo(this, parameters?.repo as string);
}
get options() {

View File

@@ -0,0 +1,59 @@
import { Octokit } from 'octokit';
import { DateTime } from 'luxon';
import { IJSONObject } from '@automatisch/types';
import { assignOwnerAndRepo } from '../utils';
export default class NewCommit {
client?: Octokit;
repoOwner?: string;
repo?: string;
head?: string;
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
if (connectionData.accessToken) {
this.client = new Octokit({
auth: connectionData.accessToken as string,
});
}
if (parameters?.head) {
this.head = parameters.head as string;
}
assignOwnerAndRepo(this, parameters?.repo as string);
}
get options() {
const options = {
owner: this.repoOwner,
repo: this.repo,
};
if (this.head) {
return {
...options,
sha: this.head,
};
}
return options;
}
async run(startTime: Date) {
const options = {
...this.options,
since: DateTime.fromJSDate(startTime).toISO(),
};
return await this.client.paginate(this.client.rest.repos.listCommits, options);
}
async testRun() {
const options = {
...this.options,
per_page: 1,
};
return (await this.client.rest.repos.listCommits(options)).data;
}
}

View File

@@ -1,6 +1,8 @@
import { Octokit } from 'octokit';
import { IJSONObject } from '@automatisch/types';
import { assignOwnerAndRepo } from '../utils';
export default class NewLabel {
client?: Octokit;
repoOwner?: string;
@@ -13,12 +15,7 @@ export default class NewLabel {
});
}
if (parameters?.repo) {
const [owner, repo] = (parameters.repo as string).split('/');
this.repoOwner = owner;
this.repo = repo;
}
assignOwnerAndRepo(this, parameters?.repo as string);
}
get options() {

View File

@@ -2,6 +2,8 @@ import { Octokit } from 'octokit';
import { DateTime } from 'luxon';
import { IJSONObject } from '@automatisch/types';
import { assignOwnerAndRepo } from '../utils';
export default class NewMilestone {
client?: Octokit;
repoOwner?: string;
@@ -14,12 +16,7 @@ export default class NewMilestone {
});
}
if (parameters?.repo) {
const [owner, repo] = (parameters.repo as string).split('/');
this.repoOwner = owner;
this.repo = repo;
}
assignOwnerAndRepo(this, parameters?.repo as string);
}
get options() {

View File

@@ -2,6 +2,8 @@ import { Octokit } from 'octokit';
import { DateTime } from 'luxon';
import { IJSONObject } from '@automatisch/types';
import { assignOwnerAndRepo } from '../utils';
export default class NewNotification {
client?: Octokit;
connectionData?: IJSONObject;
@@ -19,12 +21,7 @@ export default class NewNotification {
});
}
if (parameters?.repo) {
const [owner, repo] = (parameters.repo as string).split('/');
this.repoOwner = owner;
this.repo = repo;
}
assignOwnerAndRepo(this, parameters?.repo as string);
}
get hasRepo() {

View File

@@ -2,6 +2,8 @@ import { Octokit } from 'octokit';
import { DateTime } from 'luxon';
import { IJSONObject } from '@automatisch/types';
import { assignOwnerAndRepo } from '../utils';
export default class NewPullRequest {
client?: Octokit;
repoOwner?: string;
@@ -14,12 +16,7 @@ export default class NewPullRequest {
});
}
if (parameters?.repo) {
const [owner, repo] = (parameters.repo as string).split('/');
this.repoOwner = owner;
this.repo = repo;
}
assignOwnerAndRepo(this, parameters?.repo as string);
}
get options() {

View File

@@ -2,6 +2,8 @@ import { Octokit } from 'octokit';
import { DateTime } from 'luxon';
import { IJSONObject } from '@automatisch/types';
import { assignOwnerAndRepo } from '../utils';
export default class NewRelease {
client?: Octokit;
repoOwner?: string;
@@ -14,12 +16,7 @@ export default class NewRelease {
});
}
if (parameters?.repo) {
const [owner, repo] = (parameters.repo as string).split('/');
this.repoOwner = 'facebook' || owner;
this.repo = 'react' || repo;
}
assignOwnerAndRepo(this, parameters?.repo as string);
}
get options() {

View File

@@ -1,6 +1,8 @@
import { Octokit } from 'octokit';
import { IJSONObject } from '@automatisch/types';
import { assignOwnerAndRepo } from '../utils';
export default class NewWatcher {
client?: Octokit;
repoOwner?: string;
@@ -13,12 +15,7 @@ export default class NewWatcher {
});
}
if (parameters?.repo) {
const [owner, repo] = (parameters.repo as string).split('/');
this.repoOwner = owner;
this.repo = repo;
}
assignOwnerAndRepo(this, parameters?.repo as string);
}
get options() {