1+ import sys
2+ import os
3+ import requests
4+ from typing import Dict , Optional , Tuple
5+ import base64
6+ from dotenv import load_dotenv
7+
8+
9+ def _get_github_api (
10+ endpoint : str , headers : Dict [str , str ], org : str , repo : str = "build-your-own-x"
11+ ) -> Tuple [bool , Optional [Dict ]]:
12+ """Make a GET request to GitHub API and return (success, response)."""
13+ url = f"https://api.github.com/repos/{ org } /{ repo } /{ endpoint } "
14+ try :
15+ response = requests .get (url , headers = headers )
16+ if response .status_code == 200 :
17+ return True , response .json ()
18+ elif response .status_code == 404 :
19+ return False , None
20+ else :
21+ print (f"API error for { endpoint } : { response .status_code } " , file = sys .stderr )
22+ return False , None
23+ except Exception as e :
24+ print (f"Exception for { endpoint } : { e } " , file = sys .stderr )
25+ return False , None
26+
27+
28+ def _get_file_content (
29+ file_path : str ,
30+ headers : Dict [str , str ],
31+ org : str ,
32+ repo : str = "build-your-own-x" ,
33+ ref : str = "master" ,
34+ ) -> Optional [str ]:
35+ """Get the content of a file from the repository."""
36+ success , result = _get_github_api (
37+ f"contents/{ file_path } ?ref={ ref } " , headers , org , repo
38+ )
39+ if not success or not result :
40+ return None
41+
42+ try :
43+ content = base64 .b64decode (result .get ("content" , "" )).decode ("utf-8" )
44+ return content
45+ except Exception as e :
46+ print (f"Content decode error for { file_path } : { e } " , file = sys .stderr )
47+ return None
48+
49+
50+ def verify_task () -> bool :
51+ """Verify the find commit data task for Voxel Engine entries."""
52+ # Load environment variables from .mcp_env
53+ load_dotenv (".mcp_env" )
54+
55+ # Get GitHub token and org
56+ github_token = os .environ .get ("MCP_GITHUB_TOKEN" )
57+ github_org = os .environ .get ("GITHUB_EVAL_ORG" )
58+
59+ if not github_token :
60+ print ("Error: MCP_GITHUB_TOKEN environment variable not set" , file = sys .stderr )
61+ return False
62+
63+ if not github_org :
64+ print ("Error: GITHUB_EVAL_ORG environment variable not set" , file = sys .stderr )
65+ return False
66+
67+ headers = {
68+ "Authorization" : f"Bearer { github_token } " ,
69+ "Accept" : "application/vnd.github.v3+json" ,
70+ }
71+
72+ print ("Verifying Voxel Engine commit date task..." )
73+
74+ # 1. Check if ANSWER.md exists in the repository
75+ print ("1. Checking if ANSWER.md exists..." )
76+ content = _get_file_content ("ANSWER.md" , headers , github_org )
77+ if not content :
78+ print ("Error: ANSWER.md not found in repository" , file = sys .stderr )
79+ return False
80+ print ("✓ ANSWER.md found" )
81+
82+ # 2. Check the content format
83+ print ("2. Checking content format..." )
84+ content = content .strip ()
85+
86+ # The expected date when Daniel Stefanovic added Voxel Engine entries
87+ # Based on historical records, this should be 2018-07-07
88+ expected_date = "2018-07-07"
89+
90+ # Check if the content matches the expected date format (YYYY-MM-DD)
91+ import re
92+ date_pattern = r'^\d{4}-\d{2}-\d{2}$'
93+ if not re .match (date_pattern , content ):
94+ print (f"Error: Invalid date format. Expected YYYY-MM-DD, got: { content } " , file = sys .stderr )
95+ return False
96+ print ("✓ Date format is correct" )
97+
98+ # 3. Verify the date is correct
99+ print ("3. Verifying the date..." )
100+ if content != expected_date :
101+ print (f"Error: Incorrect date. Expected { expected_date } , got: { content } " , file = sys .stderr )
102+ return False
103+ print (f"✓ Date is correct: { content } " )
104+
105+ # 4. Verify README.md contains Voxel Engine section
106+ print ("4. Checking if README.md contains Voxel Engine section..." )
107+ readme_content = _get_file_content ("README.md" , headers , github_org )
108+ if not readme_content :
109+ print ("Error: README.md not found in repository" , file = sys .stderr )
110+ return False
111+
112+ if "Voxel Engine" not in readme_content :
113+ print ("Error: Voxel Engine section not found in README.md" , file = sys .stderr )
114+ return False
115+
116+ # Check for specific Voxel Engine entries
117+ voxel_entries = [
118+ "Let's Make a Voxel Engine" ,
119+ "Java Voxel Engine Tutorial"
120+ ]
121+
122+ for entry in voxel_entries :
123+ if entry not in readme_content :
124+ print (f"Warning: Voxel Engine entry '{ entry } ' not found in README.md" , file = sys .stderr )
125+
126+ print ("✓ Voxel Engine section found in README.md" )
127+
128+ print ("\n ✅ All verification checks passed!" )
129+ print ("Task completed successfully:" )
130+ print (f" - ANSWER.md created with date: { content } " )
131+ print (" - Date format is correct (YYYY-MM-DD)" )
132+ print (" - Date matches expected creation date for Voxel Engine entries by Daniel Stefanovic" )
133+ print (" - Voxel Engine section exists in README.md" )
134+
135+ return True
136+
137+
138+ if __name__ == "__main__" :
139+ success = verify_task ()
140+ sys .exit (0 if success else 1 )
0 commit comments