Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions integrations/jira/integration.definition.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions integrations/jira/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
41 changes: 18 additions & 23 deletions integrations/jira/src/actions/add-comment-to-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
15 changes: 3 additions & 12 deletions integrations/jira/src/actions/find-all-users.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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[]
Expand Down
17 changes: 3 additions & 14 deletions integrations/jira/src/actions/find-user.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
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
try {
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 = {}
Expand Down
6 changes: 1 addition & 5 deletions integrations/jira/src/actions/new-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 1 addition & 5 deletions integrations/jira/src/actions/update-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 2 additions & 6 deletions integrations/jira/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export class JiraApi {
await this.client.issues.editIssue(issueUpdate)
}

async addCommentToIssue(
comment: Version3Parameters.AddComment
): Promise<string> {
async addCommentToIssue(comment: Version3Parameters.AddComment): Promise<string> {
const { id } = await this.client.issueComments.addComment({
issueIdOrKey: comment.issueIdOrKey,
body: comment.body,
Expand All @@ -42,9 +40,7 @@ export class JiraApi {
})
}

async findAllUser(
addParams?: Version3Parameters.GetAllUsers
): Promise<Version3Models.User[]> {
async findAllUser(addParams?: Version3Parameters.GetAllUsers): Promise<Version3Models.User[]> {
return await this.client.users.getAllUsers(addParams)
}
}
8 changes: 1 addition & 7 deletions integrations/jira/src/definitions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
44 changes: 9 additions & 35 deletions integrations/jira/src/misc/custom-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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
Expand All @@ -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({
Expand Down
30 changes: 10 additions & 20 deletions integrations/jira/src/misc/custom-uis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
},
}

Expand All @@ -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)',
},
}

Expand All @@ -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)',
},
}
4 changes: 1 addition & 3 deletions integrations/jira/src/misc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof botpress.Integration>[0]
export type IntegrationCtx = IntegrationContext<Configuration>

export type RegisterFunction = Implementation['register']
Expand Down
6 changes: 2 additions & 4 deletions integrations/jira/src/setup/register.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,6 +14,5 @@ export const register: RegisterFunction = async ({ctx}) => {
throw new Error('Invalid configuration')
}

return true;

return true
}
Loading