refactor(icons): consolidate categories with metadata mapping and category validation

This commit is contained in:
Bjorn Lammers 2025-04-29 16:24:29 +02:00
parent 3305a49a7e
commit 9a1d26368b
7 changed files with 321 additions and 18 deletions

View File

@ -35,32 +35,49 @@ body:
label: Categories label: Categories
multiple: true multiple: true
options: options:
- Animal - AI
- Cloud - Analytics-&-Monitoring
- Automation
- Browsers-&-Search
- Cloud-&-Hosting
- Communication - Communication
- Community-&-Social
- Content-Management
- Crypto
- Databases
- Design - Design
- Development - Development
- Downloaders
- E-Commerce - E-Commerce
- Education - Education
- File - File-Management-&-Sync
- Finance - Finance
- Food - Food
- Framework
- Gaming - Gaming
- Hardware - Hardware
- Health - Health
- Location - Home-Automation
- Logistics - Identity
- Infrastructure
- Library
- Mapping-&-Location
- Media - Media
- Music - Music-&-Audio
- Nature - Nature
- Networking
- News - News
- Organization - Notes-&-Productivity
- Search - Operating-Systems
- Organization-&-Planning
- Programming-Language
- Security - Security
- SocialMedia - Software
- Streaming - Streaming
- Travel - Travel
- Version-Control
- Video - Video
- Virtualization
- type: input - type: input
attributes: attributes:
label: Aliases label: Aliases

View File

@ -33,32 +33,49 @@ body:
label: Categories label: Categories
multiple: true multiple: true
options: options:
- Animal - AI
- Cloud - Analytics-&-Monitoring
- Automation
- Browsers-&-Search
- Cloud-&-Hosting
- Communication - Communication
- Community-&-Social
- Content-Management
- Crypto
- Databases
- Design - Design
- Development - Development
- Downloaders
- E-Commerce - E-Commerce
- Education - Education
- File - File-Management-&-Sync
- Finance - Finance
- Food - Food
- Framework
- Gaming - Gaming
- Hardware - Hardware
- Health - Health
- Location - Home-Automation
- Logistics - Identity
- Infrastructure
- Library
- Mapping-&-Location
- Media - Media
- Music - Music-&-Audio
- Nature - Nature
- Networking
- News - News
- Organization - Notes-&-Productivity
- Search - Operating-Systems
- Organization-&-Planning
- Programming-Language
- Security - Security
- SocialMedia - Software
- Streaming - Streaming
- Travel - Travel
- Version-Control
- Video - Video
- Virtualization
- type: input - type: input
attributes: attributes:
label: Aliases label: Aliases

View File

@ -29,6 +29,54 @@ body:
options: options:
- SVG - SVG
- PNG - PNG
- type: dropdown
attributes:
label: Categories
multiple: true
options:
- AI
- Analytics-&-Monitoring
- Automation
- Browsers-&-Search
- Cloud-&-Hosting
- Communication
- Community-&-Social
- Content-Management
- Crypto
- Databases
- Design
- Development
- Downloaders
- E-Commerce
- Education
- File-Management-&-Sync
- Finance
- Food
- Framework
- Gaming
- Hardware
- Health
- Home-Automation
- Identity
- Infrastructure
- Library
- Mapping-&-Location
- Media
- Music-&-Audio
- Nature
- Networking
- News
- Notes-&-Productivity
- Operating-Systems
- Organization-&-Planning
- Programming-Language
- Security
- Software
- Streaming
- Travel
- Version-Control
- Video
- Virtualization
- type: textarea - type: textarea
attributes: attributes:
label: Additional information label: Additional information

View File

@ -24,6 +24,54 @@ body:
options: options:
- SVG - SVG
- PNG - PNG
- type: dropdown
attributes:
label: Categories
multiple: true
options:
- AI
- Analytics-&-Monitoring
- Automation
- Browsers-&-Search
- Cloud-&-Hosting
- Communication
- Community-&-Social
- Content-Management
- Crypto
- Databases
- Design
- Development
- Downloaders
- E-Commerce
- Education
- File-Management-&-Sync
- Finance
- Food
- Framework
- Gaming
- Hardware
- Health
- Home-Automation
- Identity
- Infrastructure
- Library
- Mapping-&-Location
- Media
- Music-&-Audio
- Nature
- Networking
- News
- Notes-&-Productivity
- Operating-Systems
- Organization-&-Planning
- Programming-Language
- Security
- Software
- Streaming
- Travel
- Version-Control
- Video
- Virtualization
- type: textarea - type: textarea
attributes: attributes:
label: Additional information label: Additional information

View File

@ -37,6 +37,58 @@ jobs:
run: echo "ISSUE_FORM=$(python scripts/parse_issue_form.py)" >> "$GITHUB_OUTPUT" run: echo "ISSUE_FORM=$(python scripts/parse_issue_form.py)" >> "$GITHUB_OUTPUT"
env: env:
INPUT_ISSUE_BODY: ${{ github.event.issue.body }} INPUT_ISSUE_BODY: ${{ github.event.issue.body }}
- name: Validate Categories
run: |
import json
import sys
import os
# Load allowed categories from metadata.map.json
map_file = "metadata.map.json"
try:
with open(map_file, 'r', encoding='utf-8') as f:
map_data = json.load(f)
# Assuming the first key in the map holds the example structure
example_key = list(map_data.keys())[0]
allowed_categories = set(map_data[example_key]['categories'])
print(f"Loaded {len(allowed_categories)} allowed categories from {map_file}")
except Exception as e:
print(f"::error file={map_file}::Failed to load or parse allowed categories from {map_file}: {e}")
sys.exit(1)
# Load submitted form data
form_json_string = os.environ.get('INPUT_ISSUE_FORM')
if not form_json_string:
print("::error::Failed to get form JSON from environment variable.")
sys.exit(1)
try:
form_data = json.loads(form_json_string)
except json.JSONDecodeError as e:
print(f"::error::Failed to parse form JSON: {e}")
print(f"Form JSON string was: {form_json_string}")
sys.exit(1)
# Extract submitted categories (handle potential missing key or None value)
submitted_categories_str = form_data.get('Categories') # Label from issue form
submitted_categories = set()
if submitted_categories_str:
submitted_categories = set(cat.strip() for cat in submitted_categories_str.split('\\n') if cat.strip())
print(f"Submitted categories: {submitted_categories or 'None'}")
# Validate
invalid_categories = submitted_categories - allowed_categories
if invalid_categories:
print(f"::error::Invalid categories found: {', '.join(sorted(list(invalid_categories)))}")
print("Please ensure all submitted categories exist in metadata.map.json.")
sys.exit(1)
else:
print("All submitted categories are valid.")
env:
INPUT_ISSUE_FORM: ${{ steps.parse_issue_form.outputs.ISSUE_FORM }}
- name: Create metadata file - name: Create metadata file
run: python scripts/generate_metadata_file.py ${{ env.ICON_TYPE }} addition run: python scripts/generate_metadata_file.py ${{ env.ICON_TYPE }} addition
env: env:

View File

@ -37,6 +37,62 @@ jobs:
run: echo "ISSUE_FORM=$(python scripts/parse_issue_form.py)" >> "$GITHUB_OUTPUT" run: echo "ISSUE_FORM=$(python scripts/parse_issue_form.py)" >> "$GITHUB_OUTPUT"
env: env:
INPUT_ISSUE_BODY: ${{ github.event.issue.body }} INPUT_ISSUE_BODY: ${{ github.event.issue.body }}
- name: Validate Categories
run: |
import json
import sys
import os
# Load allowed categories from metadata.map.json
map_file = "metadata.map.json"
try:
with open(map_file, 'r', encoding='utf-8') as f:
map_data = json.load(f)
# Assuming the first key in the map holds the example structure
example_key = list(map_data.keys())[0]
allowed_categories = set(map_data[example_key]['categories'])
print(f"Loaded {len(allowed_categories)} allowed categories from {map_file}")
except Exception as e:
print(f"::error file={map_file}::Failed to load or parse allowed categories from {map_file}: {e}")
sys.exit(1)
# Load submitted form data
form_json_string = os.environ.get('INPUT_ISSUE_FORM')
if not form_json_string:
print("::error::Failed to get form JSON from environment variable.")
sys.exit(1)
try:
form_data = json.loads(form_json_string)
except json.JSONDecodeError as e:
print(f"::error::Failed to parse form JSON: {e}")
print(f"Form JSON string was: {form_json_string}")
sys.exit(1)
# Extract submitted categories (handle potential missing key or None value)
# NOTE: The update forms might not have a 'Categories' field if categories aren't updatable via that form.
# If 'Categories' is missing or None in the form data, validation passes trivially.
submitted_categories_str = form_data.get('Categories') # Label from issue form
submitted_categories = set()
if submitted_categories_str:
submitted_categories = set(cat.strip() for cat in submitted_categories_str.split('\\n') if cat.strip())
if not submitted_categories_str:
print("No categories submitted in this form, skipping validation.")
else:
print(f"Submitted categories: {submitted_categories}")
# Validate
invalid_categories = submitted_categories - allowed_categories
if invalid_categories:
print(f"::error::Invalid categories found: {', '.join(sorted(list(invalid_categories)))}")
print("Please ensure all submitted categories exist in metadata.map.json.")
sys.exit(1)
else:
print("All submitted categories are valid.")
env:
INPUT_ISSUE_FORM: ${{ steps.parse_issue_form.outputs.ISSUE_FORM }}
- name: Update metadata file - name: Update metadata file
run: python scripts/generate_metadata_file.py ${{ env.ICON_TYPE }} update run: python scripts/generate_metadata_file.py ${{ env.ICON_TYPE }} update
env: env:

65
metadata.map.json Normal file
View File

@ -0,0 +1,65 @@
{
"example-icon": {
"base": "svg",
"aliases": [
"example-alias",
"another-alias"
],
"categories": [
"AI",
"Analytics-&-Monitoring",
"Automation",
"Browsers-&-Search",
"Cloud-&-Hosting",
"Communication",
"Community-&-Social",
"Content-Management",
"Crypto",
"Databases",
"Design",
"Development",
"Downloaders",
"E-Commerce",
"Education",
"File-Management-&-Sync",
"Finance",
"Food",
"Framework",
"Gaming",
"Hardware",
"Health",
"Home-Automation",
"Identity",
"Infrastructure",
"Library",
"Mapping-&-Location",
"Media",
"Music-&-Audio",
"Nature",
"Networking",
"News",
"Notes-&-Productivity",
"Operating-Systems",
"Organization-&-Planning",
"Programming-Language",
"Security",
"Software",
"Streaming",
"Travel",
"Version-Control",
"Video",
"Virtualization"
],
"update": {
"timestamp": "YYYY-MM-DDTHH:mm:ssZ",
"author": {
"id": 12345678,
"login": "contributor-login"
}
},
"colors": {
"dark": "example-icon-dark",
"light": "example-icon-light"
}
}
}