Skip to content

Commit e368963

Browse files
Merge pull request #28 from YDX-2147483647/copilot/fix-27
2 parents a3dcf81 + c448eb5 commit e368963

4 files changed

Lines changed: 71 additions & 5 deletions

File tree

.github/workflows/check.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ jobs:
1717
with:
1818
sparse-checkout: |
1919
projects.yaml
20+
scripts/projects.schema.json
2021
sparse-checkout-cone-mode: false
22+
- name: Install boon
23+
run: |
24+
wget https://github.com/santhosh-tekuri/boon/releases/download/v0.6.1/boon-x86_64-unknown-linux-gnu.tar.gz
25+
tar -xzf boon-x86_64-unknown-linux-gnu.tar.gz
26+
sudo mv boon /usr/local/bin/boon
27+
2128
- name: Get names
2229
uses: mikefarah/yq@master
2330
id: projects-names
@@ -35,3 +42,7 @@ jobs:
3542
echo '```' >> $GITHUB_STEP_SUMMARY
3643
exit 1
3744
fi
45+
46+
- name: Validate according to the schema
47+
run: |
48+
boon scripts/projects.schema.json projects.yaml

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"yaml.schemas": {
3-
".vscode/projects.schema.json": "projects.yaml"
3+
"scripts/projects.schema.json": "projects.yaml"
44
}
55
}

scripts/add_project.py

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
4396
def 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

81136
def 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

Comments
 (0)