From 0b4dbf65372f5689bd9efffb85e92d96ca38d485 Mon Sep 17 00:00:00 2001 From: Yankyyyy Date: Fri, 22 Aug 2025 06:30:19 +0000 Subject: [PATCH] bug: timezone conversion missing issue fix --- .../repository_member/repository_member.json | 9 +--- erpnext_github_integration/github_api.py | 42 +++++++++++++------ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/erpnext_github_integration/erpnext_github_integration/doctype/repository_member/repository_member.json b/erpnext_github_integration/erpnext_github_integration/doctype/repository_member/repository_member.json index 6bbba81..3d7ac6e 100644 --- a/erpnext_github_integration/erpnext_github_integration/doctype/repository_member/repository_member.json +++ b/erpnext_github_integration/erpnext_github_integration/doctype/repository_member/repository_member.json @@ -8,7 +8,6 @@ "github_username", "github_id", "column_break_adfu", - "erp_user", "role", "email" ], @@ -43,12 +42,6 @@ "fieldtype": "Data", "label": "Email" }, - { - "fieldname": "erp_user", - "fieldtype": "Link", - "label": "ERPNext User", - "options": "User" - }, { "fieldname": "column_break_adfu", "fieldtype": "Column Break" @@ -56,7 +49,7 @@ ], "istable": 1, "links": [], - "modified": "2025-08-20 11:22:24.539371", + "modified": "2025-08-22 11:43:59.752071", "modified_by": "Administrator", "module": "Erpnext Github Integration", "name": "Repository Member", diff --git a/erpnext_github_integration/github_api.py b/erpnext_github_integration/github_api.py index 7987019..d92f6a8 100644 --- a/erpnext_github_integration/github_api.py +++ b/erpnext_github_integration/github_api.py @@ -3,6 +3,7 @@ import datetime from datetime import datetime, timedelta from dateutil import parser +import pytz from .github_client import github_request def has_role(role): @@ -19,10 +20,24 @@ def convert_github_datetime(dt_string): if not dt_string: return None try: - # Parse ISO 8601 format and convert to MySQL format + # Parse ISO 8601 format dt = parser.parse(dt_string) - return dt.strftime('%Y-%m-%d %H:%M:%S') - except (ValueError, TypeError): + + # Ensure it's treated as UTC if no timezone info + if dt.tzinfo is None: + dt = pytz.utc.localize(dt) + elif dt.tzinfo.utcoffset(dt) == pytz.utc.utcoffset(dt): + pass # Already UTC + + # Convert to IST + ist_tz = pytz.timezone('Asia/Kolkata') + local_dt = dt.astimezone(ist_tz) + + # Return without timezone info for MySQL + return local_dt.replace(tzinfo=None).strftime('%Y-%m-%d %H:%M:%S') + + except (ValueError, TypeError) as e: + frappe.log_error(f'Error parsing datetime {dt_string}: {str(e)}', 'DateTime Parse Error') return None # Usage @@ -322,17 +337,18 @@ def sync_repo(repository): repo_doc.set('branches_table', []) for b in branches: branch_name = b.get('name') - commit_sha = b.get('commit', {}).get('sha') - if commit_sha: - # Fetch detailed commit info to get the date - commit_details = github_request('GET', f'/repos/{repo_full}/commits/{commit_sha}', token) - if commit_details: - # Now you can access the nested commit data - commit_date_str = commit_details.get('commit', {}).get('committer', {}).get('date') - if commit_date_str: - commit_date = convert_github_datetime(commit_date_str) - frappe.log_error(f'Branch: {branch_name}, Date: {commit_date}', 'GitHub Sync Debug') + # Get the latest commit for this specific branch (this includes full commit data) + commits = github_request('GET', f'/repos/{repo_full}/commits', token, + params={'sha': branch_name, 'per_page': 1}) or [] + + if commits: + latest_commit = commits[0] + # This should have the full commit data including dates + commit_date_str = latest_commit.get('commit', {}).get('author', {}).get('date') + if commit_date_str: + commit_date = convert_github_datetime(commit_date_str) + frappe.log_error(f'Branch: {branch_name}, Latest Commit Date: {commit_date}', 'GitHub Sync Debug') repo_doc.append('branches_table', { 'repo_full_name': repo_full, 'branch_name': b.get('name'),