@@ -40,14 +40,69 @@ def url_to_id(url: str) -> dict[str, str]:
4040 raise Exception (f"Cannot recognize URL netloc “{ u .netloc } ”: { url } " )
4141
4242
43+ def parse_labels (
44+ labels_section : str , labels_config : list [dict [str , str ]]
45+ ) -> dict [str , str ]:
46+ """Parse selected labels from checkboxes"""
47+ # Create mapping from display name to internal label
48+ label_mapping = {label ["name" ]: label ["label" ] for label in labels_config }
49+
50+ selected_labels : list [str ] = []
51+
52+ for line in labels_section .strip ().splitlines ():
53+ if line .startswith ("- [x]" ):
54+ # Extract the label name (emoji + text before the first '—')
55+ match = re .match (r"- \[x\] (.+?) —" , line )
56+ if match :
57+ label = match .group (1 ).strip ()
58+ assert label in label_mapping , f"unknown label: { label } "
59+ selected_labels .append (label_mapping [label ])
60+
61+ if selected_labels :
62+ return {"labels" : f"[{ ', ' .join (selected_labels )} ]" }
63+ return {}
64+
65+
66+ def parse_package_registries (registries_text : str ) -> dict [str , str ]:
67+ """Parse package registry URLs and extract IDs"""
68+ result = {}
69+
70+ for line in registries_text .strip ().splitlines ():
71+ url = line .strip ()
72+ if not url :
73+ continue
74+
75+ parsed = urlparse (url )
76+ path = parsed .path
77+ match parsed .netloc :
78+ case "pypi.org" :
79+ # Example: https://pypi.org/project/showman/
80+ result ["pypi_id" ] = path .removeprefix ("/project/" ).removesuffix ("/" )
81+ case "www.npmjs.com" :
82+ # Example: https://www.npmjs.com/package/astro-typst
83+ result ["npm_id" ] = path .removeprefix ("/package/" )
84+ case "crates.io" | "lib.rs" :
85+ # Example: https://crates.io/crates/typstyle or https://lib.rs/crates/tinymist
86+ result ["cargo_id" ] = path .removeprefix ("/crates/" )
87+ case "pkg.go.dev" :
88+ # Example: https://pkg.go.dev/github.com/francescoalemanno/gotypst
89+ result ["go_id" ] = path .removeprefix ("/" )
90+ case other :
91+ assert False , f"{ other } is not supported yet: { url } "
92+
93+ return result
94+
95+
4396def build_transformers (project_yaml : str ) -> dict [str , Transformer ]:
4497 """
4598 @param project_yaml: content of `project.yaml`
4699 @return transformers: { original_key: original_value ⇒ { key: value} }
47100 """
48101 yaml = YAML (typ = "safe" )
102+ project_config = yaml .load (project_yaml )
49103
50- categories = yaml .load (project_yaml )["categories" ]
104+ categories = project_config ["categories" ]
105+ labels = project_config ["labels" ]
51106
52107 return {
53108 "Name" : lambda v : {"name" : v .strip ()},
@@ -57,8 +112,8 @@ def build_transformers(project_yaml: str) -> dict[str, Transformer]:
57112 c ["category" ] for c in categories if c ["title" ] == v .strip ()
58113 )
59114 },
60- # TODO: Support _Labels_
61- # TODO: Support _Package registries_
115+ "Labels" : lambda v : parse_labels ( v , labels ),
116+ "Package registries" : parse_package_registries ,
62117 }
63118
64119
@@ -80,7 +135,7 @@ def parse_issue_body(body: str, transformers: dict[str, Transformer]) -> dict[st
80135
81136def dump (project : dict [str , str ], project_yaml : str ) -> str :
82137 last_line = project_yaml .splitlines ()[- 1 ]
83- tab = re .match (R"^(\s*) " , last_line ).group (1 )
138+ tab = re .match (R"^(\s*) " , last_line ).group (1 ) # type: ignore
84139 return f"{ tab } - " + f"\n { tab } " .join (f"{ k } : { v } " for k , v in project .items ())
85140
86141
0 commit comments