Check if a commit only contains SPDX header changes.
(self, commit_hash: str)
| 196 | return {} |
| 197 | |
| 198 | def _is_spdx_only_commit(self, commit_hash: str) -> bool: |
| 199 | """Check if a commit only contains SPDX header changes.""" |
| 200 | try: |
| 201 | # Get commit message |
| 202 | result = subprocess.run( |
| 203 | ["git", "show", "-s", "--format=%s%n%b", commit_hash], |
| 204 | capture_output=True, |
| 205 | text=True, |
| 206 | cwd=self.repo_root, |
| 207 | ) |
| 208 | |
| 209 | if result.returncode != 0: |
| 210 | return False |
| 211 | |
| 212 | commit_message = result.stdout.lower() |
| 213 | |
| 214 | # Check for SPDX-related keywords in commit message |
| 215 | spdx_keywords = [ |
| 216 | "spdx", |
| 217 | "license header", |
| 218 | "copyright header", |
| 219 | "add license", |
| 220 | "update license", |
| 221 | "license annotation", |
| 222 | "reuse annotate", |
| 223 | "add spdx", |
| 224 | "update spdx", |
| 225 | "copyright attribution", |
| 226 | ] |
| 227 | |
| 228 | if any(keyword in commit_message for keyword in spdx_keywords): |
| 229 | # Get the diff to see if it's only header changes |
| 230 | diff_result = subprocess.run( |
| 231 | ["git", "show", "--format=", commit_hash], |
| 232 | capture_output=True, |
| 233 | text=True, |
| 234 | cwd=self.repo_root, |
| 235 | ) |
| 236 | |
| 237 | if diff_result.returncode == 0: |
| 238 | diff_content = diff_result.stdout |
| 239 | |
| 240 | # Check if the diff only contains SPDX/copyright/license changes |
| 241 | # Look for lines that are only adding/removing headers |
| 242 | diff_lines = diff_content.split("\n") |
| 243 | substantial_changes = 0 |
| 244 | |
| 245 | for line in diff_lines: |
| 246 | if line.startswith(("+", "-")) and not line.startswith( |
| 247 | ("+++", "---") |
| 248 | ): |
| 249 | # Skip lines that are just SPDX/copyright/license related |
| 250 | line_content = line[1:].strip() |
| 251 | if line_content and not any( |
| 252 | marker in line_content.lower() |
| 253 | for marker in [ |
| 254 | "spdx-", |
| 255 | "copyright", |