feat: add new milestone trigger in GitHub
This commit is contained in:
@@ -404,6 +404,45 @@
|
||||
"name": "Test trigger"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "New milestone",
|
||||
"key": "newMilestone",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new milestone 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import NewBranch from './triggers/new-branch';
|
||||
import NewNotification from './triggers/new-notification';
|
||||
import NewPullRequest from './triggers/new-pull-request';
|
||||
import NewWatcher from './triggers/new-watcher';
|
||||
import NewMilestone from './triggers/new-milestone';
|
||||
|
||||
export default class Triggers {
|
||||
newRepository: NewRepository;
|
||||
@@ -13,6 +14,7 @@ export default class Triggers {
|
||||
newNotification: NewNotification;
|
||||
newPullRequest: NewPullRequest;
|
||||
newWatcher: NewWatcher;
|
||||
newMilestone: NewMilestone;
|
||||
|
||||
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
||||
this.newRepository = new NewRepository(connectionData);
|
||||
@@ -21,5 +23,6 @@ export default class Triggers {
|
||||
this.newNotification = new NewNotification(connectionData, parameters);
|
||||
this.newPullRequest = new NewPullRequest(connectionData, parameters);
|
||||
this.newWatcher = new NewWatcher(connectionData, parameters);
|
||||
this.newMilestone = new NewMilestone(connectionData, parameters);
|
||||
}
|
||||
}
|
||||
|
63
packages/backend/src/apps/github/triggers/new-milestone.ts
Normal file
63
packages/backend/src/apps/github/triggers/new-milestone.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { Octokit } from 'octokit';
|
||||
import { DateTime } from 'luxon';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default class NewMilestone {
|
||||
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,
|
||||
state: 'open' as const,
|
||||
};
|
||||
}
|
||||
|
||||
async run(startTime: Date) {
|
||||
const iterator = await this.client.paginate.iterator(this.client.rest.issues.listMilestones, this.options);
|
||||
const newMilestones = [];
|
||||
|
||||
const startTimeDateObject = DateTime.fromJSDate(startTime);
|
||||
|
||||
milestoneIterator:
|
||||
for await (const { data: milestones } of iterator) {
|
||||
for (const milestone of milestones) {
|
||||
const createdAtDateObject = DateTime.fromISO(milestone.created_at);
|
||||
|
||||
if (createdAtDateObject < startTimeDateObject) {
|
||||
break milestoneIterator;
|
||||
}
|
||||
|
||||
newMilestones.push(milestone);
|
||||
}
|
||||
}
|
||||
|
||||
return newMilestones;
|
||||
}
|
||||
|
||||
async testRun() {
|
||||
const options = {
|
||||
...this.options,
|
||||
per_page: 1,
|
||||
};
|
||||
|
||||
return (await this.client.rest.issues.listMilestones(options)).data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user