Files
wekan/models/lib/externalParsers.js
T
Lauri Ojansivu 050df89f06 Requested By and Assigned By: a + to set them, and they survive a round
trip.

Both fields were set by clicking the word "Add". They have the round + that
Members and Assignee use now, opening the same editor the text opens - the
same class, so it is the same button and not a second one that looks like
it.

Checking where else they live turned up a ROUND TRIP THAT LOST THEM, which
is the worst shape this bug takes: the export looks complete and the import
reports success. They were exported by the card PDF, the card Excel and the
board CSV, and imported by nothing - a card exported and imported back had
forgotten who asked for it and who assigned it. models/wekanCreator.js and
the per-menu scoped importer both set them now.

The board's streaming Excel TABLE exported neither, so it gained two
columns: header and value in the same commit, because a header without its
value shifts every column after it.

From other trackers, where the idea has another name: Jira's REPORTER is who
asked for the work, and an issue's AUTHOR on GitHub, Gitea, Forgejo and
GitLab is the same thing. Both arrive as Requested By, as free text, so they
survive an import from a tracker nobody on this board has an account on. A
source with no such field - Trello, CSV - gains nothing, and a negative test
says so.

Also two things the grouping left crooked, both visible on an opened card:

- Members, Assignee and Creator were each a full-width row, so the last two
  fell below the first. The class that made a FIELD full width predates the
  groups; the GROUP is the full-width row now, and its fields share it.
- A field whose title the group header had taken over put its + on the first
  line, level with its neighbours' titles. Every field in a group keeps its
  own title again: the group header names the family and folds it, the
  field's title names the field, and the + starts on the line below it.

tests/requestedAssignedByRoundTrip.test.cjs walks the whole way round - the
card, Card Settings, four exports, three importers - because this was found
by looking rather than by anything failing.

Thanks to xet7 !
2026-08-14 03:28:21 +03:00

201 lines
8.0 KiB
JavaScript

// Parsers that normalize exports/API responses from other tools into the common
// "Kanboard shape" { board, columns, swimlanes, tasks } that KanboardCreator
// consumes. Each is best-effort and tolerant of missing fields.
//
// A normalized task: { title, description, column_name, swimlane_name,
// date_due, owner_username, tags: [string] }.
function uniq(arr) {
return [...new Set(arr.filter(Boolean))];
}
// --- NextCloud Deck ---------------------------------------------------------
// Accepts a Deck board with stacks (each stack carries its cards), e.g. the
// shape returned by the Deck REST API (GET /boards/{id} + /stacks).
export function parseNextcloudDeck(data) {
const board = data.board || data;
const stacks = board.stacks || data.stacks || [];
const tasks = [];
stacks.forEach(stack => {
(stack.cards || []).forEach(card => {
tasks.push({
title: card.title || 'Imported card',
description: card.description || '',
column_name: stack.title,
swimlane_name: 'Default',
date_due: card.duedate || card.dueDate,
owner_username:
(card.assignedUsers &&
card.assignedUsers[0] &&
(card.assignedUsers[0].participant
? card.assignedUsers[0].participant.uid
: card.assignedUsers[0].uid)) ||
card.owner,
tags: (card.labels || []).map(l => (typeof l === 'string' ? l : l.title)),
});
});
});
return {
board: { name: board.title || 'Imported NextCloud Deck board' },
columns: stacks.map(s => ({ title: s.title })),
swimlanes: [{ name: 'Default' }],
tasks,
};
}
// --- OpenProject ------------------------------------------------------------
// Accepts a work-packages collection (GET /api/v3/work_packages), i.e.
// { _embedded: { elements: [ { subject, description:{raw}, dueDate,
// _links:{ status:{title}, assignee:{title}, type:{title} } } ] } }.
export function parseOpenProject(data) {
const elements =
(data._embedded && data._embedded.elements) ||
data.elements ||
(Array.isArray(data) ? data : []);
const tasks = elements.map(wp => {
const links = wp._links || {};
return {
title: wp.subject || wp.name || 'Imported work package',
description: (wp.description && (wp.description.raw || wp.description.html)) || '',
column_name: (links.status && links.status.title) || wp.status || 'Imported',
swimlane_name: 'Default',
date_due: wp.dueDate || wp.due_date,
owner_username: links.assignee && links.assignee.title,
tags: [links.type && links.type.title].filter(Boolean),
};
});
return {
board: { name: (data._links && data._links.self && data._links.self.title) || 'Imported OpenProject' },
columns: uniq(tasks.map(t => t.column_name)).map(title => ({ title })),
swimlanes: [{ name: 'Default' }],
tasks,
};
}
// --- Shared issue-tracker mapping (GitHub / Gitea / Forgejo) -----------------
// Accepts an array of issues (GET /repos/{o}/{r}/issues). Pull requests are
// skipped. Issues are grouped into Open / Closed lists.
function parseIssuesArray(data, system) {
const issues = Array.isArray(data) ? data : data.issues || [];
const tasks = issues
.filter(issue => !issue.pull_request)
.map(issue => ({
title: issue.title || 'Imported issue',
description: issue.body || issue.description || '',
column_name: issue.state === 'closed' ? 'Closed' : 'Open',
swimlane_name: 'Default',
date_due: (issue.milestone && (issue.milestone.due_on || issue.milestone.due_date)) || issue.due_date,
owner_username:
(issue.assignee && (issue.assignee.login || issue.assignee.username)) || undefined,
// Who OPENED the issue is who asked for the work - WeKan's "Requested
// By", as opposed to the assignee who does it. Free text, so it survives
// an import from a tracker nobody on this board has an account on.
requested_by: (issue.user && (issue.user.login || issue.user.name))
|| (issue.author && (issue.author.login || issue.author.username || issue.author.name))
|| undefined,
tags: (issue.labels || []).map(l => (typeof l === 'string' ? l : l.name)),
}));
return {
board: { name: `Imported ${system} issues` },
columns: [{ title: 'Open' }, { title: 'Closed' }],
swimlanes: [{ name: 'Default' }],
tasks,
};
}
export function parseGithub(data) {
return parseIssuesArray(data, 'GitHub');
}
// Gitea and Forgejo share the same issue API shape.
export function parseGitea(data) {
return parseIssuesArray(data, 'Gitea/Forgejo');
}
// --- GitLab -----------------------------------------------------------------
// Accepts an array of issues (GET /projects/{id}/issues). GitLab uses
// state "opened"/"closed", string labels, and assignee.username.
export function parseGitlab(data) {
const issues = Array.isArray(data) ? data : data.issues || [];
const tasks = issues.map(issue => ({
title: issue.title || 'Imported issue',
description: issue.description || '',
column_name: issue.state === 'closed' ? 'Closed' : 'Open',
swimlane_name: 'Default',
date_due: issue.due_date || (issue.milestone && issue.milestone.due_date),
owner_username: issue.assignee && issue.assignee.username,
requested_by: issue.author && (issue.author.username || issue.author.name),
tags: (issue.labels || []).map(l => (typeof l === 'string' ? l : l.name)),
}));
return {
board: { name: 'Imported GitLab issues' },
columns: [{ title: 'Open' }, { title: 'Closed' }],
swimlanes: [{ name: 'Default' }],
tasks,
};
}
// --- Asana ----------------------------------------------------------------
// Accepts an Asana tasks export { data: [ { name, notes, completed, due_on,
// memberships:[{section:{name}}], tags:[{name}], assignee:{name} } ] }.
export function parseAsana(data) {
const items = Array.isArray(data) ? data : (data.data || []);
const tasks = items.map(t => {
const section =
(t.memberships && t.memberships[0] && t.memberships[0].section &&
t.memberships[0].section.name) ||
(t.completed ? 'Done' : 'In Progress');
return {
title: t.name || 'Imported task',
description: t.notes || '',
column_name: section,
swimlane_name: 'Default',
date_due: t.due_on || t.due_at,
owner_username: t.assignee && (t.assignee.email || t.assignee.name),
tags: (t.tags || []).map(tag => (typeof tag === 'string' ? tag : tag.name)),
};
});
return {
board: { name: (data.project && data.project.name) || 'Imported Asana project' },
columns: uniq(tasks.map(t => t.column_name)).map(title => ({ title })),
swimlanes: [{ name: 'Default' }],
tasks,
};
}
// --- ZenKit ----------------------------------------------------------------
// Accepts a ZenKit-style export { title, stages:[{name}],
// items:[{title, description, stage_name, due, tags:[string]}] }.
export function parseZenkit(data) {
const items = Array.isArray(data) ? data : (data.items || []);
const stages = data.stages || [];
const tasks = items.map(t => ({
title: t.title || t.name || 'Imported item',
description: t.description || t.notes || '',
column_name: t.stage_name || t.stageName || t.list || 'Inbox',
swimlane_name: 'Default',
date_due: t.due || t.dueDate || t.due_date,
owner_username: t.assignee && (t.assignee.email || t.assignee.name),
tags: Array.isArray(t.tags) ? t.tags.map(tag => (typeof tag === 'string' ? tag : tag.name)) : [],
}));
const derivedColumns = uniq(tasks.map(t => t.column_name)).map(title => ({ title }));
return {
board: { name: data.title || data.name || 'Imported ZenKit list' },
columns: stages.length ? stages.map(s => ({ title: s.name || s.title })) : derivedColumns,
swimlanes: [{ name: 'Default' }],
tasks,
};
}
// Map an import source name to its parser (forgejo reuses the Gitea parser).
export const EXTERNAL_PARSERS = {
deck: parseNextcloudDeck,
openproject: parseOpenProject,
github: parseGithub,
gitlab: parseGitlab,
gitea: parseGitea,
forgejo: parseGitea,
asana: parseAsana,
zenkit: parseZenkit,
};