Get git diff with full content since the previous version.
(previous_version: Optional[str])
| 104 | |
| 105 | |
| 106 | def get_git_diff_since_version(previous_version: Optional[str]) -> str: |
| 107 | """Get git diff with full content since the previous version.""" |
| 108 | if previous_version: |
| 109 | try: |
| 110 | # Get commit messages and full diff since the previous tag |
| 111 | print(f"🔍 Analyzing changes since v{previous_version}...") |
| 112 | |
| 113 | # First get the commit log |
| 114 | commits_cmd = f"git log v{previous_version}..HEAD --oneline --no-merges" |
| 115 | commits_output = run_cmd(commits_cmd, capture_output=True, check=False) |
| 116 | |
| 117 | # Then get the actual diff content (limit to avoid overwhelming output) |
| 118 | diff_cmd = ( |
| 119 | f"git diff v{previous_version}..HEAD --no-merges --stat --summary" |
| 120 | ) |
| 121 | diff_summary = run_cmd(diff_cmd, capture_output=True, check=False) |
| 122 | |
| 123 | # Get more detailed diff for key files (exclude large generated files and release notes) |
| 124 | # Limit to 300 lines to keep Claude prompts manageable |
| 125 | detailed_diff_cmd = f"git diff v{previous_version}..HEAD --no-merges -- '*.py' '*.ts' '*.tsx' '*.js' '*.md' '*.yml' '*.yaml' '*.json' '*.toml' ':!releases/'" |
| 126 | detailed_diff_raw = run_cmd( |
| 127 | detailed_diff_cmd, capture_output=True, check=False |
| 128 | ) |
| 129 | |
| 130 | # Limit detailed diff to 300 lines |
| 131 | if detailed_diff_raw: |
| 132 | lines = detailed_diff_raw.split("\n") |
| 133 | if len(lines) > 300: |
| 134 | detailed_diff = ( |
| 135 | "\n".join(lines[:300]) |
| 136 | + f"\n\n... (truncated {len(lines) - 300} lines for brevity)" |
| 137 | ) |
| 138 | else: |
| 139 | detailed_diff = detailed_diff_raw |
| 140 | else: |
| 141 | detailed_diff = detailed_diff_raw |
| 142 | |
| 143 | if commits_output: |
| 144 | result = f"""COMMIT MESSAGES: |
| 145 | {commits_output} |
| 146 | |
| 147 | DIFF SUMMARY: |
| 148 | {diff_summary or 'No summary available'} |
| 149 | |
| 150 | DETAILED CHANGES (Python, TypeScript, configs, docs): |
| 151 | {detailed_diff or 'No detailed changes available'}""" |
| 152 | return result |
| 153 | elif commits_output: |
| 154 | return f"COMMIT MESSAGES:\n{commits_output}" |
| 155 | except Exception as e: |
| 156 | print(f"⚠️ Error getting diff since {previous_version}: {e}") |
| 157 | |
| 158 | # Fallback: get recent commits and diff |
| 159 | try: |
| 160 | print("🔍 Analyzing recent changes (last 20 commits)...") |
| 161 | |
| 162 | # Get recent commit messages |
| 163 | commits_cmd = "git log --oneline --no-merges -20" |
no test coverage detected