From 525472d3e0bb0518e382dbc8f68d2309de109e48 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Thu, 20 Oct 2022 23:12:44 +0200 Subject: [PATCH] feat(github): add create issue action --- .../apps/github/actions/create-issue/index.ts | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 packages/backend/src/apps/github/actions/create-issue/index.ts diff --git a/packages/backend/src/apps/github/actions/create-issue/index.ts b/packages/backend/src/apps/github/actions/create-issue/index.ts new file mode 100644 index 00000000..6a53da50 --- /dev/null +++ b/packages/backend/src/apps/github/actions/create-issue/index.ts @@ -0,0 +1,80 @@ +import { IActionOutput } from '@automatisch/types'; +import defineAction from '../../../../helpers/define-action'; +import getRepoOwnerAndRepo from '../../common/get-repo-owner-and-repo'; + +export default defineAction({ + name: 'Create issue', + key: 'createIssue', + description: 'Create a new issue.', + substeps: [ + { + key: 'chooseConnection', + name: 'Choose connection', + }, + { + key: 'chooseAction', + name: 'Set up action', + arguments: [ + { + label: 'Repo', + key: 'repo', + type: 'dropdown', + required: false, + variables: false, + source: { + type: 'query', + name: 'getData', + arguments: [ + { + name: 'key', + value: 'listRepos' + } + ] + } + }, + { + label: 'Title', + key: 'title', + type: 'string', + required: true, + variables: true + }, + { + label: 'Body', + key: 'body', + type: 'string', + required: true, + variables: true + } + ], + }, + { + key: 'testStep', + name: 'Test action', + }, + ], + + async run($) { + const repoParameter = $.step.parameters.repo as string; + const title = $.step.parameters.title as string; + const body = $.step.parameters.body as string; + + if (!repoParameter) throw new Error('A repo must be set!') + if (!title) throw new Error('A title must be set!'); + + const { repoOwner, repo } = getRepoOwnerAndRepo(repoParameter); + const response = await $.http.post(`/repos/${repoOwner}/${repo}/issues`, { + title, + body, + }); + + const issue: IActionOutput = { + data: { + raw: response.data, + }, + error: response?.integrationError, + }; + + return issue; + }, +});