Skip to content

Commit 122b1d7

Browse files
ci: Update the issue template form
1 parent f9aa43d commit 122b1d7

7 files changed

Lines changed: 163 additions & 76 deletions

File tree

.github/ISSUE_TEMPLATE/01_suggest-project.yml

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ body:
88
value: |
99
Please make sure that the project was not already added or suggested to this best-of list.
1010
11-
(Existing projects are recorded in [projects.yaml](https://github.com/YDX-2147483647/best-of-typst/blob/main/projects.yaml) and [README.md](https://github.com/YDX-2147483647/best-of-typst/blob/main/README.md), and others’ requests are in [Issues](https://github.com/YDX-2147483647/best-of-typst/issues?q=is%3Aopen+label%3Aadd-project))
11+
(Existing projects are recorded in [projects.yaml](https://github.com/YDX-2147483647/best-of-typst/blob/main/projects.yaml) or [README.md](https://github.com/YDX-2147483647/best-of-typst/blob/main/README.md), and others’ requests are in [Issues](https://github.com/YDX-2147483647/best-of-typst/issues?q=is%3Aopen+label%3Aadd-project))
1212
1313
- type: markdown
1414
attributes:
1515
value: |
1616
### Project details
1717
1818
Please fill out as much of the following information as possible.
19+
It will assist human review and also help the robot draft a pull request.
1920
2021
- type: input
2122
id: name
@@ -27,7 +28,8 @@ body:
2728
id: url
2829
attributes:
2930
label: URL
30-
description: GitHub, Gitee, Greasy Fork…
31+
description: GitHub, GitLab, Gitee, Greasy Fork…
32+
3133
- type: dropdown
3234
id: category
3335
attributes:
@@ -47,6 +49,54 @@ body:
4749
- 🐱‍🐉 Miscellaneous
4850
# sync-categories: end
4951

52+
- type: checkboxes
53+
id: labels
54+
attributes:
55+
label: Labels
56+
description: Select one or more labels.
57+
options:
58+
# sync-labels: start
59+
- label: |
60+
🤖 CLI
61+
Command-line programs with pre-built binaries available.
62+
- label: |
63+
🥡 Runnable
64+
Runnable projects that needs a proper environment (e.g., pip/npm/cargo install).
65+
- label: |
66+
🔌 API
67+
Libraries providing API for development.
68+
- label: |
69+
🎨 App
70+
Local apps with graphical user interface.
71+
- label: |
72+
🦋 Web
73+
Web pages and Web apps.
74+
- label: |
75+
🧩 Extension
76+
Browser addons and user scripts, and other kinds of extensions.
77+
- label: |
78+
🌌 Typst package
79+
Projects that are also available as Typst packages, and experimental unpublished local packages.
80+
- label: |
81+
🗺️ Multilingual
82+
Projects that are available in multiple languages or scripts.
83+
- label: |
84+
🐧 non-English
85+
Projects that are not available in English.
86+
# sync-labels: end
87+
88+
- type: textarea
89+
attributes:
90+
label: Package registries
91+
description: Links to the project in package registries or catalogs (if any).
92+
placeholder: |
93+
Examples:
94+
https://pypi.org/project/showman/
95+
https://www.npmjs.com/package/astro-typst
96+
https://crates.io/crates/typstyle
97+
https://lib.rs/crates/tinymist
98+
https://pkg.go.dev/github.com/francescoalemanno/gotypst
99+
50100
- type: markdown
51101
attributes:
52102
value: |

.vscode/projects.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@
110110
"pypi_id": {
111111
"type": "string"
112112
},
113+
"go_id": {
114+
"type": "string"
115+
},
113116
"greasy_fork_id": {
114117
"type": "integer"
115118
},
@@ -155,6 +158,11 @@
155158
"pypi_id"
156159
]
157160
},
161+
{
162+
"required": [
163+
"go_id"
164+
]
165+
},
158166
{
159167
"required": [
160168
"greasy_fork_id"

justfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ python := env_var_or_default('PYTHON','python')
99
bootstrap:
1010
{{ python }} -m pip install --upgrade ruamel.yaml
1111

12-
# Sync categories
13-
sync-categories *ARGS:
14-
{{ python }} ./scripts/sync_categories.py ./projects.yaml ./.github/ISSUE_TEMPLATE/01_suggest-project.yml {{ ARGS }}
12+
# Sync categories and labels to the issue template form
13+
sync-issue-form *ARGS:
14+
{{ python }} ./scripts/sync_issue_form.py ./projects.yaml ./.github/ISSUE_TEMPLATE/01_suggest-project.yml {{ ARGS }}
1515

1616
# List suggestions of adding projects
1717
list-project-suggestions:

projects.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ projects:
827827
- name: gotypst
828828
category: coding
829829
github_id: francescoalemanno/gotypst
830+
go_id: github.com/francescoalemanno/gotypst
830831
labels: [api]
831832

832833
- name: Prism-Typst

scripts/add_project.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
def url_to_id(url: str) -> dict[str, str]:
3030
u = urlparse(url.strip())
3131
match u.netloc:
32-
case "github.com" | "gitee.com":
32+
case "github.com" | "gitee.com" | "gitlab.com":
3333
key = f"{u.netloc.removesuffix('.com')}_id"
3434
return {key: u.path.removeprefix("/").removesuffix("/")}
3535
case "greasyfork.org":
@@ -57,6 +57,8 @@ def build_transformers(project_yaml: str) -> dict[str, Transformer]:
5757
c["category"] for c in categories if c["title"] == v.strip()
5858
)
5959
},
60+
# TODO: Support _Labels_
61+
# TODO: Support _Package registries_
6062
}
6163

6264

scripts/sync_categories.py

Lines changed: 0 additions & 70 deletions
This file was deleted.

scripts/sync_issue_form.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""Sync categories and labels to the issue template form
2+
3+
projects.yaml → .github/ISSUE_TEMPLATE/01_suggest-project.yml
4+
5+
Note that this script does NOT update `.vscode/projects.schema.json`.
6+
"""
7+
8+
from __future__ import annotations
9+
10+
from argparse import ArgumentParser
11+
from collections import deque
12+
from pathlib import Path
13+
from typing import TYPE_CHECKING
14+
15+
from ruamel.yaml import YAML
16+
17+
if TYPE_CHECKING:
18+
from collections.abc import Generator
19+
from typing import Literal
20+
21+
22+
def build_parser() -> ArgumentParser:
23+
parser = ArgumentParser(
24+
description=__doc__,
25+
epilog="Read from source, substitute the content in destination between "
26+
"“# sync-{categories,labels}: start” and “# sync-{categories,labels}: end”.",
27+
)
28+
parser.add_argument("source", type=Path, help="projects.yaml")
29+
parser.add_argument(
30+
"destination", type=Path, help=".github/ISSUE_TEMPLATE/01_suggest-project.yml"
31+
)
32+
return parser
33+
34+
35+
def format_categories(projects_yaml: dict, *, tab: str) -> Generator[str, None, None]:
36+
return (f"{tab}- {c['title']}" for c in projects_yaml["categories"])
37+
38+
39+
def format_labels(projects_yaml: dict, *, tab: str) -> Generator[str, None, None]:
40+
return (
41+
f"""
42+
{tab}- label: |
43+
{tab} {label["name"]}
44+
{tab} {label["description"]}
45+
""".strip("\n")
46+
for label in projects_yaml["labels"]
47+
)
48+
49+
50+
def transform(issue_template: str, projects_yaml: dict) -> str:
51+
original_rows = issue_template.splitlines()
52+
53+
rows: deque[str] = deque()
54+
interlude: None | Literal["categories", "labels"] = None
55+
for r in original_rows:
56+
match (interlude, r.strip()):
57+
case (None, "# sync-categories: start"):
58+
rows.append(r)
59+
60+
tab = r[: r.index("#")]
61+
rows.extend(format_categories(projects_yaml, tab=tab))
62+
interlude = "categories"
63+
case (_, "# sync-categories: end"):
64+
rows.append(r)
65+
interlude = None
66+
67+
case (None, "# sync-labels: start"):
68+
rows.append(r)
69+
70+
tab = r[: r.index("#")]
71+
rows.extend(format_labels(projects_yaml, tab=tab))
72+
interlude = "labels"
73+
case (_, "# sync-labels: end"):
74+
rows.append(r)
75+
interlude = None
76+
77+
case (None, _):
78+
rows.append(r)
79+
80+
case _:
81+
# Skip original interludes
82+
pass
83+
84+
return "\n".join(rows) + "\n"
85+
86+
87+
if __name__ == "__main__":
88+
args = build_parser().parse_args()
89+
src: Path = args.source
90+
dst: Path = args.destination
91+
92+
yaml = YAML(typ="safe")
93+
projects_yaml = yaml.load(src.read_text(encoding="utf-8"))
94+
issue_template = dst.read_text(encoding="utf-8")
95+
96+
dst.write_text(transform(issue_template, projects_yaml), encoding="utf-8")

0 commit comments

Comments
 (0)