@@ -47,20 +47,31 @@ def get_existing_comment_id(pr_number: int) -> str | None:
4747 exit_code , stdout , stderr = run_command (cmd )
4848
4949 if exit_code != 0 :
50- raise Exception (f"Failed to get PR comments: { stderr } " )
50+ print (f"Warning: Failed to get PR comments: { stderr } " )
51+ return None
5152
5253 try :
5354 pr_data = json .loads (stdout )
5455 comments = pr_data .get ("comments" , [])
5556
5657 # Look for comments with our signature
57- for comment in comments :
58- if "This comment was automatically generated by the release preview workflow" in comment .get ("body" , "" ):
59- return comment .get ("id" )
58+ signature = "This comment was automatically generated by the release preview workflow"
6059
60+ for comment in comments :
61+ comment_body = comment .get ("body" , "" )
62+ # Also check for release preview header as backup
63+ if (signature in comment_body or
64+ "📦 Release Preview" in comment_body ):
65+ comment_id = comment .get ("id" )
66+ if comment_id :
67+ print (f"Found existing comment with ID: { comment_id } " )
68+ return str (comment_id )
69+
70+ print ("No existing release preview comment found" )
6171 return None
6272 except json .JSONDecodeError as e :
63- raise Exception (f"Failed to parse PR comments JSON: { e } " ) from e
73+ print (f"Warning: Failed to parse PR comments JSON: { e } " )
74+ return None
6475
6576
6677def get_release_preview () -> str :
@@ -135,18 +146,31 @@ def create_or_update_comment(pr_number: int, comment_body: str) -> None:
135146 existing_comment_id = get_existing_comment_id (pr_number )
136147
137148 if existing_comment_id :
138- # Update existing comment
149+ print (f"Found existing comment { existing_comment_id } , attempting to update..." )
150+
151+ # Try to update existing comment
139152 cmd = ["gh" , "api" , f"repos/{{owner}}/{{repo}}/issues/comments/{ existing_comment_id } " ,
140153 "--method" , "PATCH" , "--field" , f"body=@{ temp_file } " ]
141154
142155 exit_code , stdout , stderr = run_command (cmd )
143156
144157 if exit_code != 0 :
145- raise Exception (f"Failed to update comment: { stderr } " )
158+ print (f"Failed to update existing comment (it may have been deleted): { stderr } " )
159+ print ("Creating new comment instead..." )
160+
161+ # Fall back to creating a new comment
162+ cmd = ["gh" , "pr" , "comment" , str (pr_number ), "--body-file" , temp_file ]
163+ exit_code , stdout , stderr = run_command (cmd )
164+
165+ if exit_code != 0 :
166+ raise Exception (f"Failed to create comment: { stderr } " )
146167
147- print (f"Updated existing comment { existing_comment_id } " )
168+ print ("Created new comment" )
169+ else :
170+ print (f"Updated existing comment { existing_comment_id } " )
148171 else :
149172 # Create new comment using gh pr comment
173+ print ("No existing comment found, creating new comment..." )
150174 cmd = ["gh" , "pr" , "comment" , str (pr_number ), "--body-file" , temp_file ]
151175
152176 exit_code , stdout , stderr = run_command (cmd )
0 commit comments