diff --git a/integrations/jira/integration.definition.ts b/integrations/jira/integration.definition.ts index 376227d0..382ffec4 100644 --- a/integrations/jira/integration.definition.ts +++ b/integrations/jira/integration.definition.ts @@ -1,18 +1,12 @@ import { IntegrationDefinition } from '@botpress/sdk' -import { - configuration, - states, - user, - channels, - actions, -} from './src/definitions' +import { configuration, states, user, channels, actions } from './src/definitions' export default new IntegrationDefinition({ - name: "plus/jira", - title: "Jira", - description: "This integration allows you to manipulate Jira issues and users.", - version: '0.2.3', + name: 'plus/jira', + title: 'Jira', + description: 'This integration allows you to manipulate Jira issues and users.', + version: '0.2.4', readme: 'readme.md', icon: 'icon.svg', configuration, diff --git a/integrations/jira/package.json b/integrations/jira/package.json index 23ff8026..9db68920 100644 --- a/integrations/jira/package.json +++ b/integrations/jira/package.json @@ -24,6 +24,7 @@ "zod": "^3.20.6" }, "devDependencies": { + "@botpress/cli": "^0.6.15", "@types/node": "^18.11.17", "ts-node": "^10.9.1", "typescript": "^4.9.4" diff --git a/integrations/jira/src/actions/add-comment-to-issue.ts b/integrations/jira/src/actions/add-comment-to-issue.ts index 41303951..e93bf315 100644 --- a/integrations/jira/src/actions/add-comment-to-issue.ts +++ b/integrations/jira/src/actions/add-comment-to-issue.ts @@ -3,27 +3,22 @@ import type { Implementation } from '../misc/types' import { getClient } from '../utils' -export const addCommentToIssue: Implementation['actions']['addCommentToIssue'] = - async ({ ctx, input, logger }) => { - const validatedInput = addCommentToIssueInputSchema.parse(input) - const jiraClient = getClient(ctx.configuration) - const comment = { - issueIdOrKey: validatedInput.issueKey, - body: validatedInput.body, - } - let response - try { - response = await jiraClient.addCommentToIssue(comment) - logger - .forBot() - .info( - `Successful - Add Comment to Issue - with issueKey: ${validatedInput.issueKey} - id: ${response}` - ) - } catch (error) { - response = '' - logger - .forBot() - .debug(`'Add Comment to Issue' exception ${JSON.stringify(error)}`) - } - return { id: response } +export const addCommentToIssue: Implementation['actions']['addCommentToIssue'] = async ({ ctx, input, logger }) => { + const validatedInput = addCommentToIssueInputSchema.parse(input) + const jiraClient = getClient(ctx.configuration) + const comment = { + issueIdOrKey: validatedInput.issueKey, + body: validatedInput.body, } + let response + try { + response = await jiraClient.addCommentToIssue(comment) + logger + .forBot() + .info(`Successful - Add Comment to Issue - with issueKey: ${validatedInput.issueKey} - id: ${response}`) + } catch (error) { + response = '' + logger.forBot().debug(`'Add Comment to Issue' exception ${JSON.stringify(error)}`) + } + return { id: response } +} diff --git a/integrations/jira/src/actions/find-all-users.ts b/integrations/jira/src/actions/find-all-users.ts index f48d261e..4782968d 100644 --- a/integrations/jira/src/actions/find-all-users.ts +++ b/integrations/jira/src/actions/find-all-users.ts @@ -1,18 +1,11 @@ import { Version3Models } from 'jira.js' -import { - findAllUsersInputSchema, - findAllUsersOutputSchema, -} from '../misc/custom-schemas' +import { findAllUsersInputSchema, findAllUsersOutputSchema } from '../misc/custom-schemas' import type { Implementation } from '../misc/types' import { getClient } from '../utils' -export const findAllUsers: Implementation['actions']['findAllUsers'] = async ({ - ctx, - input, - logger, -}) => { +export const findAllUsers: Implementation['actions']['findAllUsers'] = async ({ ctx, input, logger }) => { const validatedInput = findAllUsersInputSchema.parse(input) const jiraClient = getClient(ctx.configuration) const addParams = { @@ -22,9 +15,7 @@ export const findAllUsers: Implementation['actions']['findAllUsers'] = async ({ let response try { response = await jiraClient.findAllUser(addParams) - logger - .forBot() - .info(`Successful - Find All User - Total Users ${response.length}`) + logger.forBot().info(`Successful - Find All User - Total Users ${response.length}`) } catch (error) { logger.forBot().debug(`'Find All User' exception ${JSON.stringify(error)}`) response = [] as Version3Models.User[] diff --git a/integrations/jira/src/actions/find-user.ts b/integrations/jira/src/actions/find-user.ts index f8092063..26ae579d 100644 --- a/integrations/jira/src/actions/find-user.ts +++ b/integrations/jira/src/actions/find-user.ts @@ -1,16 +1,9 @@ -import { - findUserInputSchema, - findUserOutputSchema, -} from '../misc/custom-schemas' +import { findUserInputSchema, findUserOutputSchema } from '../misc/custom-schemas' import type { Implementation } from '../misc/types' import { getClient } from '../utils' -export const findUser: Implementation['actions']['findUser'] = async ({ - ctx, - input, - logger, -}) => { +export const findUser: Implementation['actions']['findUser'] = async ({ ctx, input, logger }) => { const validatedInput = findUserInputSchema.parse(input) const jiraClient = getClient(ctx.configuration) let response @@ -18,11 +11,7 @@ export const findUser: Implementation['actions']['findUser'] = async ({ response = await jiraClient.findUser(validatedInput.accountId) logger .forBot() - .info( - `Successful - Find User - ${ - response?.displayName || 'Unknown' - } - with ID: ${validatedInput.accountId}` - ) + .info(`Successful - Find User - ${response?.displayName || 'Unknown'} - with ID: ${validatedInput.accountId}`) } catch (error) { logger.forBot().debug(`'Find User' exception ${JSON.stringify(error)}`) response = {} diff --git a/integrations/jira/src/actions/new-issue.ts b/integrations/jira/src/actions/new-issue.ts index 6999c56f..03911c1f 100644 --- a/integrations/jira/src/actions/new-issue.ts +++ b/integrations/jira/src/actions/new-issue.ts @@ -3,11 +3,7 @@ import type { Implementation } from '../misc/types' import { getClient } from '../utils' -export const newIssue: Implementation['actions']['newIssue'] = async ({ - ctx, - input, - logger, -}) => { +export const newIssue: Implementation['actions']['newIssue'] = async ({ ctx, input, logger }) => { const validatedInput = newIssueInputSchema.parse(input) const jiraClient = getClient(ctx.configuration) const issue = { diff --git a/integrations/jira/src/actions/update-issue.ts b/integrations/jira/src/actions/update-issue.ts index 5fc31974..f42a737b 100644 --- a/integrations/jira/src/actions/update-issue.ts +++ b/integrations/jira/src/actions/update-issue.ts @@ -3,11 +3,7 @@ import type { Implementation } from '../misc/types' import { getClient } from '../utils' -export const updateIssue: Implementation['actions']['updateIssue'] = async ({ - ctx, - input, - logger, -}) => { +export const updateIssue: Implementation['actions']['updateIssue'] = async ({ ctx, input, logger }) => { const validatedInput = updateIssueInputSchema.parse(input) const jiraClient = getClient(ctx.configuration) const issueUpdate = { diff --git a/integrations/jira/src/client/index.ts b/integrations/jira/src/client/index.ts index 1cb32534..156e3b7f 100644 --- a/integrations/jira/src/client/index.ts +++ b/integrations/jira/src/client/index.ts @@ -25,9 +25,7 @@ export class JiraApi { await this.client.issues.editIssue(issueUpdate) } - async addCommentToIssue( - comment: Version3Parameters.AddComment - ): Promise { + async addCommentToIssue(comment: Version3Parameters.AddComment): Promise { const { id } = await this.client.issueComments.addComment({ issueIdOrKey: comment.issueIdOrKey, body: comment.body, @@ -42,9 +40,7 @@ export class JiraApi { }) } - async findAllUser( - addParams?: Version3Parameters.GetAllUsers - ): Promise { + async findAllUser(addParams?: Version3Parameters.GetAllUsers): Promise { return await this.client.users.getAllUsers(addParams) } } diff --git a/integrations/jira/src/definitions/actions.ts b/integrations/jira/src/definitions/actions.ts index d9207964..489a2d9a 100644 --- a/integrations/jira/src/definitions/actions.ts +++ b/integrations/jira/src/definitions/actions.ts @@ -10,13 +10,7 @@ import { findAllUsersInputSchema, findAllUsersOutputSchema, } from '../misc/custom-schemas' -import { - findUserUi, - newIssueUi, - updateIssueUi, - addCommentToIssueUi, - findAllUsersUi, -} from '../misc/custom-uis' +import { findUserUi, newIssueUi, updateIssueUi, addCommentToIssueUi, findAllUsersUi } from '../misc/custom-uis' const findUser = { title: 'Find User', diff --git a/integrations/jira/src/misc/custom-schemas.ts b/integrations/jira/src/misc/custom-schemas.ts index 63608cc4..01032955 100644 --- a/integrations/jira/src/misc/custom-schemas.ts +++ b/integrations/jira/src/misc/custom-schemas.ts @@ -6,37 +6,23 @@ import { } from './sub-schemas' export const newIssueInputSchema = z.object({ - summary: z - .string() - .describe( - 'The summary of the issue, providing a brief description (e.g. My Issue)' - ), + summary: z.string().describe('The summary of the issue, providing a brief description (e.g. My Issue)'), description: z .string() .optional() .describe( 'The detailed description of the issue (Optional) (e.g. This is an example issue for demonstration purposes)' ), - issueType: z - .string() - .describe( - 'The type of the issue (e.g. "Bug", "Task", "Subtask", "Story" or "Epic")' - ), - projectKey: z - .string() - .describe('The key of the project to which the issue belongs (e.g. TEST)'), + issueType: z.string().describe('The type of the issue (e.g. "Bug", "Task", "Subtask", "Story" or "Epic")'), + projectKey: z.string().describe('The key of the project to which the issue belongs (e.g. TEST)'), parentKey: z .string() .optional() - .describe( - 'The key of the parent issue, if this issue is a sub-task (Optional) (e.g. TEST-1)' - ), + .describe('The key of the parent issue, if this issue is a sub-task (Optional) (e.g. TEST-1)'), assigneeId: z .string() .optional() - .describe( - 'The ID of the user to whom the issue is assigned (Optional) (e.g. 5b10ac8d82e05b22cc7d4ef5)' - ), + .describe('The ID of the user to whom the issue is assigned (Optional) (e.g. 5b10ac8d82e05b22cc7d4ef5)'), }) export const newIssueOutputSchema = z.object({ @@ -46,9 +32,7 @@ export const newIssueOutputSchema = z.object({ export const findUserInputSchema = z.object({ accountId: z .string() - .describe( - 'Account ID (e.g. 5b10a2844c20165700ede21g or 747474:a1b2c3d4-e5f6-7890-a1b2-c3d4e5f67890)' - ), + .describe('Account ID (e.g. 5b10a2844c20165700ede21g or 747474:a1b2c3d4-e5f6-7890-a1b2-c3d4e5f67890)'), }) export const findUserOutputSchema = z.object({ @@ -70,11 +54,7 @@ export const findUserOutputSchema = z.object({ export const updateIssueInputSchema = newIssueInputSchema.partial().extend({ issueKey: z.string().describe('The Key for Issue (e.g. TASK-185)'), - issueType: z - .string() - .describe( - 'The type of the issue (e.g. "Bug", "Task", "Subtask", "Story" or "Epic")' - ), + issueType: z.string().describe('The type of the issue (e.g. "Bug", "Task", "Subtask", "Story" or "Epic")'), }) export const updateIssueOutputSchema = newIssueOutputSchema @@ -89,14 +69,8 @@ export const addCommentToIssueOutputSchema = z.object({ }) export const findAllUsersInputSchema = z.object({ - startAt: z - .number() - .optional() - .describe('The index of the first item to return (Default: 0) (Optional)'), - maxResults: z - .number() - .optional() - .describe('The maximum number of items to return (Default: 50) (Optional)'), + startAt: z.number().optional().describe('The index of the first item to return (Default: 0) (Optional)'), + maxResults: z.number().optional().describe('The maximum number of items to return (Default: 50) (Optional)'), }) export const findAllUsersOutputSchema = z.object({ diff --git a/integrations/jira/src/misc/custom-uis.ts b/integrations/jira/src/misc/custom-uis.ts index 69569695..d28e6317 100644 --- a/integrations/jira/src/misc/custom-uis.ts +++ b/integrations/jira/src/misc/custom-uis.ts @@ -6,28 +6,24 @@ export const findUserUi = { export const newIssueUi = { summary: { - title: - 'The summary of the issue, providing a brief description (e.g. My Issue)', + title: 'The summary of the issue, providing a brief description (e.g. My Issue)', }, description: { title: 'The detailed description of the issue (Optional) (e.g. This is an example issue for demonstration purposes)', }, issueType: { - title: - 'The type of the issue (e.g. "Bug", "Task", "Subtask", "Story" or "Epic")', + title: 'The type of the issue (e.g. "Bug", "Task", "Subtask", "Story" or "Epic")', examples: ['Bug', 'Task', 'Story', 'Subtask', 'Epic'], }, projectKey: { title: 'The key of the project to which the issue belongs (e.g. TEST)', }, parentKey: { - title: - 'The key of the parent issue, if this issue is a sub-task (Optional) (e.g. TEST-1)', + title: 'The key of the parent issue, if this issue is a sub-task (Optional) (e.g. TEST-1)', }, assigneeId: { - title: - 'The ID of the user to whom the issue is assigned (Optional) (e.g. 5b10ac8d82e05b22cc7d4ef5)', + title: 'The ID of the user to whom the issue is assigned (Optional) (e.g. 5b10ac8d82e05b22cc7d4ef5)', }, } @@ -36,29 +32,24 @@ export const updateIssueUi = { title: 'The Key for Issue (Required) (e.g. TASK-185)', }, summary: { - title: - 'The summary of the issue, providing a brief description (Optional) (e.g. My Issue)', + title: 'The summary of the issue, providing a brief description (Optional) (e.g. My Issue)', }, description: { title: 'The detailed description of the issue (Optional) (e.g. This is an example issue for demonstration purposes)', }, issueType: { - title: - 'The type of the issue (Required) (e.g. "Bug", "Task", "Subtask", "Story" or "Epic")', + title: 'The type of the issue (Required) (e.g. "Bug", "Task", "Subtask", "Story" or "Epic")', examples: ['Bug', 'Task', 'Story', 'Subtask', 'Epic'], }, projectKey: { - title: - 'The key of the project to which the issue belongs (Optional) (e.g. TEST)', + title: 'The key of the project to which the issue belongs (Optional) (e.g. TEST)', }, parentKey: { - title: - 'The key of the parent issue, if this issue is a sub-task (Optional) (e.g. TEST-1)', + title: 'The key of the parent issue, if this issue is a sub-task (Optional) (e.g. TEST-1)', }, assigneeId: { - title: - 'The ID of the user to whom the issue is assigned (Optional) (e.g. 5b10ac8d82e05b22cc7d4ef5)', + title: 'The ID of the user to whom the issue is assigned (Optional) (e.g. 5b10ac8d82e05b22cc7d4ef5)', }, } @@ -76,7 +67,6 @@ export const findAllUsersUi = { title: 'The index of the first item to return (Default: 0) (Optional)', }, maxResults: { - title: - ' The maximum number of items to return per page (Default: 50) (Optional)', + title: ' The maximum number of items to return per page (Default: 50) (Optional)', }, } diff --git a/integrations/jira/src/misc/types.ts b/integrations/jira/src/misc/types.ts index fc2ccc80..cab2d884 100644 --- a/integrations/jira/src/misc/types.ts +++ b/integrations/jira/src/misc/types.ts @@ -3,9 +3,7 @@ import type * as botpress from '.botpress' import type { Configuration } from '.botpress/implementation/configuration' export type Config = botpress.configuration.Configuration -export type Implementation = ConstructorParameters< - typeof botpress.Integration ->[0] +export type Implementation = ConstructorParameters[0] export type IntegrationCtx = IntegrationContext export type RegisterFunction = Implementation['register'] diff --git a/integrations/jira/src/setup/register.ts b/integrations/jira/src/setup/register.ts index 1fde01b2..8ba1aef1 100644 --- a/integrations/jira/src/setup/register.ts +++ b/integrations/jira/src/setup/register.ts @@ -1,8 +1,7 @@ import type { RegisterFunction } from '../misc/types' import { getClient } from '../utils' - -export const register: RegisterFunction = async ({ctx}) => { +export const register: RegisterFunction = async ({ ctx }) => { /** * This is called when a bot installs the integration. * You should use this handler to instanciate ressources in the external service and ensure that the configuration is valid. @@ -15,6 +14,5 @@ export const register: RegisterFunction = async ({ctx}) => { throw new Error('Invalid configuration') } - return true; - + return true } diff --git a/integrations/jira/src/utils/index.ts b/integrations/jira/src/utils/index.ts index abf2cc6b..b48a1fbb 100644 --- a/integrations/jira/src/utils/index.ts +++ b/integrations/jira/src/utils/index.ts @@ -1,5 +1,4 @@ import { JiraApi } from '../client' import type { Config } from '../misc/types' -export const getClient = (config: Config) => - new JiraApi(config.host, config.email, config.apiToken) +export const getClient = (config: Config) => new JiraApi(config.host, config.email, config.apiToken)