The diagnostics snapshot.
An absolute issues/new URL.
buildGithubUrl(diag); // "https://github.com/owner/repo/issues/new?template=…"
export function buildGithubUrl(d: Diagnostics): string {
const base = `https://github.com/${__GITHUB_OWNER__}/${__GITHUB_REPO__}/issues/new`;
const { template, labels } = reportConfig.github;
const maxChars = reportConfig.maxChars.github;
const build = (logs: string): string => {
const params = new URLSearchParams();
params.set('template', template);
if (labels.length) params.set('labels', labels.join(','));
params.set('title', `[Bug] ${d.message}`.slice(0, 120));
params.set('version', d.version);
params.set('diagnostics', formatMetadata(d));
params.set('logs', logs);
return `${base}?${params.toString()}`;
};
const fullLogs = formatLogs(d);
let url = build(fullLogs);
if (url.length <= maxChars) return url;
// Too long: shrink the raw logs and mark them as truncated. Each pass trims a
// bit more than the overflow to absorb URL-encoding expansion and the marker.
const marker = '\n…[truncated — full log copied to clipboard]';
let raw = fullLogs;
do {
const overflow = url.length - maxChars;
raw = raw.slice(0, Math.max(0, raw.length - overflow - marker.length - 16));
url = build(raw + marker);
} while (url.length > maxChars && raw.length > 0);
return url;
}
Builds a prefilled GitHub issue-form URL. Because a
templateis set, GitHub prefills by field id (version,diagnostics,logs) rather thanbody. Thelogsfield is shrunk last so the whole URL stays within the configured character budget.