Tweaking output

This commit is contained in:
Pavel Shevaev 2022-08-29 10:58:15 +03:00
parent d75deea884
commit 082ed23f12
1 changed files with 67 additions and 38 deletions

105
chirp.php
View File

@ -9,9 +9,27 @@ $auth_token = gitea_login($gitea_url, $user, $pass);
if(!$auth_token)
throw new Exception("Could not login to gitea");
gitea_check_base_repo($auth_token, $gitea_url, 'bit/skeletik', false);
gitea_check_base_repo($auth_token, $gitea_url, 'bit/skeletor');
gitea_check_base_repo($auth_token, $gitea_url, 'bit/skeletor-rnd');
gitea_check_base_repo($auth_token, $gitea_url, 'bit/skeletik',
array(
'check_forks' => true,
'check_composer' => true,
'check_upm' => false
)
);
gitea_check_base_repo($auth_token, $gitea_url, 'bit/skeletor',
array(
'check_forks' => true,
'check_composer' => true,
'check_upm' => true
)
);
gitea_check_base_repo($auth_token, $gitea_url, 'bit/skeletor-rnd',
array(
'check_forks' => true,
'check_composer' => true,
'check_upm' => true
)
);
//////////////////////////////////
@ -129,57 +147,68 @@ function _is_composer_git_repo(array $repos, $repo)
return false;
}
function gitea_check_base_repo($auth_token, $gitea_url, $base_repo, $check_upm = true)
function gitea_check_base_repo(
$auth_token,
$gitea_url,
$base_repo,
array $opts
)
{
echo "=== Checking base repo '$base_repo' ===\n";
echo "************************* Checking base repo '$base_repo' *************************\n";
$commits = gitea_get_commits($auth_token, $gitea_url, $base_repo);
$forks = gitea_get_forks($auth_token, $gitea_url, $base_repo);
echo "== Checking forks ==\n";
foreach($forks as $fork)
if($opts['check_forks'])
{
$repo_fork = $fork['full_name'];
foreach($commits as $commit)
$forks = gitea_get_forks($auth_token, $gitea_url, $base_repo);
echo "== Checking forks ==\n";
foreach($forks as $fork)
{
$status = gitea_get_commit($auth_token, $gitea_url, $repo_fork, $commit['sha']);
if($status === null)
$repo_fork = $fork['full_name'];
foreach($commits as $commit)
{
echo "Fork '$repo_fork' is behind '$base_repo' at ({$commit['sha']}, {$commit['commit']['author']['date']} by {$commit['commit']['author']['name']})\n";
break;
}
//early exit if commit exists
else if(isset($status['sha']))
{
break;
$status = gitea_get_commit($auth_token, $gitea_url, $repo_fork, $commit['sha']);
if($status === null)
{
echo "Fork '$repo_fork' is behind\n";
break;
}
//early exit if commit exists
else if(isset($status['sha']))
{
break;
}
}
}
}
echo "== Checking Composer manifest ==\n";
$composer_json = gitea_get_source($auth_token, $gitea_url, $base_repo, "composer/composer.json");
$composer_arr = json_decode($composer_json, true);
foreach($composer_arr['require'] as $repo => $version)
if($opts['check_composer'])
{
if(strpos($repo, "bit/") !== 0)
continue;
echo "== Checking Composer manifest ==\n";
$composer_json = gitea_get_source($auth_token, $gitea_url, $base_repo, "composer/composer.json");
$composer_arr = json_decode($composer_json, true);
if(!_is_composer_git_repo($composer_arr['repositories'], "$gitea_url/$repo"))
continue;
$tags = gitea_get_tags($auth_token, $gitea_url, $repo);
if(isset($tags[0]))
foreach($composer_arr['require'] as $repo => $version)
{
$last_tag_info = $tags[0];
if(ltrim($last_tag_info["name"], 'v') != ltrim($version, 'v'))
echo "Newer version in $repo: current $version, latest {$last_tag_info["name"]}\n";
if(strpos($repo, "bit/") !== 0)
continue;
if(!_is_composer_git_repo($composer_arr['repositories'], "$gitea_url/$repo"))
continue;
$tags = gitea_get_tags($auth_token, $gitea_url, $repo);
if(isset($tags[0]))
{
$last_tag_info = $tags[0];
if(ltrim($last_tag_info["name"], 'v') != ltrim($version, 'v'))
echo "Package update '$repo': current $version, latest {$last_tag_info["name"]}\n";
}
else
echo "Could not fetch tags for $repo\n";
}
else
echo "Could not fetch tags for $repo\n";
}
if($check_upm)
if($opts['check_upm'])
{
echo "== Checking UPM manifest ==\n";
$upm_json = gitea_get_source($auth_token, $gitea_url, $base_repo, "unity/Packages/manifest.json");
@ -200,7 +229,7 @@ function gitea_check_base_repo($auth_token, $gitea_url, $base_repo, $check_upm =
{
$last_tag_info = $tags[0];
if(ltrim($last_tag_info["name"], 'v') != ltrim($version, 'v'))
echo "Newer version in $repo: current $version, latest {$last_tag_info["name"]}\n";
echo "Package update '$repo': current $version, latest {$last_tag_info["name"]}\n";
}
else
echo "Could not fetch tags for $repo\n";