feat: add new watcher trigger in GitHub (#302)
* feat: add new watcher trigger in GitHub
This commit is contained in:
@@ -365,6 +365,45 @@
|
|||||||
"name": "Test trigger"
|
"name": "Test trigger"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "New watcher",
|
||||||
|
"key": "newWatcher",
|
||||||
|
"interval": "15m",
|
||||||
|
"description": "Triggers when a new watcher is added to a repo",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ import NewOrganization from './triggers/new-organization';
|
|||||||
import NewBranch from './triggers/new-branch';
|
import NewBranch from './triggers/new-branch';
|
||||||
import NewNotification from './triggers/new-notification';
|
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';
|
||||||
|
|
||||||
export default class Triggers {
|
export default class Triggers {
|
||||||
newRepository: NewRepository;
|
newRepository: NewRepository;
|
||||||
@@ -11,6 +12,7 @@ export default class Triggers {
|
|||||||
newBranch: NewBranch;
|
newBranch: NewBranch;
|
||||||
newNotification: NewNotification;
|
newNotification: NewNotification;
|
||||||
newPullRequest: NewPullRequest;
|
newPullRequest: NewPullRequest;
|
||||||
|
newWatcher: NewWatcher;
|
||||||
|
|
||||||
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
||||||
this.newRepository = new NewRepository(connectionData);
|
this.newRepository = new NewRepository(connectionData);
|
||||||
@@ -18,5 +20,6 @@ export default class Triggers {
|
|||||||
this.newBranch = new NewBranch(connectionData, parameters);
|
this.newBranch = new NewBranch(connectionData, parameters);
|
||||||
this.newNotification = new NewNotification(connectionData, parameters);
|
this.newNotification = new NewNotification(connectionData, parameters);
|
||||||
this.newPullRequest = new NewPullRequest(connectionData, parameters);
|
this.newPullRequest = new NewPullRequest(connectionData, parameters);
|
||||||
|
this.newWatcher = new NewWatcher(connectionData, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,13 +32,15 @@ export default class NewPullRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(startTime: Date) {
|
async run(startTime: Date) {
|
||||||
const iterator = await this.client.paginate.iterator(this.client.rest.pulls.list, this.options);
|
const iterator = await this.client.paginate.iterator(
|
||||||
|
this.client.rest.pulls.list,
|
||||||
|
this.options
|
||||||
|
);
|
||||||
const newPullRequests = [];
|
const newPullRequests = [];
|
||||||
|
|
||||||
const startTimeDateObject = DateTime.fromJSDate(startTime);
|
const startTimeDateObject = DateTime.fromJSDate(startTime);
|
||||||
|
|
||||||
pullRequestIterator:
|
pullRequestIterator: for await (const { data: pullRequests } of iterator) {
|
||||||
for await (const { data: pullRequests } of iterator) {
|
|
||||||
for (const pullRequest of pullRequests) {
|
for (const pullRequest of pullRequests) {
|
||||||
const createdAtDateObject = DateTime.fromISO(pullRequest.created_at);
|
const createdAtDateObject = DateTime.fromISO(pullRequest.created_at);
|
||||||
|
|
||||||
|
48
packages/backend/src/apps/github/triggers/new-watcher.ts
Normal file
48
packages/backend/src/apps/github/triggers/new-watcher.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { Octokit } from 'octokit';
|
||||||
|
import { IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
|
export default class NewWatcher {
|
||||||
|
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 entries
|
||||||
|
return await this.client.paginate(
|
||||||
|
this.client.rest.activity.listWatchersForRepo,
|
||||||
|
this.options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async testRun() {
|
||||||
|
return await this.run();
|
||||||
|
const options = {
|
||||||
|
...this.options,
|
||||||
|
per_page: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (await this.client.rest.activity.listWatchersForRepo(options)).data;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user