All files / src parse-delivery-markdown.ts

75.75% Statements 50/66
61.9% Branches 13/21
76.92% Functions 10/13
75.75% Lines 50/66

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67  1x 1x 1x 1x 10x 10x     10x 10x 10x 10x 10x 10x     10x 10x 1x 1x 2x 2x 2x 2x 2x 2x     2x 2x 10x 10x 10x 10x 10x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x               1x 1x  
import type { DeliveryFolder } from "./delivery-path.js"
 
const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/
 
export function parseFrontmatterLine(line: string): [string, string] | null {
  const idx = line.indexOf(":")
  if (idx === -1) {
    return null
  }
  const key = line.slice(0, idx).trim()
  let value = line.slice(idx + 1).trim()
  if (
    (value.startsWith('"') && value.endsWith('"')) ||
    (value.startsWith("'") && value.endsWith("'"))
  ) {
    value = value.slice(1, -1)
  }
  return [key, value]
}
 
export function parseDeliveryMarkdown(text: string): {
  frontmatter: Record<string, string>
  body: string
  full: string
} {
  const match = FRONTMATTER_RE.exec(text)
  if (!match) {
    return { frontmatter: {}, body: text, full: text }
  }
  const frontmatter: Record<string, string> = {}
  for (const line of match[1].split("\n")) {
    const parsed = parseFrontmatterLine(line)
    if (parsed) {
      frontmatter[parsed[0]] = parsed[1]
    }
  }
  const body = text.slice(match[0].length)
  return { frontmatter, body, full: text }
}
 
const ENTITY_LABELS: Record<DeliveryFolder, string> = {
  us: "User story",
  epics: "Epic",
  versions: "Version",
  sprints: "Sprint",
}
 
export function deliveryEntityLabel(folder: DeliveryFolder): string {
  return ENTITY_LABELS[folder]
}
 
export function frontmatterBadgeKeys(folder: DeliveryFolder): string[] {
  const common = ["id", "title", "status"]
  switch (folder) {
    case "us":
      return [...common, "epic", "version", "sprint", "moscow", "ready"]
    case "epics":
      return [...common, "versions", "outcome"]
    case "versions":
      return [...common, "outcome"]
    case "sprints":
      return [...common, "version", "goal"]
    default:
      return common
  }
}