Skip to content

Commit

Permalink
Issue #2567
Browse files Browse the repository at this point in the history
  • Loading branch information
zoic21 committed Jul 19, 2024
1 parent 330d191 commit a434e08
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 39 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"symfony/expression-language": "^5.4",
"doctrine/cache": "^1.13",
"monolog/monolog": "^2.9",
"knplabs/github-api": "^3",
"league/flysystem-webdav": "^1.0",
"pragmarx/google2fa-qrcode": "^3.0",
"abbadon1334/sun-position-spa-php": "^2.0",
Expand Down
54 changes: 16 additions & 38 deletions core/repo/github.repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,6 @@ public static function getConfigurationOption(){
);
}

public static function getGithubClient($_token=null) {
$client = new \Github\Client();
if (!is_null($_token) && $_token!=''){
if(defined('Github\Client::AUTH_ACCESS_TOKEN')){
$client->authenticate($_token, '', Github\Client::AUTH_ACCESS_TOKEN);
}else{
$client->authenticate($_token, '', Github\Client::AUTH_HTTP_TOKEN);
}
}
return $client;
}

public static function checkUpdate(&$_update) {
if (is_array($_update)) {
if (count($_update) < 1) {
Expand All @@ -102,9 +90,8 @@ public static function checkUpdate(&$_update) {
}
return;
}
$client = self::getGithubClient($_update->getConfiguration('token',config::byKey('github::token','core','')));
try {
$branch = $client->api('repo')->branches($_update->getConfiguration('user'), $_update->getConfiguration('repository'), $_update->getConfiguration('version', 'master'));
$branch = self::getBranchInfo($_update);
} catch (Exception $e) {
$_update->setRemoteVersion('repository not found');
$_update->setStatus('ok');
Expand All @@ -125,15 +112,20 @@ public static function checkUpdate(&$_update) {
}
$_update->save();
}

public static function downloadObject($_update) {

public static function getBranchInfo($_update){
$headers = array('User-agent: jeedom');
$token = $_update->getConfiguration('token',config::byKey('github::token','core',''));
$client = self::getGithubClient($token);
try {
$branch = $client->api('repo')->branches($_update->getConfiguration('user'), $_update->getConfiguration('repository'), $_update->getConfiguration('version', 'master'));
} catch (Exception $e) {
throw new Exception(__('Dépot github non trouvé :', __FILE__) . ' ' . $_update->getConfiguration('user') . '/' . $_update->getConfiguration('repository') . '/' . $_update->getConfiguration('version', 'master'));
if($token != ''){
$headers[] = 'Authorization: Bearer '.$token;
}
$request_http = new com_http('https://api.github.com/repos/'.$_update->getConfiguration('user').'/'.$_update->getConfiguration('repository').'/branches/'.$_update->getConfiguration('version', 'master'));
$request_http->setHeader($headers);
return json_decode($request_http->exec(10, 1), true);
}

public static function downloadObject($_update) {
$branch = self::getBranchInfo($_update);
$tmp_dir = jeedom::getTmpFolder('github');
$tmp = $tmp_dir . '/' . $_update->getLogicalId() . '.zip';
if (file_exists($tmp)) {
Expand All @@ -145,7 +137,6 @@ public static function downloadObject($_update) {
if (!is_writable($tmp_dir)) {
throw new Exception(__('Impossible d\'écrire dans le répertoire :', __FILE__) . ' ' . $tmp . __('. Exécuter la commande suivante en SSH : sudo chmod 777 -R', __FILE__) . ' ' . $tmp_dir);
}

$url = 'https://api.github.com/repos/' . $_update->getConfiguration('user') . '/' . $_update->getConfiguration('repository') . '/zipball/' . $_update->getConfiguration('version', 'master');
log::add('update', 'alert', __('Téléchargement de', __FILE__) . ' ' . $_update->getLogicalId() . '...');
if ($token == '') {
Expand Down Expand Up @@ -173,12 +164,6 @@ public static function objectInfo($_update) {
}

public static function downloadCore($_path) {
$client = self::getGithubClient(config::byKey('github::token','core',''));
try {
$client->api('repo')->branches(config::byKey('github::core::user', 'core', 'jeedom'), config::byKey('github::core::repository', 'core', 'core'), config::byKey('github::core::branch', 'core', 'stable'));
} catch (Exception $e) {
throw new Exception(__('Dépot github non trouvé :', __FILE__) . ' ' . config::byKey('github::core::user', 'core', 'jeedom') . '/' . config::byKey('github::core::repository', 'core', 'core') . '/' . config::byKey('github::core::branch', 'core', 'stable'));
}
$url = 'https://api.github.com/repos/' . config::byKey('github::core::user', 'core', 'jeedom') . '/' . config::byKey('github::core::repository', 'core', 'core') . '/zipball/' . config::byKey('github::core::branch', 'core', 'stable');
echo __('Téléchargement de', __FILE__) . ' ' . $url . '...';
if (config::byKey('github::token') == '') {
Expand All @@ -190,16 +175,9 @@ public static function downloadCore($_path) {
}

public static function versionCore() {
try {
$client = self::getGithubClient(config::byKey('github::token','core',''));
$fileContent = $client->api('repo')->contents()->download(config::byKey('github::core::user', 'core', 'jeedom'), config::byKey('github::core::repository', 'core', 'core'), 'core/config/version', config::byKey('github::core::branch', 'core', 'stable'));
return trim($fileContent);
} catch (Exception $e) {

} catch (Error $e) {

}
return null;
$url = 'https://raw.githubusercontent.com/'.config::byKey('github::core::user', 'core', 'jeedom').'/'.config::byKey('github::core::repository', 'core', 'core').'/' . config::byKey('github::core::branch', 'core', 'stable') . '/core/config/version';
$request_http = new com_http($url);
return trim($request_http->exec(30));
}

/* * *********************Methode d'instance************************* */
Expand Down
2 changes: 2 additions & 0 deletions docs/fr_FR/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- Mysql : utilisation d'une table de cache en base. Le moins performant mais sauvegardé en temps réel (aucune perte de données possible)
- Redis : réservé aux experts, s'appuie sur redis pour gerer le cache (necessite donc que vous installiez vous meme un redis et les dépendance php-redis)

- Amélioration de la gestion des plugins sur github (plus de dépendances à une librairie tierce) [LIEN](https://github.com/jeedom/core/issues/2567)

>**IMPORTANT**
>
> Tout changement de moteur de cache entraine une remise a zéro de celui-ci il faut donc attendre ensuite que les modules renvoient les informations pour tout retrouver
Expand Down

0 comments on commit a434e08

Please sign in to comment.