-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(atlassian): add many more triggers and tools for jsm, jira, and confluence #3205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
waleedlatif1
wants to merge
3
commits into
staging
Choose a base branch
from
feat/atlassian
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
527 changes: 507 additions & 20 deletions
527
apps/docs/content/docs/en/tools/jira_service_management.mdx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { checkInternalAuth } from '@/lib/auth/hybrid' | ||
| import { validateJiraCloudId, validateJiraIssueKey } from '@/lib/core/security/input-validation' | ||
| import { | ||
| downloadJsmAttachments, | ||
| getJiraCloudId, | ||
| getJsmApiBaseUrl, | ||
| getJsmHeaders, | ||
| } from '@/tools/jsm/utils' | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
|
|
||
| const logger = createLogger('JsmAttachmentsAPI') | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| const auth = await checkInternalAuth(request) | ||
| if (!auth.success || !auth.userId) { | ||
| return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| try { | ||
| const body = await request.json() | ||
| const { | ||
| domain, | ||
| accessToken, | ||
| cloudId: cloudIdParam, | ||
| issueIdOrKey, | ||
| includeAttachments, | ||
| start, | ||
| limit, | ||
| } = body | ||
|
|
||
| if (!domain) { | ||
| logger.error('Missing domain in request') | ||
| return NextResponse.json({ error: 'Domain is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!accessToken) { | ||
| logger.error('Missing access token in request') | ||
| return NextResponse.json({ error: 'Access token is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| if (!issueIdOrKey) { | ||
| logger.error('Missing issueIdOrKey in request') | ||
| return NextResponse.json({ error: 'Issue ID or key is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| const issueIdOrKeyValidation = validateJiraIssueKey(issueIdOrKey, 'issueIdOrKey') | ||
| if (!issueIdOrKeyValidation.isValid) { | ||
| return NextResponse.json({ error: issueIdOrKeyValidation.error }, { status: 400 }) | ||
| } | ||
|
|
||
| const cloudId = cloudIdParam || (await getJiraCloudId(domain, accessToken)) | ||
|
|
||
| const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId') | ||
| if (!cloudIdValidation.isValid) { | ||
| return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 }) | ||
| } | ||
|
|
||
| const baseUrl = getJsmApiBaseUrl(cloudId) | ||
| const params = new URLSearchParams() | ||
| if (start) params.append('start', start) | ||
| if (limit) params.append('limit', limit) | ||
|
|
||
| const url = `${baseUrl}/request/${issueIdOrKey}/attachment${params.toString() ? `?${params.toString()}` : ''}` | ||
|
|
||
| logger.info('Fetching request attachments from:', url) | ||
|
|
||
| const response = await fetch(url, { | ||
| method: 'GET', | ||
| headers: getJsmHeaders(accessToken), | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| const errorText = await response.text() | ||
| logger.error('JSM API error:', { | ||
| status: response.status, | ||
| statusText: response.statusText, | ||
| error: errorText, | ||
| }) | ||
|
|
||
| return NextResponse.json( | ||
| { error: `JSM API error: ${response.status} ${response.statusText}`, details: errorText }, | ||
| { status: response.status } | ||
| ) | ||
| } | ||
|
|
||
| const data = await response.json() | ||
|
|
||
| const rawAttachments = data.values || [] | ||
|
|
||
| const attachments = rawAttachments.map((att: Record<string, unknown>) => ({ | ||
| filename: att.filename ?? '', | ||
| author: att.author | ||
| ? { | ||
| accountId: (att.author as Record<string, unknown>).accountId ?? '', | ||
| displayName: (att.author as Record<string, unknown>).displayName ?? '', | ||
| active: (att.author as Record<string, unknown>).active ?? true, | ||
| } | ||
| : null, | ||
| created: att.created ?? null, | ||
| size: att.size ?? 0, | ||
| mimeType: att.mimeType ?? '', | ||
| })) | ||
|
|
||
| let files: Array<{ name: string; mimeType: string; data: string; size: number }> | undefined | ||
|
|
||
| if (includeAttachments && rawAttachments.length > 0) { | ||
| const downloadable = rawAttachments | ||
| .filter((att: Record<string, unknown>) => { | ||
| const links = att._links as Record<string, string> | undefined | ||
| return links?.content | ||
| }) | ||
| .map((att: Record<string, unknown>) => ({ | ||
| contentUrl: (att._links as Record<string, string>).content as string, | ||
| filename: (att.filename as string) ?? '', | ||
| mimeType: (att.mimeType as string) ?? '', | ||
| size: (att.size as number) ?? 0, | ||
| })) | ||
|
|
||
| if (downloadable.length > 0) { | ||
| files = await downloadJsmAttachments(downloadable, accessToken) | ||
| } | ||
| } | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| output: { | ||
| ts: new Date().toISOString(), | ||
| issueIdOrKey, | ||
| attachments, | ||
| total: data.size || 0, | ||
| isLastPage: data.isLastPage ?? true, | ||
| ...(files && files.length > 0 ? { files } : {}), | ||
| }, | ||
| }) | ||
| } catch (error) { | ||
| logger.error('Error fetching attachments:', { | ||
| error: error instanceof Error ? error.message : String(error), | ||
| stack: error instanceof Error ? error.stack : undefined, | ||
| }) | ||
|
|
||
| return NextResponse.json( | ||
| { | ||
| error: error instanceof Error ? error.message : 'Internal server error', | ||
| success: false, | ||
| }, | ||
| { status: 500 } | ||
| ) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.