File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -92,9 +92,33 @@ def main():
9292    print (generated_code )
9393    print ("=== GENERATED DIFF END ===" )
9494
95-     # Write the diff to a temporary file 
95+     # Filter out lines that are not part of a valid unified diff 
96+     diff_lines  =  []
97+     in_diff  =  False 
98+     for  line  in  generated_code .splitlines ():
99+         if  line .startswith ('--- ' ) or  line .startswith ('+++ ' ):
100+             in_diff  =  True 
101+         if  in_diff :
102+             # Only allow valid diff lines or context lines 
103+             if  (
104+                 line .startswith ('--- ' ) or  line .startswith ('+++ ' ) or 
105+                 line .startswith ('@@' ) or 
106+                 line .startswith ('+' ) or 
107+                 line .startswith ('-' ) or 
108+                 line .startswith (' ' ) or 
109+                 line .strip () ==  '' 
110+             ):
111+                 diff_lines .append (line )
112+     # Join the filtered lines 
113+     filtered_diff  =  '\n ' .join (diff_lines )
114+ 
115+     if  not  filtered_diff .strip ().startswith ('---' ):
116+         print ("::error::OpenAI did not return a valid unified diff." , file = sys .stderr )
117+         sys .exit (1 )
118+ 
119+     # Write the filtered diff to a temporary file 
96120    with  tempfile .NamedTemporaryFile (mode = 'w+' , delete = False ) as  tmp_patch :
97-         tmp_patch .write (generated_code )
121+         tmp_patch .write (filtered_diff )
98122        tmp_patch_path  =  tmp_patch .name 
99123
100124    # Apply the patch 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments