Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
36 changes: 4 additions & 32 deletions apps/sim/app/api/tools/jira/update/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
import { validateJiraCloudId, validateJiraIssueKey } from '@/lib/core/security/input-validation'
import { getJiraCloudId, parseAtlassianErrorMessage } from '@/tools/jira/utils'
import { getJiraCloudId, parseAtlassianErrorMessage, toAdf } from '@/tools/jira/utils'

export const dynamic = 'force-dynamic'

Expand All @@ -15,7 +15,7 @@ const jiraUpdateSchema = z.object({
issueKey: z.string().min(1, 'Issue key is required'),
summary: z.string().optional(),
title: z.string().optional(),
description: z.string().optional(),
description: z.union([z.string(), z.record(z.unknown())]).optional(),
Comment thread
waleedlatif1 marked this conversation as resolved.
priority: z.string().optional(),
assignee: z.string().optional(),
labels: z.array(z.string()).optional(),
Expand Down Expand Up @@ -91,21 +91,7 @@ export async function PUT(request: NextRequest) {
}

if (description !== undefined && description !== null && description !== '') {
fields.description = {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: description,
},
],
},
],
}
fields.description = toAdf(description)
}

if (priority !== undefined && priority !== null && priority !== '') {
Expand Down Expand Up @@ -136,21 +122,7 @@ export async function PUT(request: NextRequest) {
}

if (environment !== undefined && environment !== null && environment !== '') {
fields.environment = {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: environment,
},
],
},
],
}
fields.environment = toAdf(environment)
}

if (
Expand Down
34 changes: 3 additions & 31 deletions apps/sim/app/api/tools/jira/write/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createLogger } from '@sim/logger'
import { type NextRequest, NextResponse } from 'next/server'
import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
import { validateAlphanumericId, validateJiraCloudId } from '@/lib/core/security/input-validation'
import { getJiraCloudId, parseAtlassianErrorMessage } from '@/tools/jira/utils'
import { getJiraCloudId, parseAtlassianErrorMessage, toAdf } from '@/tools/jira/utils'

export const dynamic = 'force-dynamic'

Expand Down Expand Up @@ -85,21 +85,7 @@ export async function POST(request: NextRequest) {
}

if (description !== undefined && description !== null && description !== '') {
fields.description = {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: description,
},
],
},
],
}
fields.description = toAdf(description)
}

if (parent !== undefined && parent !== null && parent !== '') {
Expand Down Expand Up @@ -144,21 +130,7 @@ export async function POST(request: NextRequest) {
}

if (environment !== undefined && environment !== null && environment !== '') {
fields.environment = {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: environment,
},
],
},
],
}
fields.environment = toAdf(environment)
}

if (
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/jira/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const jiraUpdateTool: ToolConfig<JiraUpdateParams, JiraUpdateResponse> =
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'New description for the issue',
description:
'New description for the issue. Accepts plain text (auto-wrapped in ADF) or a raw ADF document object',
},
priority: {
type: 'string',
Expand Down
20 changes: 20 additions & 0 deletions apps/sim/tools/jira/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ const logger = createLogger('JiraUtils')

const MAX_ATTACHMENT_SIZE = 50 * 1024 * 1024

/**
* Converts a value to ADF format. If the value is already an ADF document object,
* it is returned as-is. If it is a plain string, it is wrapped in a single-paragraph ADF doc.
*/
export function toAdf(value: string | Record<string, unknown>): Record<string, unknown> {
if (typeof value === 'object' && value.type === 'doc') {
return value
}
return {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [{ type: 'text', text: String(value) }],
},
],
}
Comment thread
waleedlatif1 marked this conversation as resolved.
Comment thread
waleedlatif1 marked this conversation as resolved.
}

/**
* Extracts plain text from Atlassian Document Format (ADF) content.
* Returns null if content is falsy.
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/jira/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const jiraWriteTool: ToolConfig<JiraWriteParams, JiraWriteResponse> = {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Description for the issue',
description:
'Description for the issue. Accepts plain text (auto-wrapped in ADF) or a raw ADF document object',
},
priority: {
type: 'string',
Expand Down
16 changes: 8 additions & 8 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading