Files
wekan/tests/githubImport.test.cjs
T
Lauri Ojansivu 594867bab7 Import Kanboard task links as parent cards and dependencies, and GitHub comments as card comments.
Kanboard task links were only reported as losses. They now become WeKan
data: "is a child of" and "is a parent of" make the parent card, and blocks,
is blocked by, duplicates, is duplicated by, fixes, is fixed by and relates
to make dependencies of the matching type; the milestone pair becomes
related-to and is reported. Kanboard stores each link from both tasks, so
the two rows of one link become one parent link or one dependency. Rows from
getAllTaskLinks, getTaskLinkById and links grouped by label are read; an
unknown label, a link to a task not in the file and a second parent are
reported. The Kanboard export writes parents and dependencies back as task
links from both ends, so the file round-trips. The docs no longer claim typed
custom fields for Kanboard, which has none.

GitHub, Gitea and Forgejo issues put their embedded comments into the card
description; each now becomes a card comment with its author and date, and
the description is left as the issue wrote it. A comment without text, and
comments counted on the issue but not embedded, are reported.

The Jira instruction's endpoint literal is the current search
(GET /rest/api/3/search/jql) in every locale too, as code literals are copied
from English; the translation suites that pinned the old one follow.

Thanks to xet7 !
2026-10-09 12:27:59 +03:00

111 lines
4.2 KiB
JavaScript

'use strict';
// GitHub/Gitea/Forgejo issue import (models/lib/externalParsers.js).
// Run: node tests/githubImport.test.cjs
//
// The parser normalizes a GitHub Issues REST API v3 page (or several pages
// concatenated - completing pagination is the API client's job, not this
// parser's) into the Kanboard shape KanboardCreator consumes. Fields with no
// place in that shape (a second assignee, a state reason, an issue number)
// used to be silently dropped; this pins that they now survive either as a
// tag or as an entry in the `unsupported` loss report, per
// docs/Features/ImportExport/Format-Coverage.md's `{ normalized, warnings,
// unsupported }` contract.
const assert = require('assert');
async function main() {
const { parseGithub, parseGitea } = await import('../models/lib/externalParsers.js');
const issues = [
{
number: 42,
title: 'Bug: crash on save',
body: 'Steps to repro...',
state: 'open',
labels: [{ name: 'bug' }],
assignee: { login: 'alice' },
assignees: [{ login: 'alice' }, { login: 'bob' }],
user: { login: 'carol' },
milestone: { title: 'v2.0', due_on: '2026-10-01' },
comments: 3,
html_url: 'https://github.com/o/r/issues/42',
},
{ number: 43, title: 'A pull request, not an issue', pull_request: {}, state: 'open' },
{
number: 44,
title: 'Closed with a reason',
state: 'closed',
state_reason: 'not_planned',
comments_data: [{ user: { login: 'dave' }, body: 'wontfix' }],
},
];
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
console.log('githubImport:');
const out = parseGithub(issues);
test('pull requests are filtered out of the issue list', () => {
assert.strictEqual(out.tasks.length, 2);
assert.ok(out.tasks.every(t => t.title !== 'A pull request, not an issue'));
});
test('open/closed state becomes the column', () => {
assert.strictEqual(out.tasks[0].column_name, 'Open');
assert.strictEqual(out.tasks[1].column_name, 'Closed');
});
test('the issue author is Requested By, the assignee is the Owner', () => {
assert.strictEqual(out.tasks[0].requested_by, 'carol');
assert.strictEqual(out.tasks[0].owner_username, 'alice');
});
test('a milestone title is kept as a tag, not just its due date', () => {
assert.strictEqual(out.tasks[0].date_due, '2026-10-01');
assert.ok(out.tasks[0].tags.includes('milestone:v2.0'));
});
test('a second assignee is kept as a tag and reported as unsupported', () => {
assert.ok(out.tasks[0].tags.includes('assignee:bob'));
assert.ok(out.unsupported.some(u => u.path === '/0/assignees'));
});
test('the source issue number and URL are appended to the description', () => {
assert.match(out.tasks[0].description, /Source: #42 https:\/\/github\.com\/o\/r\/issues\/42/);
});
test('comments not embedded in the export are reported, not silently dropped', () => {
assert.ok(out.unsupported.some(u => u.path === '/0/comments' && /3 comment/.test(u.reason)));
});
test('comments that ARE embedded become card comments, not description text', () => {
assert.deepStrictEqual(out.tasks[1].comments, [{ text: 'wontfix', author: 'dave' }]);
assert.doesNotMatch(out.tasks[1].description, /wontfix|Comments:/);
});
test('a non-"completed" state reason is kept as a tag', () => {
assert.ok(out.tasks[1].tags.includes('state_reason:not_planned'));
});
test('several pages concatenated into one array are all imported', () => {
const page1 = [{ number: 1, title: 'first', state: 'open' }];
const page2 = [{ number: 2, title: 'second', state: 'open' }];
const merged = parseGithub([...page1, ...page2]);
assert.strictEqual(merged.tasks.length, 2);
});
test('Gitea/Forgejo share the same parser and the same loss reporting', () => {
const geteaOut = parseGitea(issues);
assert.deepStrictEqual(geteaOut.tasks.map(t => t.title), out.tasks.map(t => t.title));
assert.strictEqual(geteaOut.board.name, 'Imported Gitea/Forgejo issues');
assert.ok(geteaOut.unsupported.length > 0);
});
console.log(`\ngithubImport: ${passed} tests passed`);
}
main().catch(e => { console.error(e); process.exit(1); });