Skip to content

Commit b3b9449

Browse files
Update add_project.yml
1 parent b05dbac commit b3b9449

1 file changed

Lines changed: 49 additions & 50 deletions

File tree

.github/workflows/add_project.yml

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -64,55 +64,55 @@ jobs:
6464
export CATEGORY=$(echo "$ISSUE_BODY" | grep -A1 "Category" | tail -n1 | xargs)
6565
6666
python3 - <<'PY'
67-
import re
68-
from pathlib import Path
69-
import os
70-
71-
readme = Path("README.md")
72-
text = readme.read_text(encoding="utf-8") if readme.exists() else ""
73-
74-
name = os.environ["NAME"]
75-
repo = os.environ["REPO"]
76-
website = os.environ["WEBSITE"]
77-
desc = os.environ["DESC"]
78-
category = os.environ["CATEGORY"] or "Other"
79-
website_md = f"[{website}]({website})" if website else "—"
80-
row = f"| {name} | [Repo]({repo}) | {website_md} | {desc} |"
81-
82-
lines = text.splitlines()
83-
cat_header_pattern = re.compile(rf"##\s*{re.escape(category)}", re.I)
84-
header_idx = next((i for i, l in enumerate(lines) if cat_header_pattern.match(l)), None)
85-
86-
if header_idx is not None:
87-
table_header_idx = next((i for i in range(header_idx+1, len(lines))
88-
if re.search(r"\|\s*Name\s*\|.*\|\s*Repo\s*\|", lines[i])), None)
89-
if table_header_idx is not None:
90-
if any(name in l for l in lines[table_header_idx+2:]):
91-
print(f"Project '{name}' already exists in '{category}'. Skipping insert.")
92-
else:
93-
lines.insert(table_header_idx + 2, row)
94-
else:
95-
insert_at = header_idx + 1
96-
block = [
97-
"",
98-
"| Name | Repo | Website | Description |",
99-
"|------|------|---------|-------------|",
100-
row
101-
]
102-
for offset, l in enumerate(block):
103-
lines.insert(insert_at + offset, l)
104-
else:
105-
if lines and lines[-1].strip() != "":
106-
lines.append("")
107-
lines.append(f"## {category}")
108-
lines.append("")
109-
lines.append("| Name | Repo | Website | Description |")
110-
lines.append("|------|------|---------|-------------|")
111-
lines.append(row)
112-
113-
readme.write_text("\n".join(lines)+"\n", encoding="utf-8")
114-
print(f"Inserted project '{name}' into '{category}'")
115-
PY
67+
import re
68+
from pathlib import Path
69+
import os
70+
71+
readme = Path("README.md")
72+
text = readme.read_text(encoding="utf-8") if readme.exists() else ""
73+
74+
name = os.environ["NAME"]
75+
repo = os.environ["REPO"]
76+
website = os.environ["WEBSITE"]
77+
desc = os.environ["DESC"]
78+
category = os.environ["CATEGORY"] or "Other"
79+
website_md = f"[{website}]({website})" if website else "—"
80+
row = f"| {name} | [Repo]({repo}) | {website_md} | {desc} |"
81+
82+
lines = text.splitlines()
83+
cat_header_pattern = re.compile(rf"##\s*{re.escape(category)}", re.I)
84+
header_idx = next((i for i, l in enumerate(lines) if cat_header_pattern.match(l)), None)
85+
86+
if header_idx is not None:
87+
table_header_idx = next((i for i in range(header_idx+1, len(lines))
88+
if re.search(r"\|\s*Name\s*\|.*\|\s*Repo\s*\|", lines[i])), None)
89+
if table_header_idx is not None:
90+
if any(name in l for l in lines[table_header_idx+2:]):
91+
print(f"Project '{name}' already exists in '{category}'. Skipping insert.")
92+
else:
93+
lines.insert(table_header_idx + 2, row)
94+
else:
95+
insert_at = header_idx + 1
96+
block = [
97+
"",
98+
"| Name | Repo | Website | Description |",
99+
"|------|------|---------|-------------|",
100+
row
101+
]
102+
for offset, l in enumerate(block):
103+
lines.insert(insert_at + offset, l)
104+
else:
105+
if lines and lines[-1].strip() != "":
106+
lines.append("")
107+
lines.append(f"## {category}")
108+
lines.append("")
109+
lines.append("| Name | Repo | Website | Description |")
110+
lines.append("|------|------|---------|-------------|")
111+
lines.append(row)
112+
113+
readme.write_text("\n".join(lines)+"\n", encoding="utf-8")
114+
print(f"Inserted project '{name}' into '{category}'")
115+
PY
116116

117117
- name: Create Pull Request
118118
if: ${{ github.event.label.name == 'approved' && contains(env.MAINTAINERS, github.event.sender.login) }}
@@ -131,7 +131,6 @@ jobs:
131131
env:
132132
GH_TOKEN: ${{ secrets.MERGE_TOKEN }}
133133
run: |
134-
# Get PR number for the branch
135134
PR_NUMBER=$(gh pr list --state open --head add-project-${{ github.event.issue.number }} --json number -q '.[0].number')
136135
if [ "$PR_NUMBER" != "null" ]; then
137136
echo "Merging PR #$PR_NUMBER..."

0 commit comments

Comments
 (0)