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
2 changes: 1 addition & 1 deletion integrations/linear/integration.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import listable from './bp_modules/listable'
import { actions, channels, events, configuration, configurations, user, states, entities } from './definitions'

export const INTEGRATION_NAME = 'linear'
export const INTEGRATION_VERSION = '2.3.0'
export const INTEGRATION_VERSION = '2.4.0'

export default new IntegrationDefinition({
name: INTEGRATION_NAME,
Expand Down
7 changes: 7 additions & 0 deletions integrations/linear/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ const LINEAR_WEBHOOK_TS_FIELD = 'webhookTimestamp'

export const handler: bp.IntegrationProps['handler'] = async (props) => {
const { req, ctx, client, logger } = props
logger
.forBot()
.debug(
`Linear handler invoked (method="${req.method ?? ''}", path="${req.path ?? ''}", hasBody=${Boolean(req.body)})`
)

if (req.path === '/oauth') {
logger.forBot().info('Linear OAuth callback received')
return await handleOauth(props).catch((err) => {
logger.forBot().error('Error while processing OAuth', err.response?.data || err.message)
throw err
Expand Down
23 changes: 19 additions & 4 deletions integrations/linear/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,43 @@ const _isWebhookManuallyRegistered = (ctx: bp.HandlerProps['ctx']) =>
ctx.configurationType === 'apiKey' && ctx.configuration.webhookSigningSecret

export const register: bp.IntegrationProps['register'] = async ({ client, ctx, logger }) => {
logger.forBot().info('Registering integration...')
const manuallyRegistered = _isWebhookManuallyRegistered(ctx)
logger.forBot().info('Registering Linear integration.')

const linearClient = await LinearOauthClient.create({ client, ctx })
if (!_isWebhookManuallyRegistered(ctx)) {

if (!manuallyRegistered) {
const webhookUrl = `${process.env.BP_WEBHOOK_URL}/${ctx.webhookId}`
logger.forBot().info('Registering Linear webhook')
try {
await registerWebhook({ linearClient, logger, url: webhookUrl })
logger.forBot().info('Linear webhook registered')
} catch (thrown) {
const errorMessage = thrown instanceof Error ? thrown.message : String(thrown)
throw new RuntimeError(`Failed to register webhook: ${errorMessage}`)
}
} else {
logger
.forBot()
.info('Skipping automatic Linear webhook registration: webhookSigningSecret is set in apiKey configuration.')
}
logger.forBot().info('Integration registered successfully.')
logger.forBot().info(`Linear integration registered successfully (integrationId="${ctx.integrationId}").`)
}

export const unregister: bp.IntegrationProps['unregister'] = async ({ client, ctx, logger }) => {
if (_isWebhookManuallyRegistered(ctx)) {
const manuallyRegistered = _isWebhookManuallyRegistered(ctx)
logger.forBot().info('Unregistering Linear integration.')

if (manuallyRegistered) {
logger.forBot().info('Skipping Linear webhook unregistration: webhook was manually registered.')
return
}
try {
const linearClient = await LinearOauthClient.create({ client, ctx })
const webhookUrl = `${process.env.BP_WEBHOOK_URL}/${ctx.webhookId}`
logger.forBot().info('Unregistering Linear webhook.')
await unregisterWebhook({ linearClient, logger, url: webhookUrl })
logger.forBot().info('Linear webhook unregistration step completed.')
} catch (thrown) {
const errorMessage = thrown instanceof Error ? thrown.message : String(thrown)
logger.forBot().warn('Failed to unregister webhook:', errorMessage)
Expand Down
Loading