mirror of
https://github.com/cedar2025/Xboard.git
synced 2025-02-13 12:08:13 -05:00
fix(update): fix version comparison logic
This commit is contained in:
parent
39456923d3
commit
7ac2e2e2ed
1
.gitignore
vendored
1
.gitignore
vendored
@ -24,6 +24,7 @@ docker-compose.yml
|
|||||||
/docker
|
/docker
|
||||||
storage/laravels.conf
|
storage/laravels.conf
|
||||||
storage/laravels.pid
|
storage/laravels.pid
|
||||||
|
storage/update_pending
|
||||||
storage/laravels-timer-process.pid
|
storage/laravels-timer-process.pid
|
||||||
cli-php.ini
|
cli-php.ini
|
||||||
frontend
|
frontend
|
||||||
|
@ -62,7 +62,6 @@ class UpdateService
|
|||||||
// If unable to get current commit, try to get the first commit
|
// If unable to get current commit, try to get the first commit
|
||||||
$currentCommit = $this->getFirstCommit();
|
$currentCommit = $this->getFirstCommit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get local git logs
|
// Get local git logs
|
||||||
$localLogs = $this->getLocalGitLogs();
|
$localLogs = $this->getLocalGitLogs();
|
||||||
if (empty($localLogs)) {
|
if (empty($localLogs)) {
|
||||||
@ -74,45 +73,60 @@ class UpdateService
|
|||||||
$response = Http::withHeaders([
|
$response = Http::withHeaders([
|
||||||
'Accept' => 'application/vnd.github.v3+json',
|
'Accept' => 'application/vnd.github.v3+json',
|
||||||
'User-Agent' => 'XBoard-Update-Checker'
|
'User-Agent' => 'XBoard-Update-Checker'
|
||||||
])->get(self::GITHUB_API_URL . '?sha=master&per_page=50');
|
])->get(self::GITHUB_API_URL . '?per_page=50');
|
||||||
|
|
||||||
if ($response->successful()) {
|
if ($response->successful()) {
|
||||||
$commits = $response->json();
|
$commits = $response->json();
|
||||||
$latestCommit = $this->formatCommitHash($commits[0]['sha']);
|
|
||||||
|
|
||||||
// Find current version position in commit history
|
if (empty($commits) || !is_array($commits)) {
|
||||||
$currentIndex = -1;
|
Log::error('Invalid GitHub response format');
|
||||||
$updateLogs = [];
|
return $this->getCachedUpdateInfo();
|
||||||
$isLocalNewer = false;
|
|
||||||
|
|
||||||
// Check if local is newer than remote
|
|
||||||
foreach ($localLogs as $localCommit) {
|
|
||||||
$localHash = $this->formatCommitHash($localCommit['hash']);
|
|
||||||
if ($localHash === $latestCommit) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// If local commit not in remote, local version is newer
|
|
||||||
$isLocalNewer = true;
|
|
||||||
$updateLogs[] = [
|
|
||||||
'version' => $localHash,
|
|
||||||
'message' => $localCommit['message'],
|
|
||||||
'author' => $localCommit['author'],
|
|
||||||
'date' => $localCommit['date'],
|
|
||||||
'is_local' => true
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$isLocalNewer) {
|
$latestCommit = $this->formatCommitHash($commits[0]['sha']);
|
||||||
// If local is not newer, check remote updates
|
$currentIndex = -1;
|
||||||
foreach ($commits as $index => $commit) {
|
$updateLogs = [];
|
||||||
$shortSha = $this->formatCommitHash($commit['sha']);
|
|
||||||
if ($shortSha === $currentCommit) {
|
// First, find the current version position in remote commit history
|
||||||
$currentIndex = $index;
|
foreach ($commits as $index => $commit) {
|
||||||
|
$shortSha = $this->formatCommitHash($commit['sha']);
|
||||||
|
if ($shortSha === $currentCommit) {
|
||||||
|
$currentIndex = $index;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check local version status
|
||||||
|
$isLocalNewer = false;
|
||||||
|
if ($currentIndex === -1) {
|
||||||
|
// Current version not found in remote history, check local commits
|
||||||
|
foreach ($localLogs as $localCommit) {
|
||||||
|
$localHash = $this->formatCommitHash($localCommit['hash']);
|
||||||
|
// If latest remote commit found, local is not newer
|
||||||
|
if ($localHash === $latestCommit) {
|
||||||
|
$isLocalNewer = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Collect update logs
|
// Record additional local commits
|
||||||
$updateLogs[] = [
|
$updateLogs[] = [
|
||||||
'version' => $shortSha,
|
'version' => $localHash,
|
||||||
|
'message' => $localCommit['message'],
|
||||||
|
'author' => $localCommit['author'],
|
||||||
|
'date' => $localCommit['date'],
|
||||||
|
'is_local' => true
|
||||||
|
];
|
||||||
|
$isLocalNewer = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If local is not newer, collect commits that need to be updated
|
||||||
|
if (!$isLocalNewer && $currentIndex > 0) {
|
||||||
|
$updateLogs = [];
|
||||||
|
// Collect all commits between current version and latest version
|
||||||
|
for ($i = 0; $i < $currentIndex; $i++) {
|
||||||
|
$commit = $commits[$i];
|
||||||
|
$updateLogs[] = [
|
||||||
|
'version' => $this->formatCommitHash($commit['sha']),
|
||||||
'message' => $commit['commit']['message'],
|
'message' => $commit['commit']['message'],
|
||||||
'author' => $commit['commit']['author']['name'],
|
'author' => $commit['commit']['author']['name'],
|
||||||
'date' => $commit['commit']['author']['date'],
|
'date' => $commit['commit']['author']['date'],
|
||||||
@ -121,7 +135,7 @@ class UpdateService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$hasUpdate = !$isLocalNewer && $currentIndex !== 0 && $currentIndex !== -1;
|
$hasUpdate = !$isLocalNewer && $currentIndex > 0;
|
||||||
|
|
||||||
$updateInfo = [
|
$updateInfo = [
|
||||||
'has_update' => $hasUpdate,
|
'has_update' => $hasUpdate,
|
||||||
|
Loading…
Reference in New Issue
Block a user