11import re
2- from typing import Dict , Optional , List , Union
2+ from typing import Dict , Optional , List
33from rsmetacheck .utils .pitfall_utils import normalize_version
44from rsmetacheck .utils .pitfall_utils import extract_metadata_source_filename
55
@@ -95,15 +95,15 @@ def extract_latest_release_version(somef_data: Dict) -> Optional[str]:
9595
9696 return None
9797
98+
9899def detect_version_mismatch (somef_data : Dict , file_name : str ) -> list :
99100 """
100101 Detect version mismatches between metadata files and the latest release.
101- Checks all metadata files and returns one result dict per metadata source
102- that has an inconsistency.
102+ Returns a single result with all mismatched sources merged into one evidence message.
103103
104104 - Metadata version > release by >= 2 in any component: pitfall
105- - Metadata version > release by < 2: note (best practice to prepare ahead)
106- - Metadata version < release: pitfall (metadata was not updated)
105+ - Metadata version > release by < 2: note
106+ - Metadata version < release: pitfall
107107 - Metadata version == release: no issue
108108 """
109109 metadata_versions = extract_version_from_metadata (somef_data )
@@ -113,7 +113,10 @@ def detect_version_mismatch(somef_data: Dict, file_name: str) -> list:
113113 return []
114114
115115 normalized_release_version = normalize_version (release_version )
116- results = []
116+
117+ pitfall_sources = []
118+ note_sources = []
119+ all_mismatches = []
117120
118121 for md_info in metadata_versions :
119122 metadata_version = normalize_version (md_info ["version" ])
@@ -122,48 +125,56 @@ def detect_version_mismatch(somef_data: Dict, file_name: str) -> list:
122125 if metadata_version == normalized_release_version :
123126 continue
124127
128+ all_mismatches .append ({
129+ "source_file" : metadata_source_file ,
130+ "source" : md_info ["source" ],
131+ "metadata_version" : metadata_version ,
132+ })
133+
125134 if _metadata_ahead_of_release (metadata_version , normalized_release_version ):
126135 if _version_diff_significant (metadata_version , normalized_release_version ):
127- results .append ({
128- "has_pitfall" : True ,
129- "has_note" : False ,
130- "file_name" : file_name ,
131- "metadata_version" : metadata_version ,
132- "release_version" : normalized_release_version ,
133- "metadata_source" : md_info ["source" ],
134- "metadata_source_file" : metadata_source_file ,
135- "note_text" : None ,
136- "notes" : []
137- })
136+ pitfall_sources .append (metadata_source_file )
138137 else :
139- note_text = f"Version discrepancy: { metadata_source_file } version '{ metadata_version } ' is ahead of release version '{ normalized_release_version } '"
140- results .append ({
141- "has_pitfall" : False ,
142- "has_note" : True ,
143- "file_name" : file_name ,
144- "metadata_version" : metadata_version ,
145- "release_version" : normalized_release_version ,
146- "metadata_source" : md_info ["source" ],
147- "metadata_source_file" : metadata_source_file ,
148- "note_text" : note_text ,
149- "notes" : [{
150- "metadata_source_file" : metadata_source_file ,
151- "metadata_version" : metadata_version ,
152- "release_version" : normalized_release_version ,
153- "note_text" : note_text
154- }]
155- })
138+ note_sources .append (metadata_source_file )
156139 else :
157- results .append ({
158- "has_pitfall" : True ,
159- "has_note" : False ,
160- "file_name" : file_name ,
161- "metadata_version" : metadata_version ,
140+ pitfall_sources .append (metadata_source_file )
141+
142+ if not all_mismatches :
143+ return []
144+
145+ has_any_pitfall = len (pitfall_sources ) > 0
146+ has_any_note = len (note_sources ) > 0
147+
148+ all_source_files = [m ["source_file" ] for m in all_mismatches ]
149+
150+ # Build notes for any ahead-by-small-amount sources
151+ notes = []
152+ note_text = None
153+ for m in all_mismatches :
154+ m_version = m ["metadata_version" ]
155+ if _metadata_ahead_of_release (m_version , normalized_release_version ) and not _version_diff_significant (m_version , normalized_release_version ):
156+ text = f"Version discrepancy: { m ['source_file' ]} version '{ m_version } ' is ahead of release version '{ normalized_release_version } '"
157+ notes .append ({
158+ "metadata_source_file" : m ["source_file" ],
159+ "metadata_version" : m_version ,
162160 "release_version" : normalized_release_version ,
163- "metadata_source" : md_info ["source" ],
164- "metadata_source_file" : metadata_source_file ,
165- "note_text" : None ,
166- "notes" : []
161+ "note_text" : text
167162 })
168-
169- return results
163+ if note_text is None :
164+ note_text = text
165+
166+ result = {
167+ "has_pitfall" : has_any_pitfall ,
168+ "has_note" : (not has_any_pitfall and has_any_note ),
169+ "file_name" : file_name ,
170+ "mismatched_sources" : all_mismatches ,
171+ "metadata_source_files" : all_source_files ,
172+ "release_version" : normalized_release_version ,
173+ "note_text" : note_text ,
174+ "notes" : notes ,
175+ "metadata_version" : all_mismatches [0 ]["metadata_version" ] if all_mismatches else None ,
176+ "metadata_source_file" : all_mismatches [0 ]["source_file" ] if all_mismatches else None ,
177+ "metadata_source" : all_mismatches [0 ]["source" ] if all_mismatches else None ,
178+ }
179+
180+ return [result ]
0 commit comments