Skip to content

Commit 5727024

Browse files
Copilotcommjoen
andcommitted
Fix Black formatting issues in Python scripts
Co-authored-by: commjoen <[email protected]>
1 parent 2a8e2ea commit 5727024

File tree

2 files changed

+57
-38
lines changed

2 files changed

+57
-38
lines changed

.github/scripts/remove_pr_from_index.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,54 @@
44
import os
55
from datetime import datetime
66

7+
78
def main():
8-
pr_number = os.environ.get('PR_NUMBER', 'unknown')
9+
pr_number = os.environ.get("PR_NUMBER", "unknown")
910

1011
try:
11-
with open('/tmp/cleaned-site/index.html', 'r') as f:
12+
with open("/tmp/cleaned-site/index.html", "r") as f:
1213
content = f.read()
13-
14+
1415
# Remove the PR card for this specific PR number
15-
card_pattern = f'<div class="pr-card"[^>]*data-pr="{pr_number}"[^>]*>.*?</div>\s*</div>'
16-
updated_content = re.sub(card_pattern, '', content, flags=re.DOTALL)
17-
16+
card_pattern = (
17+
f'<div class="pr-card"[^>]*data-pr="{pr_number}"[^>]*>.*?</div>\s*</div>'
18+
)
19+
updated_content = re.sub(card_pattern, "", content, flags=re.DOTALL)
20+
1821
# Check if there are any remaining PR cards
19-
remaining_cards = re.findall(r'<div class="pr-card"[^>]*data-pr="[^"]*"[^>]*>', updated_content)
20-
22+
remaining_cards = re.findall(
23+
r'<div class="pr-card"[^>]*data-pr="[^"]*"[^>]*>', updated_content
24+
)
25+
2126
if not remaining_cards:
2227
# No remaining PRs, add a "no previews" message
2328
no_previews_html = """ <div class="no-previews" style="text-align: center; color: #666; font-style: italic; grid-column: 1 / -1;">
2429
No active PR previews available
2530
</div>"""
26-
31+
2732
# Replace any existing content in the grid
2833
grid_pattern = r'(<div class="pr-grid">)(.*?)(</div>\s*</div>\s*<div style="text-align: center)'
29-
updated_content = re.sub(grid_pattern, r'\1\n' + no_previews_html + r'\n \3', updated_content, flags=re.DOTALL)
30-
34+
updated_content = re.sub(
35+
grid_pattern,
36+
r"\1\n" + no_previews_html + r"\n \3",
37+
updated_content,
38+
flags=re.DOTALL,
39+
)
40+
3141
# Update the last updated timestamp
32-
timestamp_pattern = r'Last updated: [^<•]*'
42+
timestamp_pattern = r"Last updated: [^<•]*"
3343
new_timestamp = f'Last updated: {datetime.now().strftime("%Y-%m-%d %H:%M UTC")}'
3444
updated_content = re.sub(timestamp_pattern, new_timestamp, updated_content)
35-
36-
with open('/tmp/cleaned-site/index.html', 'w') as f:
45+
46+
with open("/tmp/cleaned-site/index.html", "w") as f:
3747
f.write(updated_content)
38-
48+
3949
print(f"Successfully removed PR #{pr_number} from index")
40-
50+
4151
except Exception as e:
4252
print(f"Error updating index: {e}")
4353
# Don't fail the cleanup if index update fails
4454

55+
4556
if __name__ == "__main__":
46-
main()
57+
main()

.github/scripts/update_pr_index.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
from datetime import datetime
66
import html
77

8+
89
def main():
910
# Get environment variables
10-
pr_number = os.environ.get('PR_NUMBER', 'unknown')
11-
pr_title = os.environ.get('PR_TITLE', 'Unknown PR')
12-
pr_sha = os.environ.get('PR_SHA', 'unknown')
13-
existing_index_file = os.environ.get('EXISTING_INDEX', '')
11+
pr_number = os.environ.get("PR_NUMBER", "unknown")
12+
pr_title = os.environ.get("PR_TITLE", "Unknown PR")
13+
pr_sha = os.environ.get("PR_SHA", "unknown")
14+
existing_index_file = os.environ.get("EXISTING_INDEX", "")
1415

1516
# Escape HTML characters in PR title
1617
pr_title_escaped = html.escape(pr_title.strip())
@@ -26,7 +27,8 @@ def main():
2627
</div>"""
2728

2829
# Base HTML template
29-
base_html = """<!DOCTYPE html>
30+
base_html = (
31+
"""<!DOCTYPE html>
3032
<html lang="en">
3133
<head>
3234
<meta charset="UTF-8">
@@ -85,55 +87,61 @@ def main():
8587
<a href="https://github.com/OWASP/wrongsecrets" target="_blank">View Repository</a> |
8688
<a href="https://github.com/OWASP/wrongsecrets/pulls" target="_blank">All Pull Requests</a>
8789
</p>
88-
<small>Generated by GitHub Actions • Last updated: """ + datetime.now().strftime("%Y-%m-%d %H:%M UTC") + """</small>
90+
<small>Generated by GitHub Actions • Last updated: """
91+
+ datetime.now().strftime("%Y-%m-%d %H:%M UTC")
92+
+ """</small>
8993
</div>
9094
</div>
9195
</body>
9296
</html>"""
97+
)
9398

9499
try:
95100
# Try to read existing index
96101
if existing_index_file and os.path.exists(existing_index_file):
97-
with open(existing_index_file, 'r') as f:
102+
with open(existing_index_file, "r") as f:
98103
existing_content = f.read()
99-
104+
100105
# Extract existing PR cards
101106
card_pattern = r'<div class="pr-card"[^>]*>.*?</div>\s*</div>'
102107
existing_cards = re.findall(card_pattern, existing_content, re.DOTALL)
103-
108+
104109
# Remove the current PR card if it exists
105110
filtered_cards = []
106111
for card in existing_cards:
107112
if f'data-pr="{pr_number}"' not in card:
108113
filtered_cards.append(card)
109-
114+
110115
# Add current PR card at the beginning
111116
all_cards = [pr_card_template] + filtered_cards
112-
117+
113118
else:
114119
# No existing index, start fresh
115120
all_cards = [pr_card_template]
116121

117122
# Generate final HTML
118123
if all_cards:
119-
cards_html = '\n'.join(all_cards)
124+
cards_html = "\n".join(all_cards)
120125
else:
121126
cards_html = ' <div class="no-previews">No active PR previews</div>'
122-
123-
final_html = base_html.replace('<!-- PR_CARDS_PLACEHOLDER -->', cards_html)
124-
125-
with open('static-site/index.html', 'w') as f:
127+
128+
final_html = base_html.replace("<!-- PR_CARDS_PLACEHOLDER -->", cards_html)
129+
130+
with open("static-site/index.html", "w") as f:
126131
f.write(final_html)
127-
132+
128133
print(f"Successfully updated index with PR #{pr_number}")
129-
134+
130135
except Exception as e:
131136
print(f"Error updating index: {e}")
132137
# Fallback to simple index
133-
fallback_html = base_html.replace('<!-- PR_CARDS_PLACEHOLDER -->', pr_card_template)
134-
with open('static-site/index.html', 'w') as f:
138+
fallback_html = base_html.replace(
139+
"<!-- PR_CARDS_PLACEHOLDER -->", pr_card_template
140+
)
141+
with open("static-site/index.html", "w") as f:
135142
f.write(fallback_html)
136143
print("Created fallback index")
137144

145+
138146
if __name__ == "__main__":
139-
main()
147+
main()

0 commit comments

Comments
 (0)