55from datetime import datetime
66import html
77
8+
89def 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+
138146if __name__ == "__main__" :
139- main ()
147+ main ()
0 commit comments