Merge pull request #306 from automatisch/github-new-collaborator-trigger
feat: add new collaborator trigger in GitHub
This commit is contained in:
@@ -521,6 +521,45 @@
|
|||||||
"name": "Test trigger"
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@ 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';
|
import NewCommitComment from './triggers/new-commit-comment';
|
||||||
import NewLabel from './triggers/new-label';
|
import NewLabel from './triggers/new-label';
|
||||||
|
import NewCollaborator from './triggers/new-collaborator';
|
||||||
|
|
||||||
export default class Triggers {
|
export default class Triggers {
|
||||||
newRepository: NewRepository;
|
newRepository: NewRepository;
|
||||||
@@ -19,6 +20,7 @@ export default class Triggers {
|
|||||||
newMilestone: NewMilestone;
|
newMilestone: NewMilestone;
|
||||||
newCommitComment: NewCommitComment;
|
newCommitComment: NewCommitComment;
|
||||||
newLabel: NewLabel;
|
newLabel: NewLabel;
|
||||||
|
newCollaborator: NewCollaborator;
|
||||||
|
|
||||||
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
||||||
this.newRepository = new NewRepository(connectionData);
|
this.newRepository = new NewRepository(connectionData);
|
||||||
@@ -30,5 +32,6 @@ export default class Triggers {
|
|||||||
this.newMilestone = new NewMilestone(connectionData, parameters);
|
this.newMilestone = new NewMilestone(connectionData, parameters);
|
||||||
this.newCommitComment = new NewCommitComment(connectionData, parameters);
|
this.newCommitComment = new NewCommitComment(connectionData, parameters);
|
||||||
this.newLabel = new NewLabel(connectionData, parameters);
|
this.newLabel = new NewLabel(connectionData, parameters);
|
||||||
|
this.newCollaborator = new NewCollaborator(connectionData, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user