m2: apply-ticket fallback anchor/chemin parsing
Some checks failed
CI / build-and-anchors (push) Failing after 34s
Some checks failed
CI / build-and-anchors (push) Failing after 34s
This commit is contained in:
@@ -185,6 +185,20 @@ function unquoteBlock(s) {
|
|||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractAnchorIdAnywhere(text) {
|
||||||
|
const s = String(text || "");
|
||||||
|
// accepte "#p-3-abcdef12" ou "p-3-abcdef12"
|
||||||
|
const m = s.match(/#?(p-\d+-[0-9a-f]{8})/i);
|
||||||
|
return m ? m[1] : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractCheminFromAnyUrl(body) {
|
||||||
|
const s = String(body || "");
|
||||||
|
// Cherche un chemin du type "/archicratie/prologue/#p-..."
|
||||||
|
const m = s.match(/(\/[a-z0-9\-]+\/[a-z0-9\-\/]+\/)#p-\d+-[0-9a-f]{8}/i);
|
||||||
|
return m ? m[1] : "";
|
||||||
|
}
|
||||||
|
|
||||||
async function readHtmlParagraphText(htmlPath, anchorId) {
|
async function readHtmlParagraphText(htmlPath, anchorId) {
|
||||||
const html = await fs.readFile(htmlPath, "utf-8");
|
const html = await fs.readFile(htmlPath, "utf-8");
|
||||||
const re = new RegExp(`<p[^>]*\\bid=["']${escapeRegExp(anchorId)}["'][^>]*>([\\s\\S]*?)<\\/p>`, "i");
|
const re = new RegExp(`<p[^>]*\\bid=["']${escapeRegExp(anchorId)}["'][^>]*>([\\s\\S]*?)<\\/p>`, "i");
|
||||||
@@ -423,12 +437,24 @@ async function main() {
|
|||||||
|
|
||||||
const body = String(issue.body || "").replace(/\r\n/g, "\n");
|
const body = String(issue.body || "").replace(/\r\n/g, "\n");
|
||||||
|
|
||||||
let chemin = pickLine(body, "Chemin") || pickHeadingValue(body, "Chemin");
|
const title = String(issue.title || "");
|
||||||
let ancre = pickLine(body, "Ancre") || pickHeadingValue(body, "Ancre paragraphe") || pickHeadingValue(body, "Ancre");
|
|
||||||
chemin = normalizeChemin(chemin);
|
let chemin =
|
||||||
|
pickLine(body, "Chemin") ||
|
||||||
|
pickHeadingValue(body, "Chemin") ||
|
||||||
|
extractCheminFromAnyUrl(body);
|
||||||
|
|
||||||
|
let ancre =
|
||||||
|
pickLine(body, "Ancre") ||
|
||||||
|
pickHeadingValue(body, "Ancre paragraphe") ||
|
||||||
|
pickHeadingValue(body, "Ancre");
|
||||||
|
|
||||||
ancre = (ancre || "").trim();
|
ancre = (ancre || "").trim();
|
||||||
if (ancre.startsWith("#")) ancre = ancre.slice(1);
|
if (ancre.startsWith("#")) ancre = ancre.slice(1);
|
||||||
|
|
||||||
|
// ✅ fallback si le ticket est mal formé
|
||||||
|
if (!ancre) ancre = extractAnchorIdAnywhere(title) || extractAnchorIdAnywhere(body);
|
||||||
|
|
||||||
const currentFull = pickSection(body, ["Texte actuel (copie exacte du paragraphe)", "## Texte actuel (copie exacte du paragraphe)"]);
|
const currentFull = pickSection(body, ["Texte actuel (copie exacte du paragraphe)", "## Texte actuel (copie exacte du paragraphe)"]);
|
||||||
const currentEx = pickSection(body, ["Texte actuel (extrait)", "## Assertion / passage à vérifier", "Assertion / passage à vérifier"]);
|
const currentEx = pickSection(body, ["Texte actuel (extrait)", "## Assertion / passage à vérifier", "Assertion / passage à vérifier"]);
|
||||||
const texteActuel = unquoteBlock(currentFull || currentEx);
|
const texteActuel = unquoteBlock(currentFull || currentEx);
|
||||||
|
|||||||
Reference in New Issue
Block a user