Skip to content

Commit

Permalink
Extend htmlToJiraMarkdown to support auto conversion of jira ticket…
Browse files Browse the repository at this point in the history
…s to links

Also made `jiraMarkdownToHtml` hyperlinks parsing more robuts
  • Loading branch information
sebastian-aranda committed Oct 26, 2023
1 parent 1657756 commit 8440276
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion love/src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ export const MTCSCommands = {
/*****************************************************************************/
/******************************OLE configurations*****************************/
/*****************************************************************************/
export const AUTO_HYPERLINK_JIRA_PROJECTS = ['BLOCK', 'LOVE', 'OBS', 'DM'];

export const LOG_REFRESH_INTERVAL_MS = 60000;

export const OLE_COMMENT_TYPE_OPTIONS = [
Expand Down Expand Up @@ -653,7 +655,7 @@ export const ccCameraFilterChangerDetailedStateToStyle = {
export const alignedStateToStyle = {
ALIGNED: 'ok',
'NOT ALIGNED': 'warning',
}
};

//DM Flow
export const dmFlowStatusMap = {
Expand Down
13 changes: 11 additions & 2 deletions love/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import html2canvas from 'html2canvas';
import { DateTime } from 'luxon';
import { toast } from 'react-toastify';
import Moment from 'moment';
import { WEBSOCKET_SIMULATION, SUBPATH, ISO_INTEGER_DATE_FORMAT } from 'Config.js';
import { WEBSOCKET_SIMULATION, SUBPATH, ISO_INTEGER_DATE_FORMAT, AUTO_HYPERLINK_JIRA_PROJECTS } from 'Config.js';

/* Backwards compatibility of Array.flat */
if (Array.prototype.flat === undefined) {
Expand Down Expand Up @@ -1935,6 +1935,15 @@ export function htmlToJiraMarkdown(html) {
return `{code}${p1}{code}`;
});

// Parse Jira tickets names
// At this point, hyperlinks have been already parsed.
// The following regex allows us to parse Jira tickets names that are not hyperlinks
const jiraTicketRegexString = `(?<!\\[[^\\]]*)(${AUTO_HYPERLINK_JIRA_PROJECTS.join('|')})+-\\d+\\b`;
const jiraTicketRegex = new RegExp(jiraTicketRegexString, 'g');
markdown = markdown.replace(jiraTicketRegex, (match) => {
return `[${match}|https://jira.lsstcorp.org/browse/${match}]`;
});

// TODO: DM-41265
// markdown = markdown.replace(/<ul>|<\/ul>|<ol>|<\/ol>|<li>/g, '');
// markdown = markdown.replace(/<\/li>/g, '\n');
Expand Down Expand Up @@ -1998,7 +2007,7 @@ export function jiraMarkdownToHtml(markdown, options = { codeFriendly: true, par
});

// Parse links
html = html.replace(/\[(.*)\|(.*)\]/g, (match, p1, p2) => {
html = html.replace(/\[(.*?)\|(.*?)\]/g, (match, p1, p2) => {
return `<a href="${p2}" rel="noopener noreferrer" target="_blank">${p1}</a>`;
});

Expand Down

0 comments on commit 8440276

Please sign in to comment.