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

committed by
Ömer Faruk Aydın

parent
bdfdb1f228
commit
c79622aefd
@@ -443,6 +443,45 @@
|
|||||||
"name": "Test trigger"
|
"name": "Test trigger"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "New commit comment",
|
||||||
|
"key": "newCommitComment",
|
||||||
|
"interval": "15m",
|
||||||
|
"description": "Triggers when a new commit comment is created",
|
||||||
|
"substeps": [
|
||||||
|
{
|
||||||
|
"key": "chooseAccount",
|
||||||
|
"name": "Choose account"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "chooseTrigger",
|
||||||
|
"name": "Set up a trigger",
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"label": "Repo",
|
||||||
|
"key": "repo",
|
||||||
|
"type": "dropdown",
|
||||||
|
"required": true,
|
||||||
|
"variables": false,
|
||||||
|
"source": {
|
||||||
|
"type": "query",
|
||||||
|
"name": "getData",
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"name": "key",
|
||||||
|
"value": "listRepos"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "testStep",
|
||||||
|
"name": "Test trigger"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@ import NewNotification from './triggers/new-notification';
|
|||||||
import NewPullRequest from './triggers/new-pull-request';
|
import NewPullRequest from './triggers/new-pull-request';
|
||||||
import NewWatcher from './triggers/new-watcher';
|
import NewWatcher from './triggers/new-watcher';
|
||||||
import NewMilestone from './triggers/new-milestone';
|
import NewMilestone from './triggers/new-milestone';
|
||||||
|
import NewCommitComment from './triggers/new-commit-comment';
|
||||||
|
|
||||||
export default class Triggers {
|
export default class Triggers {
|
||||||
newRepository: NewRepository;
|
newRepository: NewRepository;
|
||||||
@@ -15,6 +16,7 @@ export default class Triggers {
|
|||||||
newPullRequest: NewPullRequest;
|
newPullRequest: NewPullRequest;
|
||||||
newWatcher: NewWatcher;
|
newWatcher: NewWatcher;
|
||||||
newMilestone: NewMilestone;
|
newMilestone: NewMilestone;
|
||||||
|
newCommitComment: NewCommitComment;
|
||||||
|
|
||||||
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
||||||
this.newRepository = new NewRepository(connectionData);
|
this.newRepository = new NewRepository(connectionData);
|
||||||
@@ -24,5 +26,6 @@ export default class Triggers {
|
|||||||
this.newPullRequest = new NewPullRequest(connectionData, parameters);
|
this.newPullRequest = new NewPullRequest(connectionData, parameters);
|
||||||
this.newWatcher = new NewWatcher(connectionData, parameters);
|
this.newWatcher = new NewWatcher(connectionData, parameters);
|
||||||
this.newMilestone = new NewMilestone(connectionData, parameters);
|
this.newMilestone = new NewMilestone(connectionData, parameters);
|
||||||
|
this.newCommitComment = new NewCommitComment(connectionData, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,62 @@
|
|||||||
|
import { Octokit } from 'octokit';
|
||||||
|
import { DateTime } from 'luxon';
|
||||||
|
import { IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
|
export default class NewCommitComment {
|
||||||
|
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(startTime: Date) {
|
||||||
|
const iterator = await this.client.paginate.iterator(this.client.rest.repos.listCommitCommentsForRepo, this.options);
|
||||||
|
const newCommitComments = [];
|
||||||
|
|
||||||
|
const startTimeDateObject = DateTime.fromJSDate(startTime);
|
||||||
|
|
||||||
|
commitCommentIterator:
|
||||||
|
for await (const { data: commitComments } of iterator) {
|
||||||
|
for (const commitComment of commitComments) {
|
||||||
|
const createdAtDateObject = DateTime.fromISO(commitComment.created_at);
|
||||||
|
|
||||||
|
if (createdAtDateObject < startTimeDateObject) {
|
||||||
|
break commitCommentIterator;
|
||||||
|
}
|
||||||
|
|
||||||
|
newCommitComments.push(commitComment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newCommitComments;
|
||||||
|
}
|
||||||
|
|
||||||
|
async testRun() {
|
||||||
|
const options = {
|
||||||
|
...this.options,
|
||||||
|
per_page: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (await this.client.rest.repos.listCommitCommentsForRepo(options)).data;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user