feat: add new label trigger in GitHub
This commit is contained in:
@@ -482,6 +482,45 @@
|
||||
"name": "Test trigger"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "New label",
|
||||
"key": "newLabel",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new label 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import NewPullRequest from './triggers/new-pull-request';
|
||||
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';
|
||||
|
||||
export default class Triggers {
|
||||
newRepository: NewRepository;
|
||||
@@ -17,6 +18,7 @@ export default class Triggers {
|
||||
newWatcher: NewWatcher;
|
||||
newMilestone: NewMilestone;
|
||||
newCommitComment: NewCommitComment;
|
||||
newLabel: NewLabel;
|
||||
|
||||
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
||||
this.newRepository = new NewRepository(connectionData);
|
||||
@@ -27,5 +29,6 @@ export default class Triggers {
|
||||
this.newWatcher = new NewWatcher(connectionData, parameters);
|
||||
this.newMilestone = new NewMilestone(connectionData, parameters);
|
||||
this.newCommitComment = new NewCommitComment(connectionData, parameters);
|
||||
this.newLabel = new NewLabel(connectionData, parameters);
|
||||
}
|
||||
}
|
||||
|
47
packages/backend/src/apps/github/triggers/new-label.ts
Normal file
47
packages/backend/src/apps/github/triggers/new-label.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Octokit } from 'octokit';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default class NewLabel {
|
||||
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 entires
|
||||
return await this.client.paginate(
|
||||
this.client.rest.issues.listLabelsForRepo,
|
||||
this.options
|
||||
);
|
||||
}
|
||||
|
||||
async testRun() {
|
||||
const options = {
|
||||
...this.options,
|
||||
per_page: 1,
|
||||
};
|
||||
|
||||
return (await this.client.rest.issues.listLabelsForRepo(options)).data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user