mirror of
https://github.com/wekan/wekan.git
synced 2026-12-03 06:59:41 -05:00
Jira import: Jira Server and Data Center exports, as OpenProject's Jira Migrator reads them.
Compared with OpenProject's Jira Migrator, which reads Jira Server and Data
Center through REST API v2. There a description and a comment are Jira wiki
markup, not Cloud's ADF, and WeKan kept them as typed: a numbered list item
was a heading, bold was italic, and {code}, [text|url], h2. and tables showed
as typed. They are Markdown now (models/lib/jiraWikiMarkup.js).
The reporter, the creator and comment authors are offered for member mapping
too, not only assignees, so a comment is written as its mapped author. An
attachment is downloaded with a Data Center personal access token as Bearer
when no username is given; Jira Cloud still needs its email.
TODO.md lists what OpenProject migrates that WeKan does not yet.
Thanks to xet7 !
This commit is contained in:
1 parent
88256e64e2
commit
6886b2ea03
9 files changed
+417
-16
No files matched your search
@@ -120,6 +120,15 @@ color, Blocked), and a WeKan board's every field by
|
||||
`tests/wekanCardFields.test.cjs`. What is left needs what this checkout does
|
||||
not have:
|
||||
|
||||
- Jira Server and Data Center, checked with a real instance: WeKan's Jira
|
||||
import was compared on 2026-11-28 with OpenProject's Jira Migrator
|
||||
(opf/openproject `app/workers/import/jira_*`, which reads
|
||||
`/rest/api/2/search?fields=*all&expand=changelog`), and its wiki markup,
|
||||
people and personal access tokens are handled now. Still not imported, as
|
||||
OpenProject does: the issue history (`changelog.histories`), watchers,
|
||||
affected versions (`fields.versions`), single worklog entries (only the
|
||||
totals are), and an image in the markup (`!name.png!`) linked to the
|
||||
imported attachment of that name rather than to its bare name.
|
||||
- Each tool's newest release, checked with a real export file of it: Planner,
|
||||
Wrike, Teamwork, Businessmap, MeisterTask, Quire and Jira - the
|
||||
proprietary ones, whose current export is only seen with an account
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { membersMode, membersMappingFor } from '/models/lib/importMembersMode';
|
||||
import { adfPlainText } from './lib/externalParsers';
|
||||
import { jiraTextToMarkdown } from './lib/jiraWikiMarkup';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { ReactiveCache } from '/imports/reactiveCache';
|
||||
import Activities from '/models/activities';
|
||||
@@ -243,7 +244,8 @@ export class JiraCreator {
|
||||
archived: false,
|
||||
boardId,
|
||||
dateLastActivity: this._now(),
|
||||
description: adfPlainText(fields.description),
|
||||
// ADF from Cloud's API v3; wiki markup from Server, Data Center and v2.
|
||||
description: jiraTextToMarkdown(fields.description, adfPlainText),
|
||||
listId: this.lists[statusName],
|
||||
swimlaneId: this.swimlane,
|
||||
// Search order, which is the JQL's ORDER BY.
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
//
|
||||
// Jira fields.attachment[].content - /rest/api/3/attachment/content/<id>,
|
||||
// which answers with a redirect to the file; Basic EMAIL:API-TOKEN
|
||||
// on Cloud, Basic USERNAME:PASSWORD on Server and Data Center, or,
|
||||
// with no username, Bearer PERSONAL-ACCESS-TOKEN (Data Center 8.14+)
|
||||
// - /secure/attachment/<id>/<name> there
|
||||
// Deck GET /index.php/apps/deck/api/v1.0|v1.1/boards/<board>/stacks/<stack>
|
||||
// /cards/<card>/attachments/<id> (v1.1 for the `file` type, the
|
||||
// Nextcloud Files ones of Deck 1.3+); Basic USER:APP-PASSWORD,
|
||||
@@ -34,7 +37,10 @@
|
||||
// Pure, no Meteor: tests/importAttachmentAuth.test.cjs.
|
||||
|
||||
const SOURCES = {
|
||||
jira: { url: true, username: true },
|
||||
// The username is optional on Server and Data Center: without one the
|
||||
// token is a personal access token, which Jira takes only as Bearer.
|
||||
// Cloud (*.atlassian.net) still needs the email.
|
||||
jira: { url: true, username: true, usernameOptional: true },
|
||||
deck: { url: true, username: true },
|
||||
openproject: { url: true, username: false },
|
||||
asana: { url: false, username: false, origin: 'https://app.asana.com' },
|
||||
@@ -71,17 +77,20 @@ function attachmentSignIn(source, auth) {
|
||||
if (!spec || !auth || !isAttachmentAuthShape(auth)) return null;
|
||||
const token = String(auth.token || '').trim();
|
||||
const username = String(auth.username || '').trim();
|
||||
if (!token || (spec.username && !username)) return null;
|
||||
if (!token || (spec.username && !spec.usernameOptional && !username)) return null;
|
||||
let origin = spec.origin;
|
||||
let base = spec.origin;
|
||||
if (spec.url) {
|
||||
origin = originOf(auth.url);
|
||||
if (!origin) return null;
|
||||
// Jira Cloud takes an API token only with its email (Basic); a token
|
||||
// without one is a Data Center personal access token, never Cloud's.
|
||||
if (spec.usernameOptional && !username && /\.atlassian\.net$/i.test(new URL(origin).hostname)) return null;
|
||||
base = String(auth.url).trim().replace(/\/+$/, '');
|
||||
}
|
||||
const basic = (user, password) => `Basic ${Buffer.from(`${user}:${password}`).toString('base64')}`;
|
||||
const headers = {
|
||||
jira: () => ({ Authorization: basic(username, token) }),
|
||||
jira: () => ({ Authorization: username ? basic(username, token) : `Bearer ${token}` }),
|
||||
deck: () => ({ Authorization: basic(username, token), 'OCS-APIRequest': 'true' }),
|
||||
openproject: () => ({ Authorization: basic('apikey', token) }),
|
||||
asana: () => ({ Authorization: `Bearer ${token}` }),
|
||||
@@ -146,7 +155,7 @@ function attachmentRequest(source, attachment, auth) {
|
||||
}
|
||||
if (!att.url) return { lost: 'not downloaded: no address' };
|
||||
// Jira serves no attachment without a sign-in.
|
||||
if (source === 'jira' && !signIn) return { lost: 'not downloaded: give the Jira address, email and API token on the import page' };
|
||||
if (source === 'jira' && !signIn) return { lost: 'not downloaded: give the Jira address and a token on the import page: an email and API token on Cloud, a username and password or a personal access token on Server and Data Center' };
|
||||
// Slack answers a file without a sign-in with its sign-in page, which is no
|
||||
// file - and a link that is not on Slack's file host gets no token.
|
||||
if (source === 'slack') {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
import { adfPlainText } from './externalParsers.js';
|
||||
import { jiraTextToMarkdown } from './jiraWikiMarkup.js';
|
||||
|
||||
// What a Jira Cloud REST v3 issue carries beyond the fields JiraCreator has
|
||||
// always mapped (summary, ADF description, status, labels, assignee, reporter,
|
||||
@@ -8,7 +9,8 @@ import { adfPlainText } from './externalParsers.js';
|
||||
// database so it can be tested in plain Node.
|
||||
//
|
||||
// tags priority, components and fix versions, as board labels
|
||||
// comments fields.comment.comments, ADF bodies as plain text
|
||||
// comments fields.comment.comments: ADF bodies as plain text, wiki
|
||||
// markup ones (Server, Data Center, API v2) as Markdown
|
||||
// parentKey fields.parent.key, linked when that issue is imported too
|
||||
// subtasks fields.subtasks that are NOT imported: a checklist instead
|
||||
// custom_fields customfield_NNNNN values, named from the search response's
|
||||
@@ -45,7 +47,7 @@ export function jiraIssueExtras(issue, { names = {}, importedKeys = new Set(), s
|
||||
const comments = ((fields.comment && Array.isArray(fields.comment.comments)) ? fields.comment.comments : [])
|
||||
.filter(Boolean)
|
||||
.map(c => ({
|
||||
text: adfPlainText(c.body),
|
||||
text: jiraTextToMarkdown(c.body, adfPlainText),
|
||||
author: c.author && (c.author.accountId || c.author.name || c.author.emailAddress),
|
||||
authorName: c.author && (c.author.displayName || c.author.name),
|
||||
date: c.created,
|
||||
|
||||
@@ -1,20 +1,36 @@
|
||||
// Extract the distinct assignees from a Jira export so the import "map members"
|
||||
// Extract the distinct people of a Jira export so the import "map members"
|
||||
// step can map each Jira user to a WeKan user. Shared: the page reads it from a
|
||||
// pasted document, the server (models/import.js) from an uploaded file.
|
||||
//
|
||||
// The assignee, and also the reporter, the creator and each comment's author:
|
||||
// a comment is written as its mapped author (models/lib/importedTaskPlan.js
|
||||
// importedComment), so an author who assigned nothing has to be offered too.
|
||||
// A person is keyed as JiraCreator looks them up - Cloud's accountId, Server's
|
||||
// and Data Center's username (`name`), or the email address.
|
||||
function jiraUserKey(user) {
|
||||
return user && (user.accountId || user.name || user.emailAddress);
|
||||
}
|
||||
|
||||
export function jiraGetMembersToMap(data) {
|
||||
const issues = Array.isArray(data) ? data : data.issues || [];
|
||||
const issues = Array.isArray(data) ? data : (data && data.issues) || [];
|
||||
const byId = {};
|
||||
issues.forEach(issue => {
|
||||
const assignee = issue.fields && issue.fields.assignee;
|
||||
if (!assignee) return;
|
||||
const id = assignee.accountId || assignee.name || assignee.emailAddress;
|
||||
const add = user => {
|
||||
const id = jiraUserKey(user);
|
||||
if (!id || byId[id]) return;
|
||||
byId[id] = {
|
||||
id,
|
||||
username: assignee.name || assignee.displayName || id,
|
||||
fullName: assignee.displayName || assignee.name || id,
|
||||
username: user.name || user.displayName || id,
|
||||
fullName: user.displayName || user.name || id,
|
||||
wekanId: null,
|
||||
};
|
||||
};
|
||||
issues.forEach(issue => {
|
||||
const fields = (issue && issue.fields) || {};
|
||||
add(fields.assignee);
|
||||
add(fields.reporter);
|
||||
add(fields.creator);
|
||||
const comments = fields.comment && Array.isArray(fields.comment.comments) ? fields.comment.comments : [];
|
||||
comments.forEach(comment => add(comment && comment.author));
|
||||
});
|
||||
return Object.values(byId);
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
'use strict';
|
||||
|
||||
// Jira's wiki markup as WeKan's Markdown.
|
||||
//
|
||||
// Jira Cloud's REST API v3 gives a description or a comment as an Atlassian
|
||||
// Document Format object (externalParsers.js adfPlainText). Jira Server and
|
||||
// Data Center - and API v2 on Cloud too - give it as a STRING of Jira wiki
|
||||
// markup, the "Text Formatting Notation" of Jira's own help. Kept as it was,
|
||||
// that string means something else in Markdown: a numbered list item `# step`
|
||||
// is a heading, `*bold*` is italic, and `{code}`, `[text|url]`, `h2.` and
|
||||
// `||table||` show as typed. This writes the same text as Markdown, with what
|
||||
// has no Markdown counterpart (colour, underline, panels) kept as its text.
|
||||
//
|
||||
// Inside {code} and {noformat} nothing is converted, and neither is
|
||||
// {{monospace}}, which become a fenced block and inline code.
|
||||
//
|
||||
// Pure, no Meteor: tests/jiraWikiMarkup.test.cjs.
|
||||
|
||||
const PLACEHOLDER = '\u0000';
|
||||
|
||||
function fence(body, lang) {
|
||||
const text = body.replace(/^\n+|\n+$/g, '');
|
||||
const longest = Math.max(2, ...(text.match(/`+/g) || []).map(run => run.length));
|
||||
const ticks = '`'.repeat(longest + 1);
|
||||
return `${ticks}${lang || ''}\n${text}\n${ticks}`;
|
||||
}
|
||||
|
||||
function inlineCode(body) {
|
||||
const ticks = (body.match(/`+/g) || []).reduce((n, run) => Math.max(n, run.length), 0) + 1;
|
||||
const tick = '`'.repeat(ticks);
|
||||
const pad = /^`|`$/.test(body) ? ' ' : '';
|
||||
return `${tick}${pad}${body}${pad}${tick}`;
|
||||
}
|
||||
|
||||
// Text effects inside one line. Jira's effect characters count only at a
|
||||
// word's edge: `*bold*`, not the * of 2*3*4; and not a Markdown `**`.
|
||||
function inline(line, keep) {
|
||||
let out = line;
|
||||
// [text|url], [url], [~username], [mailto:x], and an anchor [#name].
|
||||
out = out.replace(/\[([^\[\]|\n]*)\|([^\[\]\n]+)\]/g, (all, label, target) => {
|
||||
const url = target.split('|')[0].trim();
|
||||
if (!/^(https?:|mailto:|ftp:|#)/i.test(url)) return all;
|
||||
return keep(`[${label.trim() || url}](${url})`);
|
||||
});
|
||||
out = out.replace(/\[~([^\[\]\n]+)\]/g, (all, user) => `@${user.trim()}`);
|
||||
out = out.replace(/\[((?:https?|ftp):\/\/[^\[\]\s|]+|mailto:[^\[\]\s|]+)\]/gi, (all, url) => keep(`<${url.replace(/^mailto:/i, '')}>`));
|
||||
// !image.png! and !image.png|thumbnail! - the issue's attachment of that
|
||||
// name, or an address.
|
||||
out = out.replace(/!([^!\s|][^!|\n]*?)(?:\|[^!\n]*)?!/g, (all, src) => {
|
||||
const name = src.trim();
|
||||
if (!/\.(png|jpe?g|gif|bmp|webp|svg)$/i.test(name) && !/^https?:\/\//i.test(name)) return all;
|
||||
return keep(``);
|
||||
});
|
||||
// {color:red}text{color} and the other inline macros without a Markdown form.
|
||||
out = out.replace(/\{color(?::[^}]*)?\}/g, '');
|
||||
out = out.replace(/\{anchor:[^}]*\}/g, '');
|
||||
// ?? citation ??
|
||||
out = out.replace(/(^|[^\w?])\?\?(?=\S)(.+?)(?<=\S)\?\?(?![\w?])/g, (all, pre, body) => `${pre}<cite>${body}</cite>`);
|
||||
// *strong* -> **strong**
|
||||
out = out.replace(/(^|[^\w*])\*(?=[^\s*])([^*\n]*?[^\s*])\*(?![\w*])/g, (all, pre, body) => `${pre}**${body}**`);
|
||||
// -deleted- -> ~~deleted~~ (never the - of a list, a range or a word)
|
||||
out = out.replace(/(^|[\s(])-(?=[^\s-])([^-\n]*?[^\s-])-(?=$|[\s).,;:!?])/g, (all, pre, body) => `${pre}~~${body}~~`);
|
||||
// +inserted+ has no Markdown form: the text.
|
||||
out = out.replace(/(^|[^\w+])\+(?=[^\s+])([^+\n]*?[^\s+])\+(?![\w+])/g, (all, pre, body) => `${pre}${body}`);
|
||||
// ^superscript^ and ~subscript~ as HTML, as Markdown allows; Jira takes
|
||||
// them inside a word too (x^2^, H~2~O), but never across a space.
|
||||
out = out.replace(/(?<!\^)\^([^\s^]+)\^(?!\^)/g, (all, body) => `<sup>${body}</sup>`);
|
||||
out = out.replace(/(?<!~)~([^\s~]+)~(?!~)/g, (all, body) => `<sub>${body}</sub>`);
|
||||
// A forced line break.
|
||||
out = out.replace(/\s*\\\\\s*/g, ' \n');
|
||||
return out;
|
||||
}
|
||||
|
||||
function tableRow(line, keep) {
|
||||
const header = /^\s*\|\|/.test(line);
|
||||
const cells = line.trim().replace(/^\|\|?/, '').replace(/\|\|?$/, '').split(/\|\|?/)
|
||||
.map(cell => inline(cell.trim(), keep).replace(/\\/g, '\\\\').replace(/\|/g, '\\|'));
|
||||
return { header, cells };
|
||||
}
|
||||
|
||||
export function jiraWikiToMarkdown(value) {
|
||||
if (typeof value !== 'string' || !value) return '';
|
||||
const kept = [];
|
||||
const keep = text => {
|
||||
kept.push(text);
|
||||
return `${PLACEHOLDER}${kept.length - 1}${PLACEHOLDER}`;
|
||||
};
|
||||
let text = value.replace(/\r\n?/g, '\n');
|
||||
// Blocks whose content is literal, first.
|
||||
text = text.replace(/\{code(?::([^}]*))?\}([\s\S]*?)\{code\}/g, (all, opts, body) => {
|
||||
const lang = (opts || '').split('|').map(part => part.trim()).find(part => /^[A-Za-z0-9_+#.-]+$/.test(part) && !part.includes('='));
|
||||
return `\n${keep(fence(body, lang ? lang.toLowerCase() : ''))}\n`;
|
||||
});
|
||||
text = text.replace(/\{noformat(?::[^}]*)?\}([\s\S]*?)\{noformat\}/g, (all, body) => `\n${keep(fence(body, ''))}\n`);
|
||||
text = text.replace(/\{\{([^\n]*?)\}\}/g, (all, body) => keep(inlineCode(body)));
|
||||
// {quote} ... {quote} becomes a block quote; {panel}, {color} blocks keep
|
||||
// their text.
|
||||
text = text.replace(/\{quote\}([\s\S]*?)\{quote\}/g, (all, body) =>
|
||||
`\n${body.replace(/^\n+|\n+$/g, '').split('\n').map(line => `> ${line}`.trimEnd()).join('\n')}\n`);
|
||||
text = text.replace(/\{panel(?::[^}]*)?\}/g, '\n');
|
||||
|
||||
const out = [];
|
||||
let table = null;
|
||||
const flushTable = () => {
|
||||
if (!table) return;
|
||||
const width = Math.max(...table.map(row => row.cells.length));
|
||||
const pad = cells => [...cells, ...Array(width - cells.length).fill('')];
|
||||
const rows = table[0].header ? table : [{ header: true, cells: Array(width).fill('') }, ...table];
|
||||
out.push(`| ${pad(rows[0].cells).join(' | ')} |`);
|
||||
out.push(`|${Array(width).fill(' --- ').join('|')}|`);
|
||||
rows.slice(1).forEach(row => out.push(`| ${pad(row.cells).join(' | ')} |`));
|
||||
table = null;
|
||||
};
|
||||
for (const line of text.split('\n')) {
|
||||
if (/^\s*\|/.test(line) && /\|\s*$/.test(line)) {
|
||||
if (!table) table = [];
|
||||
table.push(tableRow(line, keep));
|
||||
continue;
|
||||
}
|
||||
flushTable();
|
||||
let match;
|
||||
if ((match = /^\s*h([1-6])\.\s+(.*)$/.exec(line))) {
|
||||
out.push(`${'#'.repeat(Number(match[1]))} ${inline(match[2], keep)}`);
|
||||
} else if ((match = /^\s*bq\.\s+(.*)$/.exec(line))) {
|
||||
out.push(`> ${inline(match[1], keep)}`);
|
||||
} else if ((match = /^\s*([*#-]+)\s+(.*)$/.exec(line)) && !/^-{2,}$/.test(match[1])
|
||||
&& (match[1].length === 1 || /^[*#]+$/.test(match[1]))) {
|
||||
// * bullet, # numbered, ** and #* nested: each level by the last mark.
|
||||
const marks = match[1];
|
||||
const indent = ' '.repeat(marks.length - 1);
|
||||
const bullet = marks[marks.length - 1] === '#' ? '1.' : '-';
|
||||
out.push(`${indent}${bullet} ${inline(match[2], keep)}`);
|
||||
} else if (/^\s*-{4,}\s*$/.test(line)) {
|
||||
out.push('---');
|
||||
} else {
|
||||
out.push(inline(line, keep));
|
||||
}
|
||||
}
|
||||
flushTable();
|
||||
return out.join('\n')
|
||||
.replace(new RegExp(`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`, 'g'), (all, i) => kept[Number(i)])
|
||||
.replace(/\n{3,}/g, '\n\n')
|
||||
.replace(/^\n+|\n+$/g, '');
|
||||
}
|
||||
|
||||
// A Jira description or comment body, whichever form it came in: ADF from
|
||||
// Cloud's API v3, wiki markup from Server, Data Center and API v2.
|
||||
export function jiraTextToMarkdown(value, adfPlainText) {
|
||||
if (typeof value === 'string') return jiraWikiToMarkdown(value);
|
||||
return adfPlainText(value);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ test('negative: incomplete or malformed sign-ins are no sign-in', () => {
|
||||
assert.equal(attachmentSignIn('openproject', { url: 'ftp://op.example.test', token: 't' }), null);
|
||||
assert.equal(attachmentSignIn('openproject', { url: 'https://op.example.test', token: ' ' }), null);
|
||||
assert.equal(attachmentSignIn('zenkit', { token: 't' }), null);
|
||||
assert.match(attachmentRequest('jira', { name: 'x', url: 'https://acme.atlassian.net/rest/api/3/attachment/content/1' }).lost, /Jira address, email and API token/);
|
||||
assert.match(attachmentRequest('jira', { name: 'x', url: 'https://acme.atlassian.net/rest/api/3/attachment/content/1' }).lost, /Jira address and a token on the import page: an email and API token on Cloud/);
|
||||
assert.match(attachmentRequest('openproject', { name: 'a', path: '/api/v3/attachments/1/content' }).lost, /sign-in on the import page/);
|
||||
assert.equal(isAttachmentAuthShape(undefined), true);
|
||||
assert.equal(isAttachmentAuthShape({ url: 'a', username: 'b', token: 'c' }), true);
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
'use strict';
|
||||
|
||||
// A Jira Server / Data Center export, as OpenProject's Jira Migrator reads
|
||||
// one (REST API v2: /rest/api/2/search?fields=*all&expand=changelog), imported
|
||||
// into WeKan:
|
||||
//
|
||||
// * a description and a comment are Jira WIKI MARKUP strings there, not
|
||||
// Cloud's ADF objects, and become Markdown (models/lib/jiraWikiMarkup.js):
|
||||
// kept as typed, `# step` was a heading, `*bold*` italic, and {code},
|
||||
// [text|url], h2. and ||tables|| showed as typed;
|
||||
// * people are keyed by their username (`name`), and the reporter, creator
|
||||
// and comment authors are offered for mapping, not only assignees;
|
||||
// * an attachment is downloaded with Basic USERNAME:PASSWORD, or - with no
|
||||
// username - a Data Center personal access token as Bearer.
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { pathToFileURL } = require('node:url');
|
||||
|
||||
const root = path.join(__dirname, '..');
|
||||
const load = rel => import(pathToFileURL(path.join(root, rel)).href);
|
||||
|
||||
(async () => {
|
||||
const { jiraWikiToMarkdown, jiraTextToMarkdown } = await load('models/lib/jiraWikiMarkup.js');
|
||||
const { adfPlainText } = await load('models/lib/externalParsers.js');
|
||||
const { jiraIssueExtras } = await load('models/lib/jiraIssueExtras.js');
|
||||
const { jiraGetMembersToMap } = await load('models/lib/jiraMembersMapper.js');
|
||||
const { attachmentSignIn, attachmentAuthFields } = require('../models/lib/importAttachmentAuth.js');
|
||||
const md = jiraWikiToMarkdown;
|
||||
|
||||
// --- Wiki markup -> Markdown ------------------------------------------------
|
||||
assert.equal(md('h1. Release plan'), '# Release plan');
|
||||
assert.equal(md('h3. Steps'), '### Steps');
|
||||
assert.equal(md('# first\n# second\n## nested'), '1. first\n1. second\n 1. nested');
|
||||
assert.equal(md('* one\n** two\n*# mixed'), '- one\n - two\n 1. mixed');
|
||||
assert.equal(md('- dash item'), '- dash item');
|
||||
assert.equal(md('This is *bold* and _italic_.'), 'This is **bold** and _italic_.');
|
||||
assert.equal(md('*a*'), '**a**');
|
||||
assert.equal(md('was -removed- now'), 'was ~~removed~~ now');
|
||||
assert.equal(md('+underlined+ text'), 'underlined text');
|
||||
assert.equal(md('x^2^ and H~2~O'), 'x<sup>2</sup> and H<sub>2</sub>O');
|
||||
assert.equal(md('Use {{npm ci}} here'), 'Use `npm ci` here');
|
||||
assert.equal(md('See [the docs|https://example.com/a] now'), 'See [the docs](https://example.com/a) now');
|
||||
assert.equal(md('Go to [https://example.com]'), 'Go to <https://example.com>');
|
||||
assert.equal(md('Ask [~jsmith] please'), 'Ask @jsmith please');
|
||||
assert.equal(md('!screenshot.png|thumbnail!'), '');
|
||||
assert.equal(md('{color:red}Warning{color} text'), 'Warning text');
|
||||
assert.equal(md('bq. A quote'), '> A quote');
|
||||
assert.equal(md('{quote}\nline one\nline two\n{quote}'), '> line one\n> line two');
|
||||
assert.equal(md('line one\\\\line two'), 'line one \nline two');
|
||||
assert.equal(md('above\n----\nbelow'), 'above\n---\nbelow');
|
||||
assert.equal(md('{code:java}\nint x = 1 * 2 * 3;\n# not a list\n{code}'), '```java\nint x = 1 * 2 * 3;\n# not a list\n```');
|
||||
assert.equal(md('{code:title=Main.java|borderStyle=solid}\nmain();\n{code}'), '```\nmain();\n```');
|
||||
assert.equal(md('{noformat}\n*raw* h1. text\n{noformat}'), '```\n*raw* h1. text\n```');
|
||||
assert.equal(md('||Name||Value||\n|a|1|\n|b|*2*|'), '| Name | Value |\n| --- | --- |\n| a | 1 |\n| b | **2** |');
|
||||
assert.equal(md('|C:\\temp\\|x|'), '| | |\n| --- | --- |\n| C:\\\\temp\\\\ | x |', 'a backslash in a cell cannot end it');
|
||||
assert.equal(md('|no|header|'), '| | |\n| --- | --- |\n| no | header |');
|
||||
assert.equal(md('{panel:title=Note}\nInside\n{panel}'), 'Inside');
|
||||
assert.equal(md('line\r\nnext'), 'line\nnext');
|
||||
|
||||
// Negative: what is not wiki markup is left as it is.
|
||||
assert.equal(md('2*3*4 = 24'), '2*3*4 = 24', 'a * inside a word is no bold');
|
||||
assert.equal(md('pages 10-20 and 30-40'), 'pages 10-20 and 30-40', 'a range is no deletion');
|
||||
assert.equal(md('a well-known re-run'), 'a well-known re-run');
|
||||
assert.equal(md('**already markdown**'), '**already markdown**');
|
||||
assert.equal(md('snake_case_name'), 'snake_case_name');
|
||||
assert.equal(md('cd ~/repos and ~/tmp'), 'cd ~/repos and ~/tmp', 'a home directory is no subscript');
|
||||
assert.equal(md('2^10 = 1024'), '2^10 = 1024', 'one ^ is no superscript');
|
||||
assert.equal(md('[not a link]'), '[not a link]');
|
||||
assert.equal(md('[x|javascript:alert(1)]'), '[x|javascript:alert(1)]', 'only web and mail addresses become links');
|
||||
assert.equal(md('{{a ` b}}'), '``a ` b``', 'inline code with a backtick in it');
|
||||
assert.equal(md('{code}\n```\n{code}'), '````\n```\n````', 'a fence longer than the code it holds');
|
||||
assert.equal(md('Price!: 5! no'), 'Price!: 5! no', 'two ! are no image');
|
||||
assert.equal(md(''), '');
|
||||
assert.equal(md(null), '');
|
||||
assert.equal(md(undefined), '');
|
||||
|
||||
// Cloud's ADF still goes through adfPlainText, unchanged.
|
||||
const adf = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: '*not bold* # here' }] }] };
|
||||
assert.equal(jiraTextToMarkdown(adf, adfPlainText), '*not bold* # here');
|
||||
assert.equal(jiraTextToMarkdown('*bold*', adfPlainText), '**bold**');
|
||||
|
||||
// --- A Jira Server v2 issue --------------------------------------------------
|
||||
const server = name => ({ self: `https://jira.example.org/rest/api/2/user?username=${name}`, name, key: `JIRAUSER1${name.length}`, displayName: name.toUpperCase(), emailAddress: `${name}@example.org` });
|
||||
const issue = {
|
||||
key: 'OPS-7',
|
||||
fields: {
|
||||
summary: 'Rotate certificates',
|
||||
description: 'h2. Steps\n# Renew\n# Deploy *today*',
|
||||
reporter: server('rita'),
|
||||
creator: server('carl'),
|
||||
assignee: server('anna'),
|
||||
comment: { comments: [
|
||||
{ author: server('carl'), body: 'Done with {{certbot}}, see [log|https://ci.example.org/7]', created: '2026-11-20T10:00:00.000+0000' },
|
||||
{ author: server('wendy'), body: 'Thanks!', created: '2026-11-20T11:00:00.000+0000' },
|
||||
] },
|
||||
attachment: [{ filename: 'cert.png', content: 'https://jira.example.org/secure/attachment/10100/cert.png' }],
|
||||
},
|
||||
};
|
||||
const extras = jiraIssueExtras(issue, { importedKeys: new Set(['OPS-7']) });
|
||||
assert.equal(extras.comments[0].text, 'Done with `certbot`, see [log](https://ci.example.org/7)');
|
||||
assert.equal(extras.comments[0].author, 'carl', 'a Server user is keyed by username');
|
||||
assert.deepEqual(extras.attachments, [{ name: 'cert.png', url: 'https://jira.example.org/secure/attachment/10100/cert.png' }]);
|
||||
assert.deepEqual(extras.unsupported, []);
|
||||
|
||||
const people = jiraGetMembersToMap({ issues: [issue, { fields: { assignee: server('anna') } }, { fields: {} }, null] });
|
||||
assert.deepEqual(people.map(p => p.id), ['anna', 'rita', 'carl', 'wendy'], 'assignee, reporter, creator and comment authors, once each');
|
||||
assert.deepEqual(people[3], { id: 'wendy', username: 'wendy', fullName: 'WENDY', wekanId: null });
|
||||
// Cloud keeps the account id as the key.
|
||||
assert.deepEqual(jiraGetMembersToMap({ issues: [{ fields: { reporter: { accountId: 'a1', displayName: 'Ann' } } }] }).map(p => p.id), ['a1']);
|
||||
assert.deepEqual(jiraGetMembersToMap(null), []);
|
||||
|
||||
// --- Signing in for the attachment files ------------------------------------
|
||||
const basic = (u, p) => `Basic ${Buffer.from(`${u}:${p}`).toString('base64')}`;
|
||||
const url = 'https://jira.example.org';
|
||||
assert.equal(attachmentSignIn('jira', { url, username: 'anna', token: 'pw' }).headers.Authorization, basic('anna', 'pw'));
|
||||
assert.equal(attachmentSignIn('jira', { url, username: 'ann@example.org', token: 'api' }).headers.Authorization, basic('ann@example.org', 'api'));
|
||||
assert.equal(attachmentSignIn('jira', { url, token: 'NjQ2MDk1' }).headers.Authorization, 'Bearer NjQ2MDk1', 'a Data Center personal access token');
|
||||
assert.deepEqual(attachmentAuthFields('jira'), { url: true, username: true }, 'the page still asks for the username');
|
||||
// Negative: still no sign-in without a token or an address, and the other
|
||||
// sources that need a username still need one.
|
||||
assert.equal(attachmentSignIn('jira', { url, username: 'anna' }), null);
|
||||
assert.equal(attachmentSignIn('jira', { token: 'x' }), null);
|
||||
assert.equal(attachmentSignIn('deck', { url, token: 'x' }), null);
|
||||
assert.equal(attachmentSignIn('jira', { url: 'https://acme.atlassian.net', token: 'x' }), null, 'Cloud still needs the email');
|
||||
assert.equal(attachmentSignIn('jira', { url: 'https://ACME.Atlassian.NET', token: 'x' }), null);
|
||||
|
||||
// --- Everywhere: no Jira text reaches a card unconverted ----------------------
|
||||
for (const rel of ['models/jiraCreator.js', 'models/lib/jiraIssueExtras.js']) {
|
||||
const src = fs.readFileSync(path.join(root, rel), 'utf8');
|
||||
assert.doesNotMatch(src, /adfPlainText\((?:fields\.description|c\.body|comment\.body)\)/, `${rel}: a body through adfPlainText alone`);
|
||||
}
|
||||
assert.match(fs.readFileSync(path.join(root, 'models/jiraCreator.js'), 'utf8'), /description: jiraTextToMarkdown\(fields\.description, adfPlainText\)/);
|
||||
|
||||
console.log('jiraServerImport: ok');
|
||||
})().catch(error => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
// A Jira Server / Data Center export (REST API v2, as OpenProject's Jira
|
||||
// Migrator reads one): descriptions and comments are Jira wiki markup, and
|
||||
// people are keyed by username. The import page offers every person of the
|
||||
// file for mapping - the reporter and comment authors too - and the card shows
|
||||
// the markup as formatted text, not as typed. Cloud's ADF is unchanged.
|
||||
|
||||
const { test, expect } = require('../fixtures');
|
||||
const db = require('../helpers/db');
|
||||
const { navigateInApp } = require('../helpers/auth');
|
||||
const { waitForImportedBoard } = require('../helpers/import');
|
||||
const CardPage = require('../pages/CardPage');
|
||||
|
||||
const person = name => ({ name, key: `JIRAUSER${name.length}0`, displayName: `${name[0].toUpperCase()}${name.slice(1)} Example`, emailAddress: `${name}@jira.invalid` });
|
||||
|
||||
test('a Jira Server export: wiki markup becomes formatted text and every person is offered for mapping', async ({ loggedInPage: page }) => {
|
||||
const name = `Jira Server ${db.uniqueSuffix()}`;
|
||||
const source = { startAt: 0, maxResults: 50, total: 2, board: { name }, issues: [
|
||||
{ key: 'OPS-7', fields: {
|
||||
summary: 'Rotate certificates', status: { name: 'In Progress' },
|
||||
description: 'h2. Steps\n# Renew\n# Deploy *today*\n\nRun {{certbot renew}} or see [the runbook|https://wiki.invalid/runbook].',
|
||||
assignee: person('anna'), reporter: person('rita'), creator: person('rita'),
|
||||
comment: { comments: [
|
||||
{ author: person('wendy'), body: 'Done with {{certbot}}, *thanks*', created: '2026-11-20T10:00:00.000+0000' },
|
||||
] },
|
||||
} },
|
||||
{ key: 'OPS-8', fields: {
|
||||
summary: 'Cloud issue', status: { name: 'In Progress' },
|
||||
description: { type: 'doc', version: 1, content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Literal *stars* stay' }] }] },
|
||||
} },
|
||||
] };
|
||||
let boardId;
|
||||
try {
|
||||
await navigateInApp(page, '/import/jira');
|
||||
await page.locator('#import-textarea').fill(JSON.stringify(source));
|
||||
await page.locator('input.primary.wide[type="submit"]').click();
|
||||
|
||||
// The mapping step: the assignee, the reporter and the comment's author.
|
||||
const people = page.locator('.mapping-list .js-select-member');
|
||||
await expect(people).toHaveCount(3, { timeout: 30_000 });
|
||||
await expect(page.locator('.mapping-list .username')).toHaveText(['(anna)', '(rita)', '(wendy)']);
|
||||
await page.locator('.js-import-skip-mapping').click();
|
||||
await waitForImportedBoard(page);
|
||||
boardId = page.url().match(/\/b\/([^/]+)/)[1];
|
||||
|
||||
const cards = db.find('cards', { boardId });
|
||||
const server = cards.find(card => card.title.includes('OPS-7'));
|
||||
const cloud = cards.find(card => card.title.includes('OPS-8'));
|
||||
expect(server.description).toBe('## Steps\n1. Renew\n1. Deploy **today**\n\nRun `certbot renew` or see [the runbook](https://wiki.invalid/runbook).');
|
||||
expect(server.requestedBy).toBe('Rita Example');
|
||||
// Negative: Cloud's ADF is plain text, its stars are no markup.
|
||||
expect(cloud.description).toBe('Literal *stars* stay');
|
||||
const comment = db.findOne('card_comments', { cardId: server._id });
|
||||
expect(comment.text).toBe('Wendy Example: Done with `certbot`, **thanks**');
|
||||
|
||||
const board = db.findOne('boards', { _id: boardId });
|
||||
await navigateInApp(page, `/b/${boardId}/${board.slug}/${server._id}`);
|
||||
const cp = new CardPage(page);
|
||||
await cp.waitForOpen();
|
||||
await expect(cp.root.locator('h2').filter({ hasText: 'Steps' })).toBeVisible();
|
||||
await expect(cp.root.locator('ol li')).toHaveText(['Renew', 'Deploy today']);
|
||||
await expect(cp.root.locator('strong').filter({ hasText: 'today' })).toBeVisible();
|
||||
await expect(cp.root.locator('code').filter({ hasText: 'certbot renew' })).toBeVisible();
|
||||
await expect(cp.root.locator('a[href="https://wiki.invalid/runbook"]')).toHaveText('the runbook');
|
||||
// Negative: none of the markup is shown as typed.
|
||||
await expect(cp.root.getByText('h2. Steps')).toHaveCount(0);
|
||||
await expect(cp.root.getByText('{{certbot renew}}')).toHaveCount(0);
|
||||
} finally {
|
||||
if (boardId) db.cleanup({ boardIds: [boardId] });
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user