Skip to content

Commit 465bf89

Browse files
feat(bugbuster): no longer auto create a linear issue from a github issue (botpress#13250)
1 parent d2b035f commit 465bf89

File tree

6 files changed

+43
-47
lines changed

6 files changed

+43
-47
lines changed

.github/workflows/bugbuster.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Login to Botpress
2929
run: pnpm bp login -y --token ${{ secrets.PRODUCTION_TOKEN_CLOUD_OPS_ACCOUNT }} --workspace-id ${{ secrets.PRODUCTION_CLOUD_OPS_WORKSPACE_ID }}
3030
- name: Install Botpress Dependencies
31-
run: pnpm bp add linear -y && pnpm bp add github -y && pnpm bp add slack
31+
run: pnpm bp add github -y && pnpm bp add slack
3232
- name: Type Check
3333
run: tsc --noEmit
3434
- name: Build

bots/bugbuster/integrations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as pathlib from 'path'
33

44
const rootDir = pathlib.resolve(__dirname, '..', '..')
55
const integrationsDir = pathlib.join(rootDir, 'integrations')
6-
const integrations = ['linear', 'github', 'slack']
6+
const integrations = ['github', 'slack']
77

88
const main = async () => {
99
for (const integration of integrations) {

bots/bugbuster/src/bot.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@ import { z } from '@botpress/sdk'
22
import * as bp from '.botpress'
33

44
const github = new bp.github.Github()
5-
const linear = new bp.linear.Linear()
65
const slack = new bp.slack.Slack()
76

7+
type AsyncFunction = (...args: any[]) => Promise<any>
8+
89
export type Bot = typeof bot
910
export type EventHandler = Parameters<Bot['event']>[0]
1011
export type EventHandlerProps = Parameters<EventHandler>[0]
1112
export type MessageHandler = Parameters<Bot['message']>[0]
1213
export type MessageHandlerProps = Parameters<MessageHandler>[0]
1314

15+
export type Client = EventHandlerProps['client']
16+
export type ClientOperation = keyof {
17+
[K in keyof Client as Client[K] extends AsyncFunction ? K : never]: null
18+
}
19+
export type ClientInputs = {
20+
[K in ClientOperation]: Parameters<Client[K]>[0]
21+
}
22+
export type ClientOutputs = {
23+
[K in ClientOperation]: Awaited<ReturnType<Client[K]>>
24+
}
25+
1426
export type BotEvents = {
1527
[K in EventHandlerProps['event']['type']]: Extract<EventHandlerProps['event'], { type: K }>
1628
}
@@ -24,7 +36,6 @@ const listenersSchema = z.object({
2436
export const bot = new bp.Bot({
2537
integrations: {
2638
github,
27-
linear,
2839
slack,
2940
},
3041
states: {
+5-27
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,17 @@
1+
import * as listener from '../listeners'
12
import { Handler } from './typings'
23

3-
export const handleNewIssue: Handler<'github:issueOpened'> = async ({ client, ctx }, event): Promise<void> => {
4+
export const handleNewIssue: Handler<'github:issueOpened'> = async (props, event): Promise<void> => {
45
const githubIssue = event.payload
56

67
console.info('Received GitHub issue', githubIssue)
78

8-
const { output } = await client.callAction({
9-
type: 'linear:createIssue',
10-
input: {
11-
title: githubIssue.title,
12-
description: githubIssue.content ?? 'No content...',
13-
teamName: 'Cloud Services',
14-
labels: ['origin/github'],
15-
},
16-
})
17-
18-
const { issue } = output
19-
20-
const { conversation } = await client.getOrCreateConversation({
21-
integrationName: 'linear',
22-
channel: 'issue',
23-
tags: {
24-
['linear:id']: issue.id,
25-
},
26-
})
27-
28-
const issueUrl = `https://github.com/${githubIssue.repositoryOwner}/${githubIssue.repositoryName}/issues/${githubIssue.number}`
9+
const message = ['The following issue was just created in GitHub:', githubIssue.title, githubIssue.content].join('\n')
2910

30-
await client.createMessage({
11+
await listener.notifyListeners(props, {
3112
type: 'text',
32-
conversationId: conversation.id,
33-
userId: ctx.botId,
34-
tags: {},
3513
payload: {
36-
text: `Automatically created from GitHub issue: ${issueUrl}`,
14+
text: message,
3715
},
3816
})
3917
}

bots/bugbuster/src/handlers/sync-issues.ts

+7-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Handler } from './typings'
77
*/
88
export const handleSyncIssuesRequest: Handler<'syncIssuesRequest'> = async (props) => {
99
try {
10-
const { client, ctx } = props
10+
const { client } = props
1111
const {
1212
output: { targets: githubIssues },
1313
} = await client.callAction({
@@ -42,20 +42,12 @@ export const handleSyncIssuesRequest: Handler<'syncIssuesRequest'> = async (prop
4242
].join('\n')
4343
console.info(message)
4444

45-
const state = await listeners.readListeners(props)
46-
console.info(`Sending message to ${state.conversationIds.length} conversation(s)`)
47-
48-
for (const conversationId of state.conversationIds) {
49-
await client.createMessage({
50-
conversationId,
51-
userId: ctx.botId,
52-
tags: {},
53-
type: 'text',
54-
payload: {
55-
text: message,
56-
},
57-
})
58-
}
45+
await listeners.notifyListeners(props, {
46+
type: 'text',
47+
payload: {
48+
text: message,
49+
},
50+
})
5951
} catch (thrown) {
6052
// If recurring event fails to many times, bridge stops sending it... We don't want that
6153
const err = thrown instanceof Error ? thrown : new Error(`${thrown}`)

bots/bugbuster/src/listeners.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { BotListeners, EventHandlerProps } from './bot'
1+
import { BotListeners, EventHandlerProps, ClientInputs } from './bot'
22

33
type Props = Omit<EventHandlerProps, 'event'>
4+
type Message = Pick<ClientInputs['createMessage'], 'type' | 'payload'>
5+
46
const emptyListeners: BotListeners = {
57
conversationIds: [],
68
}
@@ -28,3 +30,16 @@ export const writeListeners = async (props: Props, state: BotListeners) => {
2830
payload: state,
2931
})
3032
}
33+
34+
export const notifyListeners = async (props: Props, message: Message) => {
35+
const state = await readListeners(props)
36+
console.info(`Sending message to ${state.conversationIds.length} conversation(s)`)
37+
for (const conversationId of state.conversationIds) {
38+
await props.client.createMessage({
39+
conversationId,
40+
userId: props.ctx.botId,
41+
tags: {},
42+
...message,
43+
})
44+
}
45+
}

0 commit comments

Comments
 (0)