| 
13 | 13 | # Utility Functions  | 
14 | 14 | # =============================================================================  | 
15 | 15 | 
 
  | 
 | 16 | +def create_data_uri_from_file(image_path):  | 
 | 17 | +    """Read an image file and convert to base64 data URI"""  | 
 | 18 | +    if not os.path.exists(image_path):  | 
 | 19 | +        print(f"⚠️ Image file not found: {image_path}")  | 
 | 20 | +        return None  | 
 | 21 | +      | 
 | 22 | +    try:  | 
 | 23 | +        with open(image_path, 'rb') as f:  | 
 | 24 | +            image_data = f.read()  | 
 | 25 | +          | 
 | 26 | +        # Encode to base64  | 
 | 27 | +        b64_data = base64.b64encode(image_data).decode('utf-8')  | 
 | 28 | +          | 
 | 29 | +        # Determine mime type from extension  | 
 | 30 | +        ext = Path(image_path).suffix.lower()  | 
 | 31 | +        mime_type = 'image/png' if ext == '.png' else 'image/jpeg' if ext in ['.jpg', '.jpeg'] else 'image/png'  | 
 | 32 | +          | 
 | 33 | +        data_uri = f"data:{mime_type};base64,{b64_data}"  | 
 | 34 | +          | 
 | 35 | +        print(f"✅ Created data URI for {image_path} (size: {len(data_uri)} chars)")  | 
 | 36 | +        return data_uri  | 
 | 37 | +    except Exception as e:  | 
 | 38 | +        print(f"❌ Failed to create data URI for {image_path}: {e}")  | 
 | 39 | +        return None  | 
 | 40 | + | 
16 | 41 | def parse_repository(repository):  | 
17 | 42 |     """Parse repository string into owner and name"""  | 
18 | 43 |     try:  | 
@@ -154,7 +179,7 @@ def find_line_number_of_change(original_content, old_value):  | 
154 | 179 | # GitHub PR Comment Functions  | 
155 | 180 | # =============================================================================  | 
156 | 181 | 
 
  | 
157 |  | -def create_pr_suggestion(repo_owner, repo_name, pr_number, calibration_file, xml_file, line_number, suggested_line, head_sha, github_token, artifacts_url=''):  | 
 | 182 | +def create_pr_suggestion(repo_owner, repo_name, pr_number, calibration_file, xml_file, line_number, suggested_line, head_sha, github_token, before_images=None, after_images=None, artifacts_url=''):  | 
158 | 183 |     """Create a PR comment with proposed changes"""  | 
159 | 184 |     print(f"Creating PR comment with calibration update for #{pr_number}...")  | 
160 | 185 | 
 
  | 
@@ -196,9 +221,31 @@ def create_pr_suggestion(repo_owner, repo_name, pr_number, calibration_file, xml  | 
196 | 221 | 
  | 
197 | 222 | Please update the calibration URL in `{xml_file}` at line {line_number}."""  | 
198 | 223 | 
 
  | 
199 |  | -    # Add artifacts link if provided  | 
 | 224 | +    # Convert image file paths to data URIs and embed  | 
 | 225 | +    if before_images:  | 
 | 226 | +        comment_body += "\n\n---\n\n### 📊 Before Calibration Update\n\n"  | 
 | 227 | +        for img_path in before_images:  | 
 | 228 | +            data_uri = create_data_uri_from_file(img_path)  | 
 | 229 | +            if data_uri:  | 
 | 230 | +                comment_body += f"\n\n"  | 
 | 231 | + | 
 | 232 | +    if after_images:  | 
 | 233 | +        comment_body += "\n\n---\n\n### ✨ After Calibration Update\n\n"  | 
 | 234 | +        for img_path in after_images:  | 
 | 235 | +            data_uri = create_data_uri_from_file(img_path)  | 
 | 236 | +            if data_uri:  | 
 | 237 | +                comment_body += f"\n\n"  | 
 | 238 | +      | 
 | 239 | +    # Add artifacts URL link if provided  | 
200 | 240 |     if artifacts_url:  | 
201 |  | -        comment_body += f"\n\n---\n\n### 📊 Review Results\n\nPlease review the artifacts here: {artifacts_url}"  | 
 | 241 | +        comment_body += f"\n\n---\n\n📁 For comprehensive results and full-resolution artifacts, please visit: [{artifacts_url}]({artifacts_url})\n\n"  | 
 | 242 | +      | 
 | 243 | +    # Check total comment size  | 
 | 244 | +    comment_size = len(comment_body)  | 
 | 245 | +    print(f"Total comment size: {comment_size} characters")  | 
 | 246 | +    if comment_size > 65536:  | 
 | 247 | +        print(f"⚠️ WARNING: Comment exceeds GitHub's 65KB limit by {comment_size - 65536} characters!")  | 
 | 248 | +        print("   Consider further compressing images or reducing resolution.")  | 
202 | 249 | 
 
  | 
203 | 250 |     # Create or update comment via GitHub REST API (no gh CLI)  | 
204 | 251 |     if existing_comment_id:  | 
 | 
0 commit comments