From e56856c7d36fbc8458b6313bd6563a58f9437fd3 Mon Sep 17 00:00:00 2001 From: William Chalifoux Date: Wed, 8 Nov 2023 16:28:23 -0500 Subject: [PATCH] Work in progress --- src/provider/Jira.ts | 134 ++++++++++++++++++++++++++++++++----------- 1 file changed, 100 insertions(+), 34 deletions(-) diff --git a/src/provider/Jira.ts b/src/provider/Jira.ts index 8f178eb..c0ed0a6 100644 --- a/src/provider/Jira.ts +++ b/src/provider/Jira.ts @@ -1,4 +1,4 @@ -import { Embed } from '../model/DiscordApi.js' +import {Embed, EmbedImage, EmbedThumbnail} from '../model/DiscordApi.js' import { DirectParseProvider } from '../provider/BaseProvider.js' /** @@ -19,45 +19,111 @@ export class Jira extends DirectParseProvider { } public async parseData(): Promise { + //If no webhookEvent is provided, return a descriptive message with documentation to help the user configure their request properly if (this.body.webhookEvent == null) { - this.nullifyPayload() - return - } + const embed: Embed={ + description: `An issue has occurred. No \`webhookEvent\` was received with the request. For more information, take a look at the SkyHook documentation TODO.`, + title: `Problem Occurred`, + url: ''} + //todo add documentation link + this.addEmbed(embed) + }else { + // extract variable from Jira + 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] - let isIssue: boolean - if (this.body.webhookEvent.startsWith('jira:issue_')) { - isIssue = true - } else if (this.body.webhookEvent.startsWith('comment_')) { - isIssue = false - if (this.body.issue == null) { - // What's the point of notifying a new comment if ONLY comment information is sent? - // Do we care that a comment was made if we cant tell what was commented on? - // This solution will silence errors until someone makes sense of Atlassian's decisions.. - this.nullifyPayload() - return + const tmb: EmbedThumbnail = { + url: `${this.body.iconUrl}`, + height: 80, + width: 80 } - } else { - return - } - // extract variable from Jira - 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 img: EmbedImage = { + url: `${this.body.iconUrl}`, + height: 80, + width: 80 + } + + const embed: Embed = { + title: `${img} ${issue.key} - ${issue.fields.summary}`, + thumbnail: tmb, + image: img, + // thumbnail: { + // url: this.body.iconUrl, + // height: 80, + // width: 80 + // }, + // image: { + // url: this.body.iconUrl, + // height: 80, + // width: 80 + // }, + url: this.createBrowseUrl(issue) + } + // embed.image = img + // embed.thumbnail = img + // console.log(img.url) + + switch (this.body.webhookEvent) { + // case null: + // embed.description = `This trigger has not been implemented on SkyHook yet.` + // break + case 'jira:issue_created': + embed.description = `${user.displayName} ${action} issue: ${embed.title}${issueHasAsignee ? ` (${issue.fields.assignee.displayName})` : ''} ` + break + case 'jira:issue_updated': + embed.description = `${user.displayName} ${action} issue: ${embed.title}${issueHasAsignee ? ` (${issue.fields.assignee.displayName})` : ''} ` + break + case 'jira:issue_deleted': + embed.description = `This trigger has not been implemented on SkyHook yet.` + break + case 'jira:issue_comment_created': + const comment = this.body.comment + embed.description = `${comment.updateAuthor.displayName} ${action} comment: ${comment.body}` + break + case 'jira:issue_comment_updated': + embed.description = `This trigger has not been implemented on SkyHook yet.` + break + case 'jira:issue_comment_deleted': + embed.description = `This trigger has not been implemented on SkyHook yet.` + break + case 'jira:worklog_created': + case 'jira:worklog_updated': + case 'jira:worklog_deleted': + case 'jira:version_released': + case 'jira:version_unreleased': + case 'jira:version_created': + case 'jira:version_updated': + case 'jira:version_deleted': + case 'jira:version_moved': + case 'jira:board_created': + case 'jira:board_updated': + case 'jira:board_deleted': + case 'jira:sprint_created': + case 'jira:sprint_updated': + case 'jira:sprint_deleted': + case 'jira:sprint_started': + case 'jira:sprint_closed': + case 'jira:sprint_reopened': + case 'jira:issue_generic': + case 'jira:issue_assigned': + embed.title = 'Trigger not implemented' + embed.url = '' + embed.description = `This trigger has not been implemented on SkyHook yet.` + break + default: + //todo add documentation link + embed.title = 'Problem occurred' + embed.url = '' + embed.description = `An issue has occurred. Make sure you implemented a valid \`webhookEvent\`. For more information, take a look at the SkyHook documentation. Here is what you provided for the webhookEvent: \`${this.body.webhookEvent}\`` + // embed.description = `An issue has occurred. Make sure you implemented a template from the SkyHook documentation. Here is what you provided for the webhook event: ${this.body.webhookEvent}` + break + } + this.addEmbed(embed) - // create the embed - const embed: 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: { self: string, key: string }): string {