stackchain-dashboard/frontend/update-follow-up.js
timmy d96a77c5d5
All checks were successful
CI / lint (pull_request) Successful in 1m32s
CI / build-release (pull_request) Successful in 6s
CI / release-candidate (pull_request) Has been skipped
feat: create follow-up work from updates (Closes #663)
2026-08-12 16:32:50 +00:00

33 lines
1.3 KiB
JavaScript

function createUpdateFollowUp() {
const clean = (value, limit) => String(value || '').replace(/\s+/g, ' ').trim().slice(0, limit);
const safeRepository = value => {
const candidate = String(value || '');
return /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(candidate) &&
candidate.split('/').every(part => part !== '.' && part !== '..') ? candidate : '';
};
const safeUrl = value => {
try {
const parsed = new URL(String(value || ''));
return parsed.protocol === 'https:' || parsed.protocol === 'http:' ? parsed.href : '';
} catch (_error) { return ''; }
};
function draft(detail = {}) {
const source = safeUrl(detail.url || detail.latest_comment?.url);
const context = clean(detail.latest_comment?.body || detail.subject_body, 9000);
const title = clean(detail.title, 228);
const sections = [];
if (source) sections.push('Source: ' + source);
if (context) sections.push('Latest context:\n> ' + context.replace(/\n/g, '\n> '));
return {
repository: safeRepository(detail.repository),
title: ('Follow up: ' + (title || 'Unread update')).slice(0, 240),
body: sections.join('\n\n').slice(0, 9500),
};
}
return { draft };
}
if (typeof module !== 'undefined' && module.exports) module.exports = createUpdateFollowUp;