97 lines
3.6 KiB
JavaScript
97 lines
3.6 KiB
JavaScript
// Builds a pre-filled Gitea "new issue" URL (title + body via query params —
|
|||
|
|
// verified working on this Gitea instance even though its YAML issue-forms
|
||
|
|
// rendering (.github/ISSUE_TEMPLATE/hardware-report.yml) does not render as
|
||
|
|
// a structured form: it silently falls back to a blank issue instead, so we
|
||
|
|
// don't rely on it) and opens it. The body includes a ready-to-paste YAML
|
||
|
|
// block matching data/schema.json, so a maintainer can copy it straight
|
||
|
|
// into a new data/reports/*.yml file with minimal editing.
|
||
|
|
|
||
|
|
const REPO_URL = "https://source.archipelago-foundation.org/ssmithx/ArchyHCL";
|
||
|
|
|
||
|
|
const form = document.getElementById("report-form");
|
||
|
|
const statusSelect = document.getElementById("status");
|
||
|
|
const issuesField = document.getElementById("issues");
|
||
|
|
const issuesRequiredHint = document.getElementById("issues-required");
|
||
|
|
const errorEl = document.getElementById("form-error");
|
||
|
|
|
||
|
|
function updateIssuesRequirement() {
|
||
|
|
const required = statusSelect.value !== "working";
|
||
|
|
issuesRequiredHint.hidden = !required;
|
||
|
|
issuesField.required = required;
|
||
|
|
}
|
||
|
|
statusSelect.addEventListener("change", updateIssuesRequirement);
|
||
|
|
updateIssuesRequirement();
|
||
|
|
|
||
|
|
// A YAML double-quoted scalar uses the same escaping rules as JSON strings
|
||
|
|
// for every character that matters here (quotes, backslashes, control
|
||
|
|
// chars) — JSON.stringify is a safe, simple way to produce one.
|
||
|
|
function yamlString(value) {
|
||
|
|
return JSON.stringify(value ?? "");
|
||
|
|
}
|
||
|
|
|
||
|
|
function yamlBlock(value) {
|
||
|
|
const trimmed = (value ?? "").trim();
|
||
|
|
if (!trimmed) return null;
|
||
|
|
return trimmed
|
||
|
|
.split("\n")
|
||
|
|
.map((line) => " " + line)
|
||
|
|
.join("\n");
|
||
|
|
}
|
||
|
|
|
||
|
|
function val(id) {
|
||
|
|
return document.getElementById(id).value.trim();
|
||
|
|
}
|
||
|
|
|
||
|
|
function buildYaml() {
|
||
|
|
const lines = [];
|
||
|
|
lines.push(`device_model: ${yamlString(val("device_model"))}`);
|
||
|
|
lines.push(`form_factor: ${val("form_factor")}`);
|
||
|
|
lines.push(`cpu: ${yamlString(val("cpu"))}`);
|
||
|
|
lines.push(`ram_gb: ${val("ram_gb")}`);
|
||
|
|
lines.push("storage:");
|
||
|
|
lines.push(` type: ${val("storage_type")}`);
|
||
|
|
lines.push(` size_gb: ${val("storage_size_gb")}`);
|
||
|
|
lines.push(`wifi_chip: ${yamlString(val("wifi_chip"))}`);
|
||
|
|
const ethernet = val("ethernet");
|
||
|
|
if (ethernet) lines.push(`ethernet: ${yamlString(ethernet)}`);
|
||
|
|
lines.push(`archy_version: ${yamlString(val("archy_version"))}`);
|
||
|
|
lines.push(`install_method: ${val("install_method")}`);
|
||
|
|
lines.push(`status: ${val("status")}`);
|
||
|
|
lines.push(`tested_date: ${yamlString(val("tested_date"))}`);
|
||
|
|
const submittedBy = val("submitted_by");
|
||
|
|
if (submittedBy) lines.push(`submitted_by: ${yamlString(submittedBy)}`);
|
||
|
|
const issuesBlock = yamlBlock(val("issues"));
|
||
|
|
if (issuesBlock) lines.push(`issues: |\n${issuesBlock}`);
|
||
|
|
const notesBlock = yamlBlock(val("notes"));
|
||
|
|
if (notesBlock) lines.push(`notes: |\n${notesBlock}`);
|
||
|
|
return lines.join("\n");
|
||
|
|
}
|
||
|
|
|
||
|
|
form.addEventListener("submit", (e) => {
|
||
|
|
e.preventDefault();
|
||
|
|
errorEl.hidden = true;
|
||
|
|
|
||
|
|
if (statusSelect.value !== "working" && !val("issues")) {
|
||
|
|
errorEl.textContent = 'Please describe the issue(s) — required when status is "partial" or "broken".';
|
||
|
|
errorEl.hidden = false;
|
||
|
|
issuesField.focus();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const deviceModel = val("device_model");
|
||
|
|
const title = `hw: ${deviceModel}`;
|
||
|
|
const yaml = buildYaml();
|
||
|
|
const body = [
|
||
|
|
`Hardware report for **${deviceModel}**, submitted via the site form.`,
|
||
|
|
"",
|
||
|
|
"A maintainer: copy the block below into a new file under `data/reports/` (see CONTRIBUTING.md) to add it to the list.",
|
||
|
|
"",
|
||
|
|
"```yaml",
|
||
|
|
yaml,
|
||
|
|
"```",
|
||
|
|
].join("\n");
|
||
|
|
|
||
|
|
const url = `${REPO_URL}/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`;
|
||
|
|
window.open(url, "_blank", "noopener");
|
||
|
|
});
|