feat: add new collaborator trigger in GitHub

This commit is contained in:
Ali BARIN
2022-04-22 18:51:00 +02:00
parent 57478dcc17
commit 024bb731d4
3 changed files with 89 additions and 0 deletions

View File

@@ -521,6 +521,45 @@
"name": "Test trigger"
}
]
},
{
"name": "New collaborator",
"key": "newCollaborator",
"interval": "15m",
"description": "Triggers when a new collaborator 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"
}
]
}
]
}

View File

@@ -8,6 +8,7 @@ import NewWatcher from './triggers/new-watcher';
import NewMilestone from './triggers/new-milestone';
import NewCommitComment from './triggers/new-commit-comment';
import NewLabel from './triggers/new-label';
import NewCollaborator from './triggers/new-collaborator';
export default class Triggers {
newRepository: NewRepository;
@@ -19,6 +20,7 @@ export default class Triggers {
newMilestone: NewMilestone;
newCommitComment: NewCommitComment;
newLabel: NewLabel;
newCollaborator: NewCollaborator;
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
this.newRepository = new NewRepository(connectionData);
@@ -30,5 +32,6 @@ export default class Triggers {
this.newMilestone = new NewMilestone(connectionData, parameters);
this.newCommitComment = new NewCommitComment(connectionData, parameters);
this.newLabel = new NewLabel(connectionData, parameters);
this.newCollaborator = new NewCollaborator(connectionData, parameters);
}
}

View File

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