Skip to content
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

Work in progress for Jira Provider updates #211

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all 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
134 changes: 100 additions & 34 deletions src/provider/Jira.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Embed } from '../model/DiscordApi.js'
import {Embed, EmbedImage, EmbedThumbnail} from '../model/DiscordApi.js'
import { DirectParseProvider } from '../provider/BaseProvider.js'

/**
Expand All @@ -19,45 +19,111 @@ export class Jira extends DirectParseProvider {
}

public async parseData(): Promise<void> {
//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 {
Expand Down