Skip to content

Commit fc105ef

Browse files
committed
Fetch and include latest commit info from GitHub before syncing projects
1 parent 9fd1d08 commit fc105ef

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

github-to-wordpress-sync.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,22 @@ public function ajax_sync_project() {
11501150

11511151
$project = $projects[$project_index];
11521152

1153+
// Fetch latest commit info from GitHub BEFORE syncing
1154+
$github_api = new GTWS_Github_API();
1155+
$latest_commit = $github_api->get_latest_commit($project['github_url'], $project['branch']);
1156+
1157+
if ($latest_commit) {
1158+
// Update project with latest commit info
1159+
$projects[$project_index]['last_commit'] = $latest_commit['sha'];
1160+
$projects[$project_index]['commit_message'] = $latest_commit['message'];
1161+
$projects[$project_index]['commit_date'] = $latest_commit['date'];
1162+
1163+
// Update the project variable to use for syncing
1164+
$project['last_commit'] = $latest_commit['sha'];
1165+
$project['commit_message'] = $latest_commit['message'];
1166+
$project['commit_date'] = $latest_commit['date'];
1167+
}
1168+
11531169
// Perform sync
11541170
$sync_manager = new GTWS_Sync_Manager();
11551171
$result = $sync_manager->sync_project($project);
@@ -1169,7 +1185,12 @@ public function ajax_sync_project() {
11691185

11701186
wp_send_json_success(array(
11711187
'message' => 'Sync completed successfully!',
1172-
'details' => $result
1188+
'details' => $result,
1189+
'commit' => array(
1190+
'sha' => $project['last_commit'],
1191+
'message' => $project['commit_message'],
1192+
'date' => $project['commit_date']
1193+
)
11731194
));
11741195
} else {
11751196
wp_send_json_error($result['message']);
@@ -1285,13 +1306,24 @@ public function ajax_restore_commit() {
12851306
wp_send_json_error('Commit not found');
12861307
}
12871308

1309+
// Also fetch the LATEST commit from GitHub to update last_commit field
1310+
$latest_commit = $github_api->get_latest_commit($project['github_url'], $project['branch']);
1311+
12881312
// Perform sync to specific commit
12891313
$sync_manager = new GTWS_Sync_Manager();
12901314
$result = $sync_manager->sync_project($project, $commit_sha);
12911315

12921316
if ($result['success']) {
12931317
$projects[$project_index]['last_sync'] = current_time('mysql', true);
12941318
$projects[$project_index]['last_sync_commit'] = $commit_sha;
1319+
1320+
// Update the latest commit info from GitHub (not the restored commit)
1321+
if ($latest_commit) {
1322+
$projects[$project_index]['last_commit'] = $latest_commit['sha'];
1323+
$projects[$project_index]['commit_message'] = $latest_commit['message'];
1324+
$projects[$project_index]['commit_date'] = $latest_commit['date'];
1325+
}
1326+
12951327
update_option('gtws_projects', $projects);
12961328

12971329
// Add to sync history
@@ -1304,7 +1336,8 @@ public function ajax_restore_commit() {
13041336

13051337
wp_send_json_success(array(
13061338
'message' => 'Restored to commit successfully!',
1307-
'details' => $result
1339+
'details' => $result,
1340+
'latest_commit' => $latest_commit
13081341
));
13091342
} else {
13101343
wp_send_json_error($result['message']);

0 commit comments

Comments
 (0)