From a31e4952303e59fd913a6930fa68813201e2effc Mon Sep 17 00:00:00 2001 From: Yankyyyy Date: Fri, 22 Aug 2025 06:08:59 +0000 Subject: [PATCH] bug: last_updated for branches not being fetch fix --- erpnext_github_integration/github_api.py | 17 +++++++++++++---- erpnext_github_integration/webhooks.py | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/erpnext_github_integration/github_api.py b/erpnext_github_integration/github_api.py index f2d6a94..7987019 100644 --- a/erpnext_github_integration/github_api.py +++ b/erpnext_github_integration/github_api.py @@ -321,15 +321,24 @@ def sync_repo(repository): # Clear and update branches repo_doc.set('branches_table', []) for b in branches: - commit_date_str = b.get('timestamp') or b.get('commit', {}).get('committer', {}).get('date') - if commit_date_str: - commit_date = convert_github_datetime(commit_date_str) + 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') repo_doc.append('branches_table', { 'repo_full_name': repo_full, 'branch_name': b.get('name'), 'commit_sha': b.get('commit', {}).get('sha'), 'protected': b.get('protected', False), - 'last_updated': commit_date + 'last_updated': commit_date or '' }) # Clear and update members diff --git a/erpnext_github_integration/webhooks.py b/erpnext_github_integration/webhooks.py index 76c8e6f..8ba9abb 100644 --- a/erpnext_github_integration/webhooks.py +++ b/erpnext_github_integration/webhooks.py @@ -147,7 +147,7 @@ def _handle_issues_event(data, repo_full_name): doc.state = issue.get('state', 'open') doc.labels = ','.join([l.get('name', '') for l in issue.get('labels', [])]) doc.url = issue.get('html_url', '') - doc.updated_at = frappe.utils.get_datetime(issue.get('updated_at')) + doc.updated_at = convert_github_datetime(issue.get('updated_at')) # Clear and update assignees doc.set('assignees_table', []) @@ -227,7 +227,7 @@ def _handle_pull_request_event(data, repo_full_name): doc.author = pr.get('user', {}).get('login', '') doc.mergeable_state = pr.get('mergeable_state', '') doc.url = pr.get('html_url', '') - doc.updated_at = frappe.utils.get_datetime(pr.get('updated_at')) + doc.updated_at = convert_github_datetime(pr.get('updated_at')) # Clear and update reviewers doc.set('reviewers_table', [])