-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathverify.py
More file actions
334 lines (284 loc) · 12.2 KB
/
Copy pathverify.py
File metadata and controls
334 lines (284 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
import sys
import os
import requests
from typing import Dict, List, Optional, Tuple
import base64
import re
from dotenv import load_dotenv
def _get_github_api(
endpoint: str, headers: Dict[str, str], org: str, repo: str = "claude-code"
) -> Tuple[bool, Optional[Dict]]:
"""Make a GET request to GitHub API and return (success, response)."""
url = f"https://api.github.com/repos/{org}/{repo}/{endpoint}"
try:
response = requests.get(url, headers=headers)
if response.status_code == 200:
return True, response.json()
elif response.status_code == 404:
return False, None
else:
print(f"API error for {endpoint}: {response.status_code}", file=sys.stderr)
return False, None
except Exception as e:
print(f"Exception for {endpoint}: {e}", file=sys.stderr)
return False, None
def _get_file_content(
file_path: str,
headers: Dict[str, str],
org: str,
repo: str = "claude-code",
ref: str = "main",
) -> Optional[str]:
"""Get the content of a file from the repository."""
success, result = _get_github_api(
f"contents/{file_path}?ref={ref}", headers, org, repo
)
if not success or not result:
return None
try:
content = base64.b64decode(result.get("content", "")).decode("utf-8")
return content
except Exception as e:
print(f"Content decode error for {file_path}: {e}", file=sys.stderr)
return None
def _verify_commit_exists(
commit_sha: str, headers: Dict[str, str], org: str, repo: str = "claude-code"
) -> Tuple[bool, Optional[Dict]]:
"""Verify that a commit exists and return its details."""
success, commit_data = _get_github_api(f"commits/{commit_sha}", headers, org, repo)
return success, commit_data
def _parse_feature_table(content: str) -> List[Dict]:
"""Parse the feature commit table from markdown content."""
features = []
lines = content.split("\n")
in_table = False
for line in lines:
# Look for table header
if (
"| Feature Name | Commit SHA | Author | Branch | Date | Files Changed | Commit Message |"
in line
):
in_table = True
continue
if in_table and line.startswith("|---"):
continue
# Parse table rows
if in_table and line.startswith("|"):
parts = [p.strip() for p in line.split("|")]
if len(parts) >= 8: # Should have 7 columns plus empty parts at start/end
feature_name = parts[1].strip()
commit_sha = parts[2].strip()
author = parts[3].strip()
branch = parts[4].strip()
date = parts[5].strip()
files_changed = parts[6].strip()
commit_message = parts[7].strip()
if feature_name and commit_sha and author and branch and date:
features.append(
{
"name": feature_name,
"sha": commit_sha,
"author": author,
"branch": branch,
"date": date,
"files_changed": files_changed,
"commit_message": commit_message,
}
)
# Stop at end of table section
if in_table and line and not line.startswith("|") and "##" in line:
break
return features
def verify_task() -> bool:
"""Verify the feature commit tracking task."""
# Load environment variables from .mcp_env
load_dotenv(".mcp_env")
# Get GitHub token and org
github_token = os.environ.get("MCP_GITHUB_TOKEN")
github_org = os.environ.get("GITHUB_EVAL_ORG")
if not github_token:
print("Error: MCP_GITHUB_TOKEN environment variable not set", file=sys.stderr)
return False
if not github_org:
print("Error: GITHUB_EVAL_ORG environment variable not set", file=sys.stderr)
return False
headers = {
"Authorization": f"Bearer {github_token}",
"Accept": "application/vnd.github.v3+json",
}
# Expected feature commits based on exploration
# For CHANGELOG Version 1.0.65, two valid answers exist:
# - 94dcaca5: merge commit that brought 1.0.65 into pr/2466-QwertyJack-main branch
# - 5faa082d: the actual commit that first added 1.0.65 content to CHANGELOG.md on main
expected_features = {
"Shell Completion Scripts": ["8a0febdd09bda32f38c351c0881784460d69997d"],
"CHANGELOG Version 1.0.65": [
"94dcaca5d71ad82644ae97f3a2b0c5eb8b63eae0",
"5faa082d6e4e5300485daafb94615fe133175055",
],
"Rust Extraction Improvements": ["50e58affdf1bfc7d875202bc040ebe0dcfb7d332"],
}
# Expected authors for each commit
expected_authors = {
"8a0febdd09bda32f38c351c0881784460d69997d": "gitmpr",
"94dcaca5d71ad82644ae97f3a2b0c5eb8b63eae0": "QwertyJack",
"5faa082d6e4e5300485daafb94615fe133175055": "actions-user",
"50e58affdf1bfc7d875202bc040ebe0dcfb7d332": "alokdangre",
}
# Expected commit messages for each commit
expected_messages = {
"8a0febdd09bda32f38c351c0881784460d69997d": "feat: add shell completions (bash, zsh, fish)",
"94dcaca5d71ad82644ae97f3a2b0c5eb8b63eae0": "Merge branch 'anthropics:main' into main",
"5faa082d6e4e5300485daafb94615fe133175055": "chore: Update CHANGELOG.md",
"50e58affdf1bfc7d875202bc040ebe0dcfb7d332": "Enhance Rust extraction and output handling in workflows",
}
# Expected dates for each commit (YYYY-MM-DD format)
expected_dates = {
"8a0febdd09bda32f38c351c0881784460d69997d": "2025-08-01",
"94dcaca5d71ad82644ae97f3a2b0c5eb8b63eae0": "2025-08-02",
"5faa082d6e4e5300485daafb94615fe133175055": "2025-07-31",
"50e58affdf1bfc7d875202bc040ebe0dcfb7d332": "2025-08-09",
}
print("Verifying feature commit tracking task...")
# 1. Check if FEATURE_COMMITS.md exists in main branch
print("1. Checking if FEATURE_COMMITS.md exists...")
content = _get_file_content("FEATURE_COMMITS.md", headers, github_org)
if not content:
print("Error: FEATURE_COMMITS.md not found in main branch", file=sys.stderr)
return False
print("✓ FEATURE_COMMITS.md found")
# 2. Check required sections exist
print("2. Checking required sections...")
required_sections = [
"# Feature Development Tracking",
"## Overview",
"## Feature Commit History",
]
for section in required_sections:
if section not in content:
print(f"Error: Missing required section '{section}'", file=sys.stderr)
return False
print("✓ All required sections present")
# 3. Parse and validate feature table
print("3. Parsing and validating feature table...")
features = _parse_feature_table(content)
if len(features) < 3:
print(
f"Error: Expected at least 3 features, found {len(features)}",
file=sys.stderr,
)
return False
# 4. Verify each expected feature is present with correct commit SHA
print("4. Verifying feature commit SHAs...")
found_features = {}
for feature in features:
found_features[feature["name"]] = feature["sha"]
for feature_name, expected_shas in expected_features.items():
if feature_name not in found_features:
print(
f"Error: Feature '{feature_name}' not found in table", file=sys.stderr
)
return False
actual_sha = found_features[feature_name]
if actual_sha not in expected_shas:
print(
f"Error: Wrong SHA for '{feature_name}'. Expected one of: {expected_shas}, Got: {actual_sha}",
file=sys.stderr,
)
return False
print("✓ All feature commit SHAs are correct")
# 5. Verify each commit exists and has correct author
print("5. Verifying commit details...")
all_expected_shas = set()
for shas in expected_features.values():
all_expected_shas.update(shas)
for feature in features:
if feature["sha"] in all_expected_shas:
success, commit_data = _verify_commit_exists(
feature["sha"], headers, github_org
)
if not success:
print(f"Error: Commit {feature['sha']} not found", file=sys.stderr)
return False
# Check author
expected_author = expected_authors.get(feature["sha"])
if expected_author:
actual_author = commit_data.get("author", {}).get("login", "")
if actual_author != expected_author:
print(
f"Error: Wrong author for {feature['sha']}. Expected: {expected_author}, Got: {actual_author}",
file=sys.stderr,
)
return False
# Check commit message (compare with table entry)
expected_message = expected_messages.get(feature["sha"])
if expected_message and "commit_message" in feature:
if feature["commit_message"] != expected_message:
print(
f"Error: Wrong commit message in table for {feature['sha']}. Expected: '{expected_message}', Got: '{feature['commit_message']}'",
file=sys.stderr,
)
return False
# Also verify against actual commit data
if expected_message:
actual_message = (
commit_data.get("commit", {}).get("message", "").split("\n")[0]
) # First line only
if actual_message != expected_message:
print(
f"Error: Wrong commit message for {feature['sha']}. Expected: '{expected_message}', Got: '{actual_message}'",
file=sys.stderr,
)
return False
# Check date format (YYYY-MM-DD)
if not re.match(r"^\d{4}-\d{2}-\d{2}$", feature["date"]):
print(
f"Error: Invalid date format for {feature['name']}: {feature['date']}",
file=sys.stderr,
)
return False
# Check actual date matches expected
expected_date = expected_dates.get(feature["sha"])
if expected_date:
if feature["date"] != expected_date:
print(
f"Error: Wrong date for {feature['sha']}. Expected: {expected_date}, Got: {feature['date']}",
file=sys.stderr,
)
return False
print("✓ All commit details verified")
# 6. Verify the table format is correct
print("6. Verifying table format...")
table_header = "| Feature Name | Commit SHA | Author | Branch | Date | Files Changed | Commit Message |"
if table_header not in content:
print("Error: Table header format is incorrect", file=sys.stderr)
return False
# Check that all features have complete information
for feature in features:
if not all(
[
feature["name"],
feature["sha"],
feature["author"],
feature["branch"],
feature["date"],
feature.get("commit_message", ""),
]
):
print(
f"Error: Incomplete information for feature: {feature['name']}",
file=sys.stderr,
)
return False
print("✓ Table format is correct and complete")
print("\n✅ All verification checks passed!")
print("Feature commit tracking completed successfully:")
print(" - File: FEATURE_COMMITS.md created in main branch")
print(f" - Features tracked: {len(features)}")
print(" - All expected commit SHAs verified")
print(" - All commit authors verified")
print(" - Analysis summary complete")
return True
if __name__ == "__main__":
success = verify_task()
sys.exit(0 if success else 1)