@@ -68,62 +68,35 @@ def get_changed_files(repo_root):
6868 return []
6969
7070def extract_changed_sql_queries (file_path , base_commit , current_commit ):
71- """Extract only the SQL code blocks that were added/ modified in the git diff"""
71+ """Extract SQL code blocks that were added or modified in the git diff"""
7272 try :
7373 # Get the git diff for this specific file
7474 diff_cmd = ["git" , "diff" , f"{ base_commit } ...{ current_commit } " , "--" , file_path ]
7575 result = subprocess .run (diff_cmd , capture_output = True , text = True , cwd = get_repo_root ())
7676
7777 if result .returncode != 0 :
7878 print (f"::warning::Could not get git diff for { file_path } " )
79- return []
79+ return extract_sql_queries ( file_path ) # Fallback to all queries
8080
8181 diff_content = result .stdout
8282
83- # Extract added SQL blocks from the diff
84- added_sql_queries = []
83+ # Simple approach: if there are any changes in the file and it contains SQL blocks,
84+ # validate all SQL blocks in the current version of the file
85+ # This is more reliable than trying to parse complex diff output
8586
86- # Look for lines that start with + and contain SQL code blocks
87- lines = diff_content .split ('\n ' )
88- i = 0
89- while i < len (lines ):
90- line = lines [i ]
91-
92- # Check if this is an added line with SQL code block start
93- if line .startswith ('+' ) and ('```sql' in line .lower () or '```sumo' in line .lower ()):
94- # Found start of an added SQL block
95- sql_lines = []
96- i += 1
97-
98- # Collect all lines until we find the closing ```
99- while i < len (lines ):
100- current_line = lines [i ]
101-
102- # If it's a closing ``` on an added line, we're done
103- if current_line .startswith ('+' ) and '```' in current_line and current_line .strip () == '+```' :
104- break
105-
106- # If it's an added line with SQL content, add it
107- if current_line .startswith ('+' ):
108- # Remove the + prefix and add to SQL content
109- sql_content = current_line [1 :] # Remove the '+' prefix
110- sql_lines .append (sql_content )
111-
112- i += 1
113-
114- # Join the SQL lines and clean up
115- if sql_lines :
116- sql_query = '\n ' .join (sql_lines ).strip ()
117- if sql_query and not sql_query .startswith ('#' ) and not sql_query .startswith ('//' ):
118- added_sql_queries .append (sql_query )
119-
120- i += 1
87+ has_changes = any (line .startswith (('+' , '-' )) for line in diff_content .split ('\n ' )
88+ if line .strip () and not line .startswith (('+++' , '---' )))
12189
122- return added_sql_queries
90+ if has_changes :
91+ # File has changes, extract all current SQL queries for validation
92+ return extract_sql_queries (file_path )
93+
94+ return []
12395
12496 except Exception as e :
12597 print (f"::error::Error extracting changed SQL queries from { file_path } : { e } " )
126- return []
98+ # Fallback to extracting all SQL queries from the file
99+ return extract_sql_queries (file_path )
127100
128101def extract_sql_queries (file_path ):
129102 """Extract SQL code blocks from markdown files (fallback method)"""
0 commit comments