-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy paththeme_comment.py
More file actions
118 lines (94 loc) · 3.5 KB
/
theme_comment.py
File metadata and controls
118 lines (94 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/env python3
"""Generate PR comment for theme info."""
import os
import json
def hex_to_intensity(hex_color):
"""Convert hex color to intensity."""
hex_color = hex_color.lstrip("#")
r = int(hex_color[0:2], 16)
g = int(hex_color[2:4], 16)
b = int(hex_color[4:6], 16)
return 0.299 * r + 0.587 * g + 0.114 * b
def generate_theme_comment():
"""Generate a comment with theme information for PR."""
# Get changed files from environment variable
changed_file = os.environ.get("CHANGED_FILE", "")
if not changed_file:
print("No theme file changes detected.")
return
# Load JSON data from file
with open("hyde-themes.json", "r", encoding="utf-8") as file:
content = file.read()
try:
data = json.loads(content)
except json.JSONDecodeError:
# Fallback: parse multiple JSON objects
data = []
decoder = json.JSONDecoder()
idx = 0
content = content.lstrip()
while idx < len(content):
try:
obj, idx_new = decoder.raw_decode(content[idx:])
data.append(obj)
idx += idx_new
# Skip whitespace
while idx < len(content) and content[idx] in [
"\n",
"\r",
" ",
"\t",
]:
idx += 1
except json.JSONDecodeError:
break
# Find the theme name from changed files
theme_name = os.path.basename(changed_file).replace("-", " ")
# Find matching theme in data
theme_info = None
for theme in data:
if theme.get("THEME", "").lower() == theme_name.lower():
theme_info = theme
break
if not theme_info:
print(f"No theme information found for: {theme_name}")
# Instead of exiting, provide a generic comment for new themes
theme_info = {
"THEME": theme_name,
"DESCRIPTION": "New theme submission",
"OWNER": os.environ.get("GITHUB_REPOSITORY_OWNER", ""),
"LINK": os.environ.get("GITHUB_SERVER_URL", "https://github.com")
+ "/"
+ os.environ.get("GITHUB_REPOSITORY", ""),
"COLORSCHEME": ["#000000", "#FFFFFF"],
}
# Generate comment with theme info
colors = theme_info.get("COLORSCHEME", ["#000000", "#FFFFFF"])
comment = f"""## Theme Summary: {theme_info.get("THEME", "Unknown Theme")}
**Description**: {theme_info.get("DESCRIPTION", "No description available")}
**Author**: [{theme_info.get("OWNER", "").split("/")[-1]}]({theme_info.get("OWNER", "#")})
**Link**: {theme_info.get("LINK", "No link available")}
### Color Scheme
Primary Colors:
- `{colors[0]}`
- `{colors[1]}`
### Testing
To test this theme locally:
```bash
hydectl theme import --name "{theme_info.get("THEME", "Unknown-Theme")}" --url "{theme_info.get("LINK", "")}"
```
Or clone it manually:
```bash
git clone {theme_info.get("LINK", "")}
cd {os.path.basename(theme_info.get("LINK", "").rstrip("/"))}
# Follow installation instructions in README
```
---
*This comment was automatically generated by the HyDE Gallery CI*
"""
# Write comment to file for GitHub Actions to use
with open("pr_comment.md", "w", encoding="utf-8") as f:
f.write(comment)
print(f"Generated PR comment for theme: {theme_name}")
if __name__ == "__main__":
generate_theme_comment()