mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
GitLab's Issues API v4 gives an issue a health_status (on_track, needs_attention, at_risk) and an incident a severity, and the import dropped both. They are now "health:..." and "severity:..." labels, as the issue type is a "type:..." one; an UNKNOWN severity is none. tests/gitlabImport.test.cjs: both labels, and none for a missing health or an unknown severity. Thanks to xet7 !
126 lines
6.7 KiB
JavaScript
126 lines
6.7 KiB
JavaScript
'use strict';
|
|
|
|
// GitLab issue import and Sync source (models/lib/externalParsers.js), #2698.
|
|
// Run: node tests/gitlabImport.test.cjs
|
|
//
|
|
// parseGitlab used to keep only title, description, state, due date, the
|
|
// first assignee, author and labels, and silently dropped the rest of an
|
|
// Issues API v4 issue. It now meets docs/Features/Board-Sidebar/Board-Settings/Import-Export/Format-
|
|
// Coverage.md like the GitHub adapter: every field either lands on the card,
|
|
// becomes a tag or custom field, or is named in the `unsupported` report.
|
|
|
|
const assert = require('assert');
|
|
|
|
async function main() {
|
|
const { parseGitlab } = await import('../models/lib/externalParsers.js');
|
|
const plan = await import('../models/lib/importedTaskPlan.js');
|
|
let passed = 0;
|
|
const test = (name, fn) => { fn(); passed += 1; console.log(' ok -', name); };
|
|
|
|
const issues = [
|
|
{
|
|
id: 901, iid: 7, title: 'Crash on save', description: 'Steps', state: 'opened',
|
|
labels: [{ name: 'bug', color: '#ff0000' }, 'backend'],
|
|
assignee: { username: 'alice' }, assignees: [{ username: 'alice' }, { username: 'bob' }],
|
|
author: { username: 'carol', name: 'Carol' },
|
|
milestone: { title: 'v2.0', due_date: '2026-10-01' }, iteration: { title: 'Sprint 4' },
|
|
weight: 3, confidential: true, issue_type: 'incident',
|
|
time_stats: { time_estimate: 7200, total_time_spent: 5400 },
|
|
task_completion_status: { count: 4, completed_count: 1 },
|
|
created_at: '2026-01-02T03:04:05Z',
|
|
references: { full: 'group/project#7' }, web_url: 'https://gitlab.example/group/project/-/issues/7',
|
|
notes: [
|
|
{ body: 'I can reproduce', author: { username: 'dave', name: 'Dave' }, created_at: '2026-01-03T00:00:00Z' },
|
|
{ body: 'added ~bug label', system: true, author: { username: 'gitlab' } },
|
|
],
|
|
links: [{ iid: 8, link_type: 'blocks' }, { iid: 99, link_type: 'relates_to' }],
|
|
epic: { id: 1 },
|
|
},
|
|
{ id: 902, iid: 8, title: 'Closed one', state: 'closed', closed_at: '2026-02-01T00:00:00Z', user_notes_count: 2 },
|
|
];
|
|
const result = parseGitlab(issues);
|
|
const [open, closed] = result.tasks;
|
|
|
|
test('title, state, iid key and the source link', () => {
|
|
assert.equal(open.externalId, '7');
|
|
assert.equal(open.ref, '7');
|
|
assert.equal(open.column_name, 'Open');
|
|
assert.equal(closed.column_name, 'Closed');
|
|
assert.match(open.description, /^Steps\n\nSource: group\/project#7 https:\/\/gitlab\.example\/group\/project\/-\/issues\/7$/);
|
|
});
|
|
|
|
test('every assignee, the author and the dates', () => {
|
|
assert.equal(open.owner_username, 'alice');
|
|
assert.deepEqual(open.assignees, ['bob'], 'the second assignee is no longer only a tag');
|
|
assert.equal(open.requested_by, 'carol');
|
|
assert.equal(open.date_due, '2026-10-01');
|
|
assert.equal(open.date_creation, '2026-01-02T03:04:05Z');
|
|
assert.equal(open.date_end, undefined, 'an open issue has no end');
|
|
assert.equal(closed.date_end, '2026-02-01T00:00:00Z');
|
|
});
|
|
|
|
test('labels with details, milestone, iteration, type and confidentiality become tags', () => {
|
|
assert.deepEqual(open.tags, ['bug', 'backend', 'milestone:v2.0', 'iteration:Sprint 4', 'type:incident', 'confidential']);
|
|
assert.ok(result.warnings.some(w => /confidential/.test(w)), 'confidential content is warned about');
|
|
});
|
|
|
|
test('time, weight and task completion', () => {
|
|
assert.equal(open.spent_hours, 1.5);
|
|
assert.deepEqual(open.custom_fields, { Weight: 3, 'Time estimate (hours)': 2, Tasks: '1/4' });
|
|
});
|
|
|
|
test('comments exclude system notes; links become dependencies', () => {
|
|
assert.deepEqual(open.comments, [{ text: 'I can reproduce', author: 'dave', authorName: 'Dave', date: '2026-01-03T00:00:00Z' }]);
|
|
assert.deepEqual(open.dependencies, [{ ref: '8', type: 'blocks' }, { ref: '99', type: 'related-to' }]);
|
|
});
|
|
|
|
test('what has no place is reported, not dropped (negative)', () => {
|
|
assert.ok(result.unsupported.some(u => u.path === '/0/epic'));
|
|
assert.ok(result.unsupported.some(u => u.path === '/1/user_notes_count' && /2 comment/.test(u.reason)),
|
|
'comments that exist upstream but were not exported are reported');
|
|
assert.ok(!result.unsupported.some(u => u.path === '/0/user_notes_count'), 'embedded notes are not reported missing');
|
|
});
|
|
|
|
test('the planner puts them on the card, and a link outside the import is reported', () => {
|
|
const planned = plan.planImportedTask(open, { members: { alice: 'u-alice', bob: 'u-bob' } });
|
|
assert.deepEqual(planned.memberIds, ['u-alice', 'u-bob']);
|
|
assert.equal(planned.card.spentTime, 1.5);
|
|
assert.equal(planned.card.createdAt.toISOString(), '2026-01-02T03:04:05.000Z');
|
|
assert.equal(planned.comments.length, 1);
|
|
const links = plan.planImportedLinks(result.tasks);
|
|
assert.deepEqual(links.dependencies, [{ index: 0, deps: [{ target: 1, type: 'blocks' }] }]);
|
|
assert.ok(links.unsupported.some(u => /not part of this import/.test(u.reason)), '#99 is reported');
|
|
const fields = plan.planImportedCustomFields(result.tasks);
|
|
assert.ok(fields.fields.some(f => f.name === 'Weight'));
|
|
});
|
|
|
|
test('a minimal or legacy issue still imports', () => {
|
|
const minimal = parseGitlab({ issues: [{ id: 5, title: 'Only an id', state: 'opened', labels: ['x'] }] });
|
|
assert.equal(minimal.tasks[0].externalId, '5');
|
|
assert.equal(minimal.tasks[0].description, '');
|
|
assert.deepEqual(minimal.tasks[0].tags, ['x']);
|
|
assert.deepEqual(minimal.unsupported, []);
|
|
assert.equal(parseGitlab([]).tasks.length, 0);
|
|
});
|
|
|
|
const { formatters } = await import('../models/lib/externalExportFormatters.js');
|
|
test('the export writes spent hours as time_stats seconds, and they come back', () => {
|
|
const out = formatters.gitlab({ items: [{ title: 'T', listTitle: 'Open', labels: [], spentTime: 2.25 },
|
|
{ title: 'U', listTitle: 'Open', labels: [] }] });
|
|
assert.deepStrictEqual(out[0].time_stats, { total_time_spent: 8100 });
|
|
assert.strictEqual(out[1].time_stats, undefined, 'negative: none when nothing was spent');
|
|
assert.strictEqual(parseGitlab(out).tasks[0].spent_hours, 2.25);
|
|
});
|
|
|
|
test('health status and an incident\'s severity are labels; UNKNOWN severity is none', () => {
|
|
const out = parseGitlab([{ iid: 1, title: 'A', state: 'opened', health_status: 'needs_attention', severity: 'HIGH', issue_type: 'incident' },
|
|
{ iid: 2, title: 'B', state: 'opened', severity: 'UNKNOWN', health_status: null }]);
|
|
assert.deepStrictEqual(out.tasks[0].tags, ['type:incident', 'health:needs attention', 'severity:high']);
|
|
assert.deepStrictEqual(out.tasks[1].tags, [], 'negative: no health, and an unknown severity, are no labels');
|
|
});
|
|
|
|
console.log(`\ngitlabImport: ${passed} tests passed`);
|
|
}
|
|
|
|
main().catch(error => { console.error(error); process.exitCode = 1; });
|