import { Embed } from '../model/DiscordApi' ; import { DirectParseProvider } from '../provider/BaseProvider' ; /**
 * https://developer.atlassian.com/server/jira/platform/webhooks/
 */ export class Jira extends DirectParseProvider { constructor ( ) { super ( ) ; this . setEmbedColor ( 0x1e45a8 ) ; } public getName ( ) { return 'Jira' ; } public getPath ( ) { return 'jira' ; } public async parseData ( ) { if ( this . body . webhookEvent == null ) { this . nullifyPayload ( ) ; return ; } let isIssue ; if ( this . body . webhookEvent . startsWith ( 'jira:issue_' ) ) { isIssue = true ; } else if ( this . body . webhookEvent . startsWith ( 'comment_' ) ) { isIssue = false ; if ( this . body . issue == null ) { this . nullifyPayload ( ) ; return ; } } else { return ; } const issueHasAsignee = this . body ?. issue ?. fields ?. assignee != null ; const issue = this . body . issue ; const user = this . body . user || { displayName : 'Anonymous' } ; const action = this . body . webhookEvent . split ( '_' ) [ 1 ] ; const embed = { title : `${ issue . key } - ${ issue . fields . summary }` , url : this . createBrowseUrl ( issue ) } ; if ( isIssue ) { embed . description = `${ user . displayName } ${ action } issue: ${ embed . title }${ issueHasAsignee ? ` (${ issue . fields . assignee . displayName })` : '' } ` ; } else { const comment = this . body . comment ; embed . description = `${ comment . updateAuthor . displayName } ${ action } comment: ${ comment . body }` ; } this . addEmbed ( embed ) ; } private createBrowseUrl ( issue ) { const url = new URL ( issue . self ) ; const path = url . pathname . match ( /.+?(?=\/rest\/api)/ ) ?? '' ; url . pathname = `${ path }/browse/${ issue . key }` ; return url . toString ( ) ; } }