-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(triggers): add Atlassian triggers for Jira, JSM, and Confluence #4211
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
48e69b3
feat(triggers): add Atlassian triggers for Jira, JSM, and Confluence
waleedlatif1 e8561c9
fix(triggers): replace any with Record<string, unknown> in confluence…
waleedlatif1 fd7333a
lint
waleedlatif1 4eec324
fix(triggers): use comment.id in JSM idempotency, fix confluence type…
waleedlatif1 0684382
fix(triggers): correct comment.body type to json, fix TriggerOutput d…
waleedlatif1 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
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
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
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
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,97 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import { validateJiraSignature } from '@/lib/webhooks/providers/jira' | ||
| import type { | ||
| EventMatchContext, | ||
| FormatInputContext, | ||
| FormatInputResult, | ||
| WebhookProviderHandler, | ||
| } from '@/lib/webhooks/providers/types' | ||
| import { createHmacVerifier } from '@/lib/webhooks/providers/utils' | ||
|
|
||
| const logger = createLogger('WebhookProvider:JSM') | ||
|
|
||
| /** | ||
| * Jira Service Management webhook handler. | ||
| * | ||
| * JSM uses the Jira webhook infrastructure. The handler reuses the same HMAC | ||
| * signature validation as Jira and adds JSM-specific event matching logic | ||
| * to route events to the correct trigger based on event type and changelog context. | ||
| */ | ||
| export const jsmHandler: WebhookProviderHandler = { | ||
| verifyAuth: createHmacVerifier({ | ||
| configKey: 'webhookSecret', | ||
| headerName: 'X-Hub-Signature', | ||
| validateFn: validateJiraSignature, | ||
| providerLabel: 'JSM', | ||
| }), | ||
|
|
||
| async formatInput({ body, webhook }: FormatInputContext): Promise<FormatInputResult> { | ||
| const { extractRequestData, extractCommentData } = await import('@/triggers/jsm/utils') | ||
| const providerConfig = (webhook.providerConfig as Record<string, unknown>) || {} | ||
| const triggerId = providerConfig.triggerId as string | undefined | ||
|
|
||
| if (triggerId === 'jsm_request_commented') { | ||
| return { input: extractCommentData(body as Record<string, unknown>) } | ||
| } | ||
|
|
||
| // For the generic webhook, pass through the full payload so no data is lost | ||
| if (!triggerId || triggerId === 'jsm_webhook') { | ||
| const obj = body as Record<string, unknown> | ||
| return { | ||
| input: { | ||
| webhookEvent: obj.webhookEvent, | ||
| timestamp: obj.timestamp, | ||
| user: obj.user || null, | ||
| issue_event_type_name: obj.issue_event_type_name, | ||
| issue: obj.issue || {}, | ||
| changelog: obj.changelog, | ||
| comment: obj.comment, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| return { input: extractRequestData(body as Record<string, unknown>) } | ||
| }, | ||
|
|
||
| async matchEvent({ webhook, workflow, body, requestId, providerConfig }: EventMatchContext) { | ||
| const triggerId = providerConfig.triggerId as string | undefined | ||
| const obj = body as Record<string, unknown> | ||
|
|
||
| if (triggerId && triggerId !== 'jsm_webhook') { | ||
| const webhookEvent = obj.webhookEvent as string | undefined | ||
| const issueEventTypeName = obj.issue_event_type_name as string | undefined | ||
| const changelog = obj.changelog as | ||
| | { items?: Array<{ field?: string; toString?: string }> } | ||
| | undefined | ||
|
|
||
| const { isJsmEventMatch } = await import('@/triggers/jsm/utils') | ||
| if (!isJsmEventMatch(triggerId, webhookEvent || '', issueEventTypeName, changelog)) { | ||
| logger.debug( | ||
| `[${requestId}] JSM event mismatch for trigger ${triggerId}. Event: ${webhookEvent}. Skipping execution.`, | ||
| { | ||
| webhookId: webhook.id, | ||
| workflowId: workflow.id, | ||
| triggerId, | ||
| receivedEvent: webhookEvent, | ||
| } | ||
| ) | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| return true | ||
| }, | ||
|
|
||
| extractIdempotencyId(body: unknown) { | ||
| const obj = body as Record<string, unknown> | ||
| const issue = obj.issue as Record<string, unknown> | undefined | ||
| const ts = obj.timestamp ?? '' | ||
| if (obj.webhookEvent && issue?.id) { | ||
| return `jsm:${obj.webhookEvent}:${issue.id}:${ts}` | ||
| } | ||
| if (obj.webhookEvent && ts) { | ||
| return `jsm:${obj.webhookEvent}:${ts}` | ||
| } | ||
| return null | ||
| }, | ||
|
waleedlatif1 marked this conversation as resolved.
|
||
| } | ||
Oops, something went wrong.
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.