mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 17:45:18 -05:00
Version Control shows the board as a GitHub or Gitea issue tracker in the board's own theme: cards are issues (open, or closed when archived, in a Closed or Done list, or closed upstream), the board's labels are labels, labels with a due date and the importers' milestone: labels are milestones, comments are the conversation and attachments are the files. The issue list takes GitHub's search words (is:open, label:, milestone:, author:, assignee:@me, no:label, sort:). New issue, Close and Reopen write through the ordinary collections, so the History tab - the board's history table - shows them and Restore undoes them. Import links open the GitHub, GitLab, Gitea and Forgejo importers, and each synced list has a Sync now button. The GitHub, GitLab, Gitea and Forgejo importers bring each issue's files: user-attachments and user-images links, GitLab uploads, and Gitea and Forgejo assets, downloaded through the import's SSRF guard and stored as card attachments in Admin Panel / Attachments / Default Storage. List sync has a new option, Comments, labels, state and files, off by default: comments come from one paged repository-wide list (GitHub, Gitea) or each issue's notes (GitLab), keyed by the tracker's ids, so a second run writes only what changed, and nothing written in WeKan is changed. Gitea issues are fetched without pull requests, and a rate limited answer is waited out once or ends the run with the time to retry. A public board's Show on / Default on Public Board settings are for the public: visitors and non-members get them, read-only, and the board's own members get the private side, so any view - Version Control, Email, Chat and the rest - can be the read-only public view. The card menu has a QR code of the card's link, drawn in the browser by WeKan's own encoder, which the tests check module for module against qrcode-svg. The new strings are translated in every locale. Thanks to xet7 ! Fixes #2015.
69 lines
3.5 KiB
JavaScript
69 lines
3.5 KiB
JavaScript
'use strict';
|
|
|
|
// Guard: an imported GitHub / GitLab / Gitea / Forgejo issue brings its files
|
|
// along, into Admin Panel / Attachments / Default Storage.
|
|
// Run: node tests/issueAttachments.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { issueAttachments, MAX_ATTACHMENTS_PER_ISSUE } = require('../models/lib/issueAttachments.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(`ok - ${name}`); }
|
|
const read = f => fs.readFileSync(path.join(__dirname, '..', f), 'utf8');
|
|
|
|
test('GitHub: user-attachments and user-images links in the body and comments', () => {
|
|
const files = issueAttachments({
|
|
body: 'See \n'
|
|
+ '<img width="300" src="https://user-images.githubusercontent.com/1/abc.png">',
|
|
comments: [{ body: '[log.txt](https://github.com/user-attachments/files/123/log.txt)' }],
|
|
});
|
|
assert.deepStrictEqual(files.map(f => f.name), ['screenshot', 'abc.png', 'log.txt']);
|
|
});
|
|
|
|
test('Gitea / Forgejo: assets of the issue and its comments, and /attachments/<uuid> links', () => {
|
|
const files = issueAttachments({
|
|
body: '',
|
|
assets: [{ name: 'trace.zip', browser_download_url: 'https://gitea.example.com/attachments/aaaaaaaa-1111-2222-3333-444455556666', size: 5 }],
|
|
comments_data: [{ body: 'x', assets: [{ name: 'c.png', browser_download_url: 'https://gitea.example.com/attachments/bbbbbbbb-1111-2222-3333-444455556666' }] }],
|
|
});
|
|
assert.deepStrictEqual(files.map(f => f.name), ['trace.zip', 'a', 'c.png']);
|
|
assert.strictEqual(files[0].size, 5);
|
|
});
|
|
|
|
test('GitLab: /uploads/ links resolved against the project from web_url', () => {
|
|
const files = issueAttachments({
|
|
web_url: 'https://gitlab.com/group/proj/-/issues/9',
|
|
description: '',
|
|
});
|
|
assert.deepStrictEqual(files, [{ name: 'shot.png', url: 'https://gitlab.com/group/proj/uploads/0123456789abcdef0123456789abcdef/shot.png' }]);
|
|
});
|
|
|
|
test('negative: ordinary links, relative paths and other hosts are not files', () => {
|
|
assert.deepStrictEqual(issueAttachments({
|
|
body: '[docs](https://example.com/page) [rel](/uploads/x/y.png) ) '
|
|
+ '[gh](https://github.com/o/r/issues/1) [file](ftp://host/file)',
|
|
}), []);
|
|
assert.deepStrictEqual(issueAttachments(null), []);
|
|
assert.deepStrictEqual(issueAttachments({ comments: 4 }), []);
|
|
});
|
|
|
|
test('each file once, and at most the per-issue cap', () => {
|
|
const url = n => `https://github.com/user-attachments/files/${n}/f${n}.txt`;
|
|
const body = Array.from({ length: MAX_ATTACHMENTS_PER_ISSUE + 10 }, (_, i) => `[f](${url(i)}) [f](${url(i)})`).join(' ');
|
|
assert.strictEqual(issueAttachments({ body }).length, MAX_ATTACHMENTS_PER_ISSUE);
|
|
});
|
|
|
|
test('the parsers pass them on and the creator downloads them safely into default storage', () => {
|
|
const parsers = read('models/lib/externalParsers.js');
|
|
assert.strictEqual((parsers.match(/\.\.\.withAttachments\(issue\)/g) || []).length, 2, 'GitHub/Gitea and GitLab');
|
|
const creator = read('models/kanboardCreator.js');
|
|
assert.match(creator, /fetchImportedAttachment\(att\.url\)/);
|
|
assert.match(creator, /Attachments\.writeAsync\(downloaded\.buffer, \{[\s\S]*?\}, true\)/);
|
|
// negative: Meteor-Files' own download follows redirects unchecked (FollowBleed)
|
|
assert.doesNotMatch(creator, /Attachments\.loadAsync\(/);
|
|
});
|
|
|
|
console.log(`# ${passed} passed`);
|